Assign DNS name to the cluster.
DNS name is generated from the team name and cluster name. Use "zalando.org/dnsname" service annotation that makes 'mate' service assign a CNAME to the load balancer name.
This commit is contained in:
		
							parent
							
								
									45fcb2adc9
								
							
						
					
					
						commit
						55dbacdfa6
					
				|  | @ -88,6 +88,10 @@ func (c *Cluster) ClusterName() spec.ClusterName { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (c *Cluster) ClusterTeamName() string { | ||||||
|  | 	return c.Spec.TeamId | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (c *Cluster) Run(stopCh <-chan struct{}) { | func (c *Cluster) Run(stopCh <-chan struct{}) { | ||||||
| 	go c.podEventsDispatcher(stopCh) | 	go c.podEventsDispatcher(stopCh) | ||||||
| 
 | 
 | ||||||
|  | @ -199,7 +203,7 @@ func (c *Cluster) Update(newSpec *spec.Postgresql) error { | ||||||
| 
 | 
 | ||||||
| 	newStatefulSet := getStatefulSet(c.ClusterName(), newSpec.Spec, c.etcdHost, c.dockerImage) | 	newStatefulSet := getStatefulSet(c.ClusterName(), newSpec.Spec, c.etcdHost, c.dockerImage) | ||||||
| 
 | 
 | ||||||
| 	newService := resources.Service(c.ClusterName(), newSpec.Spec.AllowedSourceRanges) | 	newService := resources.Service(c.ClusterName(), c.ClusterTeamName(), newSpec.Spec.AllowedSourceRanges) | ||||||
| 	if !servicesEqual(newService, c.Service) { | 	if !servicesEqual(newService, c.Service) { | ||||||
| 		c.logger.Infof("Service needs to be upated") | 		c.logger.Infof("Service needs to be upated") | ||||||
| 		if err := c.updateService(newService); err != nil { | 		if err := c.updateService(newService); err != nil { | ||||||
|  |  | ||||||
|  | @ -148,7 +148,7 @@ func (c *Cluster) createService() (*v1.Service, error) { | ||||||
| 	if c.Service != nil { | 	if c.Service != nil { | ||||||
| 		return nil, fmt.Errorf("Service already exists in the cluster") | 		return nil, fmt.Errorf("Service already exists in the cluster") | ||||||
| 	} | 	} | ||||||
| 	serviceSpec := resources.Service(c.ClusterName(), c.Spec.AllowedSourceRanges) | 	serviceSpec := resources.Service(c.ClusterName(), c.ClusterTeamName(), c.Spec.AllowedSourceRanges) | ||||||
| 
 | 
 | ||||||
| 	service, err := c.config.KubeClient.Services(serviceSpec.Namespace).Create(serviceSpec) | 	service, err := c.config.KubeClient.Services(serviceSpec.Namespace).Create(serviceSpec) | ||||||
| 	if k8sutil.ResourceAlreadyExists(err) { | 	if k8sutil.ResourceAlreadyExists(err) { | ||||||
|  |  | ||||||
|  | @ -11,13 +11,17 @@ import ( | ||||||
| 	"k8s.io/client-go/pkg/util/intstr" | 	"k8s.io/client-go/pkg/util/intstr" | ||||||
| 
 | 
 | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | ||||||
|  | 	"github.bus.zalan.do/acid/postgres-operator/pkg/util" | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/util/constants" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/util/constants" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	superuserName       = "postgres" | 	superuserName            = "postgres" | ||||||
| 	replicationUsername = "replication" | 	replicationUsername      = "replication" | ||||||
| 	dataVolumeName      = "pgdata" | 	dataVolumeName           = "pgdata" | ||||||
|  | 	zalandoDnsNameAnnotation = "zalando.org/dnsname" | ||||||
|  | 	// TODO: move DbHostedZone to operator configuration
 | ||||||
|  | 	DbHostedZone = "db.example.com" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func credentialSecretName(clusterName, username string) string { | func credentialSecretName(clusterName, username string) string { | ||||||
|  | @ -248,12 +252,13 @@ func UserSecrets(cluster spec.ClusterName, pgUsers map[string]spec.PgUser) (secr | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func Service(cluster spec.ClusterName, allowedSourceRanges []string) *v1.Service { | func Service(cluster spec.ClusterName, teamName string, allowedSourceRanges []string) *v1.Service { | ||||||
| 	service := &v1.Service{ | 	service := &v1.Service{ | ||||||
| 		ObjectMeta: v1.ObjectMeta{ | 		ObjectMeta: v1.ObjectMeta{ | ||||||
| 			Name:      cluster.Name, | 			Name:        cluster.Name, | ||||||
| 			Namespace: cluster.Namespace, | 			Namespace:   cluster.Namespace, | ||||||
| 			Labels:    labelsSet(cluster.Name), | 			Labels:      labelsSet(cluster.Name), | ||||||
|  | 			Annotations: map[string]string{zalandoDnsNameAnnotation: util.ClusterDNSName(cluster.Name, teamName, DbHostedZone)}, | ||||||
| 		}, | 		}, | ||||||
| 		Spec: v1.ServiceSpec{ | 		Spec: v1.ServiceSpec{ | ||||||
| 			Type:  v1.ServiceTypeLoadBalancer, | 			Type:  v1.ServiceTypeLoadBalancer, | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ import ( | ||||||
| 	"math/rand" | 	"math/rand" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
|  | 	"fmt" | ||||||
| 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | 	"github.bus.zalan.do/acid/postgres-operator/pkg/spec" | ||||||
| 	"k8s.io/client-go/pkg/api/v1" | 	"k8s.io/client-go/pkg/api/v1" | ||||||
| 	"k8s.io/client-go/pkg/types" | 	"k8s.io/client-go/pkg/types" | ||||||
|  | @ -43,3 +44,7 @@ func PodClusterName(pod *v1.Pod) spec.ClusterName { | ||||||
| 
 | 
 | ||||||
| 	return spec.ClusterName{} | 	return spec.ClusterName{} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func ClusterDNSName(clusterName, teamName, hostedZone string) string { | ||||||
|  | 	return fmt.Sprintf("%s.%s.%s", clusterName, teamName, hostedZone) | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue