Fix labels for the replica pods
This commit is contained in:
		
							parent
							
								
									fb49376085
								
							
						
					
					
						commit
						a9248b1379
					
				| 
						 | 
					@ -2199,7 +2199,7 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(spec *acidv1.PostgresSpec,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	podTemplate := &v1.PodTemplateSpec{
 | 
						podTemplate := &v1.PodTemplateSpec{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Labels:      c.connectionPoolerLabelsSelector().MatchLabels,
 | 
								Labels:      c.connectionPoolerLabelsSelector(role).MatchLabels,
 | 
				
			||||||
			Namespace:   c.Namespace,
 | 
								Namespace:   c.Namespace,
 | 
				
			||||||
			Annotations: c.generatePodAnnotations(spec),
 | 
								Annotations: c.generatePodAnnotations(spec),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
| 
						 | 
					@ -2280,7 +2280,7 @@ func (c *Cluster) generateConnectionPoolerDeployment(spec *acidv1.PostgresSpec,
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name:        name,
 | 
								Name:        name,
 | 
				
			||||||
			Namespace:   c.Namespace,
 | 
								Namespace:   c.Namespace,
 | 
				
			||||||
			Labels:      c.connectionPoolerLabelsSelector().MatchLabels,
 | 
								Labels:      c.connectionPoolerLabelsSelector(role).MatchLabels,
 | 
				
			||||||
			Annotations: map[string]string{},
 | 
								Annotations: map[string]string{},
 | 
				
			||||||
			// make StatefulSet object its owner to represent the dependency.
 | 
								// make StatefulSet object its owner to represent the dependency.
 | 
				
			||||||
			// By itself StatefulSet is being deleted with "Orphaned"
 | 
								// By itself StatefulSet is being deleted with "Orphaned"
 | 
				
			||||||
| 
						 | 
					@ -2292,7 +2292,7 @@ func (c *Cluster) generateConnectionPoolerDeployment(spec *acidv1.PostgresSpec,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: appsv1.DeploymentSpec{
 | 
							Spec: appsv1.DeploymentSpec{
 | 
				
			||||||
			Replicas: numberOfInstances,
 | 
								Replicas: numberOfInstances,
 | 
				
			||||||
			Selector: c.connectionPoolerLabelsSelector(),
 | 
								Selector: c.connectionPoolerLabelsSelector(role),
 | 
				
			||||||
			Template: *podTemplate,
 | 
								Template: *podTemplate,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -2300,52 +2300,6 @@ func (c *Cluster) generateConnectionPoolerDeployment(spec *acidv1.PostgresSpec,
 | 
				
			||||||
	return deployment, nil
 | 
						return deployment, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* func (c *Cluster) generateReplicaConnectionPoolerDeployment(spec *acidv1.PostgresSpec) (
 | 
					 | 
				
			||||||
	*appsv1.Deployment, error) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	podTemplate, err := c.generateConnectionPoolerPodTemplate(spec, Replica)
 | 
					 | 
				
			||||||
	numberOfInstances := spec.ConnectionPooler.NumberOfInstances
 | 
					 | 
				
			||||||
	if numberOfInstances == nil {
 | 
					 | 
				
			||||||
		numberOfInstances = util.CoalesceInt32(
 | 
					 | 
				
			||||||
			c.OpConfig.ConnectionPooler.NumberOfInstances,
 | 
					 | 
				
			||||||
			k8sutil.Int32ToPointer(1))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if *numberOfInstances < constants.ConnectionPoolerMinInstances {
 | 
					 | 
				
			||||||
		msg := "Adjusted number of connection pooler instances from %d to %d"
 | 
					 | 
				
			||||||
		c.logger.Warningf(msg, numberOfInstances, constants.ConnectionPoolerMinInstances)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		*numberOfInstances = constants.ConnectionPoolerMinInstances
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	deployment := &appsv1.Deployment{
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Name:        c.connectionPoolerName() + "-repl",
 | 
					 | 
				
			||||||
			Namespace:   c.Namespace,
 | 
					 | 
				
			||||||
			Labels:      c.connectionPoolerLabelsSelector().MatchLabels,
 | 
					 | 
				
			||||||
			Annotations: map[string]string{},
 | 
					 | 
				
			||||||
			// make StatefulSet object its owner to represent the dependency.
 | 
					 | 
				
			||||||
			// By itself StatefulSet is being deleted with "Orphaned"
 | 
					 | 
				
			||||||
			// propagation policy, which means that it's deletion will not
 | 
					 | 
				
			||||||
			// clean up this deployment, but there is a hope that this object
 | 
					 | 
				
			||||||
			// will be garbage collected if something went wrong and operator
 | 
					 | 
				
			||||||
			// didn't deleted it.
 | 
					 | 
				
			||||||
			OwnerReferences: c.ownerReferences(),
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Spec: appsv1.DeploymentSpec{
 | 
					 | 
				
			||||||
			Replicas: numberOfInstances,
 | 
					 | 
				
			||||||
			Selector: c.connectionPoolerLabelsSelector(),
 | 
					 | 
				
			||||||
			Template: *podTemplate,
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return deployment, nil
 | 
					 | 
				
			||||||
} */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (c *Cluster) generateConnectionPoolerService(spec *acidv1.PostgresSpec, role PostgresRole) *v1.Service {
 | 
					func (c *Cluster) generateConnectionPoolerService(spec *acidv1.PostgresSpec, role PostgresRole) *v1.Service {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// there are two ways to enable connection pooler, either to specify a
 | 
						// there are two ways to enable connection pooler, either to specify a
 | 
				
			||||||
| 
						 | 
					@ -2378,7 +2332,7 @@ func (c *Cluster) generateConnectionPoolerService(spec *acidv1.PostgresSpec, rol
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
			Name:        name,
 | 
								Name:        name,
 | 
				
			||||||
			Namespace:   c.Namespace,
 | 
								Namespace:   c.Namespace,
 | 
				
			||||||
			Labels:      c.connectionPoolerLabelsSelector().MatchLabels,
 | 
								Labels:      c.connectionPoolerLabelsSelector(role).MatchLabels,
 | 
				
			||||||
			Annotations: map[string]string{},
 | 
								Annotations: map[string]string{},
 | 
				
			||||||
			// make StatefulSet object its owner to represent the dependency.
 | 
								// make StatefulSet object its owner to represent the dependency.
 | 
				
			||||||
			// By itself StatefulSet is being deleted with "Orphaned"
 | 
								// By itself StatefulSet is being deleted with "Orphaned"
 | 
				
			||||||
| 
						 | 
					@ -2394,40 +2348,6 @@ func (c *Cluster) generateConnectionPoolerService(spec *acidv1.PostgresSpec, rol
 | 
				
			||||||
	return service
 | 
						return service
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* func (c *Cluster) generateReplicaConnectionPoolerService(spec *acidv1.PostgresSpec) *v1.Service {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	replicaserviceSpec := v1.ServiceSpec{
 | 
					 | 
				
			||||||
		Ports: []v1.ServicePort{
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				Name:       c.connectionPoolerName() + "-repl",
 | 
					 | 
				
			||||||
				Port:       pgPort,
 | 
					 | 
				
			||||||
				TargetPort: intstr.IntOrString{StrVal: c.servicePort(Replica)},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Type:     v1.ServiceTypeClusterIP,
 | 
					 | 
				
			||||||
		Selector: c.roleLabelsSet(false, Replica),
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	service := &v1.Service{
 | 
					 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
					 | 
				
			||||||
			Name:        c.connectionPoolerName() + "-repl",
 | 
					 | 
				
			||||||
			Namespace:   c.Namespace,
 | 
					 | 
				
			||||||
			Labels:      c.connectionPoolerLabelsSelector().MatchLabels,
 | 
					 | 
				
			||||||
			Annotations: map[string]string{},
 | 
					 | 
				
			||||||
			// make StatefulSet object its owner to represent the dependency.
 | 
					 | 
				
			||||||
			// By itself StatefulSet is being deleted with "Orphaned"
 | 
					 | 
				
			||||||
			// propagation policy, which means that it's deletion will not
 | 
					 | 
				
			||||||
			// clean up this service, but there is a hope that this object will
 | 
					 | 
				
			||||||
			// be garbage collected if something went wrong and operator didn't
 | 
					 | 
				
			||||||
			// deleted it.
 | 
					 | 
				
			||||||
			OwnerReferences: c.ownerReferences(),
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
		Spec: replicaserviceSpec,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return service
 | 
					 | 
				
			||||||
} */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ensurePath(file string, defaultDir string, defaultFile string) string {
 | 
					func ensurePath(file string, defaultDir string, defaultFile string) string {
 | 
				
			||||||
	if file == "" {
 | 
						if file == "" {
 | 
				
			||||||
		return path.Join(defaultDir, defaultFile)
 | 
							return path.Join(defaultDir, defaultFile)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -960,7 +960,7 @@ func testResources(cluster *Cluster, podSpec *v1.PodTemplateSpec) error {
 | 
				
			||||||
func testLabels(cluster *Cluster, podSpec *v1.PodTemplateSpec) error {
 | 
					func testLabels(cluster *Cluster, podSpec *v1.PodTemplateSpec) error {
 | 
				
			||||||
	poolerLabels := podSpec.ObjectMeta.Labels["connection-pooler"]
 | 
						poolerLabels := podSpec.ObjectMeta.Labels["connection-pooler"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if poolerLabels != cluster.connectionPoolerLabelsSelector().MatchLabels["connection-pooler"] {
 | 
						if poolerLabels != cluster.connectionPoolerLabelsSelector(Master).MatchLabels["connection-pooler"] {
 | 
				
			||||||
		return fmt.Errorf("Pod labels do not match, got %+v, expected %+v",
 | 
							return fmt.Errorf("Pod labels do not match, got %+v, expected %+v",
 | 
				
			||||||
			podSpec.ObjectMeta.Labels, cluster.connectionPoolerLabelsSelector().MatchLabels)
 | 
								podSpec.ObjectMeta.Labels, cluster.connectionPoolerLabelsSelector().MatchLabels)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -1118,7 +1118,7 @@ func testDeploymentOwnwerReference(cluster *Cluster, deployment *appsv1.Deployme
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func testSelector(cluster *Cluster, deployment *appsv1.Deployment) error {
 | 
					func testSelector(cluster *Cluster, deployment *appsv1.Deployment) error {
 | 
				
			||||||
	labels := deployment.Spec.Selector.MatchLabels
 | 
						labels := deployment.Spec.Selector.MatchLabels
 | 
				
			||||||
	expected := cluster.connectionPoolerLabelsSelector().MatchLabels
 | 
						expected := cluster.connectionPoolerLabelsSelector(Master).MatchLabels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if labels["connection-pooler"] != expected["connection-pooler"] {
 | 
						if labels["connection-pooler"] != expected["connection-pooler"] {
 | 
				
			||||||
		return fmt.Errorf("Labels are incorrect, got %+v, expected %+v",
 | 
							return fmt.Errorf("Labels are incorrect, got %+v, expected %+v",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -420,11 +420,11 @@ func (c *Cluster) labelsSelector() *metav1.LabelSelector {
 | 
				
			||||||
// have e.g. different `application` label, so that recreatePod operation will
 | 
					// have e.g. different `application` label, so that recreatePod operation will
 | 
				
			||||||
// not interfere with it (it lists all the pods via labels, and if there would
 | 
					// not interfere with it (it lists all the pods via labels, and if there would
 | 
				
			||||||
// be no difference, it will recreate also pooler pods).
 | 
					// be no difference, it will recreate also pooler pods).
 | 
				
			||||||
func (c *Cluster) connectionPoolerLabelsSelector() *metav1.LabelSelector {
 | 
					func (c *Cluster) connectionPoolerLabelsSelector(role PostgresRole) *metav1.LabelSelector {
 | 
				
			||||||
	connectionPoolerLabels := labels.Set(map[string]string{})
 | 
						connectionPoolerLabels := labels.Set(map[string]string{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	extraLabels := labels.Set(map[string]string{
 | 
						extraLabels := labels.Set(map[string]string{
 | 
				
			||||||
		"connection-pooler": c.connectionPoolerName(Master),
 | 
							"connection-pooler": c.connectionPoolerName(role),
 | 
				
			||||||
		"application":       "db-connection-pooler",
 | 
							"application":       "db-connection-pooler",
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue