Avoid modifying pooler deployment selector labels
This commit is contained in:
parent
ddfa26e6bd
commit
e30b6a5670
|
|
@ -152,8 +152,8 @@ class EndToEndTestCase(unittest.TestCase):
|
||||||
print('Operator log: {}'.format(k8s.get_operator_log()))
|
print('Operator log: {}'.format(k8s.get_operator_log()))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def test_a_overwrite_pooler_deployment(self):
|
def test_overwrite_pooler_deployment(self):
|
||||||
result = self.k8s.create_with_kubectl("manifests/minimal-fake-pooler-deployment.yaml")
|
self.k8s.create_with_kubectl("manifests/minimal-fake-pooler-deployment.yaml")
|
||||||
self.eventuallyEqual(lambda: self.k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync")
|
self.eventuallyEqual(lambda: self.k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync")
|
||||||
|
|
||||||
self.k8s.api.custom_objects_api.patch_namespaced_custom_object(
|
self.k8s.api.custom_objects_api.patch_namespaced_custom_object(
|
||||||
|
|
|
||||||
|
|
@ -78,16 +78,25 @@ func needReplicaConnectionPoolerWorker(spec *acidv1.PostgresSpec) bool {
|
||||||
// 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(role PostgresRole) *metav1.LabelSelector {
|
func (c *Cluster) connectionPoolerLabelsSelector(role PostgresRole, moreLabels bool) *metav1.LabelSelector {
|
||||||
connectionPoolerLabels := labels.Set(map[string]string{})
|
connectionPoolerLabels := labels.Set(map[string]string{})
|
||||||
|
|
||||||
extraLabels := labels.Set(map[string]string{
|
var extraLabels map[string]string
|
||||||
|
|
||||||
|
if moreLabels {
|
||||||
|
extraLabels = labels.Set(map[string]string{
|
||||||
"connection-pooler": c.connectionPoolerName(role),
|
"connection-pooler": c.connectionPoolerName(role),
|
||||||
"application": "db-connection-pooler",
|
"application": "db-connection-pooler",
|
||||||
"spilo-role": string(role),
|
"spilo-role": string(role),
|
||||||
"cluster-name": c.Name,
|
"cluster-name": c.Name,
|
||||||
"Namespace": c.Namespace,
|
"Namespace": c.Namespace,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
extraLabels = labels.Set(map[string]string{
|
||||||
|
"connection-pooler": c.connectionPoolerName(role),
|
||||||
|
"application": "db-connection-pooler",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
connectionPoolerLabels = labels.Merge(connectionPoolerLabels, c.labelsSet(false))
|
connectionPoolerLabels = labels.Merge(connectionPoolerLabels, c.labelsSet(false))
|
||||||
connectionPoolerLabels = labels.Merge(connectionPoolerLabels, extraLabels)
|
connectionPoolerLabels = labels.Merge(connectionPoolerLabels, extraLabels)
|
||||||
|
|
@ -284,7 +293,7 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
|
||||||
|
|
||||||
podTemplate := &v1.PodTemplateSpec{
|
podTemplate := &v1.PodTemplateSpec{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: c.connectionPoolerLabelsSelector(role).MatchLabels,
|
Labels: c.connectionPoolerLabelsSelector(role, true).MatchLabels,
|
||||||
Namespace: c.Namespace,
|
Namespace: c.Namespace,
|
||||||
Annotations: c.generatePodAnnotations(spec),
|
Annotations: c.generatePodAnnotations(spec),
|
||||||
},
|
},
|
||||||
|
|
@ -338,7 +347,7 @@ func (c *Cluster) generateConnectionPoolerDeployment(connectionPooler *Connectio
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: connectionPooler.Name,
|
Name: connectionPooler.Name,
|
||||||
Namespace: connectionPooler.Namespace,
|
Namespace: connectionPooler.Namespace,
|
||||||
Labels: c.connectionPoolerLabelsSelector(connectionPooler.Role).MatchLabels,
|
Labels: c.connectionPoolerLabelsSelector(connectionPooler.Role, true).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"
|
||||||
|
|
@ -350,7 +359,7 @@ func (c *Cluster) generateConnectionPoolerDeployment(connectionPooler *Connectio
|
||||||
},
|
},
|
||||||
Spec: appsv1.DeploymentSpec{
|
Spec: appsv1.DeploymentSpec{
|
||||||
Replicas: numberOfInstances,
|
Replicas: numberOfInstances,
|
||||||
Selector: c.connectionPoolerLabelsSelector(connectionPooler.Role),
|
Selector: c.connectionPoolerLabelsSelector(connectionPooler.Role, false),
|
||||||
Template: *podTemplate,
|
Template: *podTemplate,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -389,7 +398,7 @@ func (c *Cluster) generateConnectionPoolerService(connectionPooler *ConnectionPo
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: connectionPooler.Name,
|
Name: connectionPooler.Name,
|
||||||
Namespace: connectionPooler.Namespace,
|
Namespace: connectionPooler.Namespace,
|
||||||
Labels: c.connectionPoolerLabelsSelector(connectionPooler.Role).MatchLabels,
|
Labels: c.connectionPoolerLabelsSelector(connectionPooler.Role, true).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"
|
||||||
|
|
|
||||||
|
|
@ -838,9 +838,9 @@ func testResources(cluster *Cluster, podSpec *v1.PodTemplateSpec, role PostgresR
|
||||||
func testLabels(cluster *Cluster, podSpec *v1.PodTemplateSpec, role PostgresRole) error {
|
func testLabels(cluster *Cluster, podSpec *v1.PodTemplateSpec, role PostgresRole) error {
|
||||||
poolerLabels := podSpec.ObjectMeta.Labels["connection-pooler"]
|
poolerLabels := podSpec.ObjectMeta.Labels["connection-pooler"]
|
||||||
|
|
||||||
if poolerLabels != cluster.connectionPoolerLabelsSelector(role).MatchLabels["connection-pooler"] {
|
if poolerLabels != cluster.connectionPoolerLabelsSelector(role, true).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(role).MatchLabels)
|
podSpec.ObjectMeta.Labels, cluster.connectionPoolerLabelsSelector(role, true).MatchLabels)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -848,7 +848,7 @@ func testLabels(cluster *Cluster, podSpec *v1.PodTemplateSpec, role PostgresRole
|
||||||
|
|
||||||
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(Master).MatchLabels
|
expected := cluster.connectionPoolerLabelsSelector(Master, true).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",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue