refactor poolerLabels function
This commit is contained in:
parent
eb640ebd97
commit
6c1084972b
|
|
@ -78,25 +78,18 @@ 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) connectionPoolerLabels(role PostgresRole, moreLabels bool) *metav1.LabelSelector {
|
func (c *Cluster) connectionPoolerLabels(role PostgresRole, spiloRole bool) *metav1.LabelSelector {
|
||||||
connectionPoolerLabels := labels.Set(map[string]string{})
|
connectionPoolerLabels := c.labelsSet(false)
|
||||||
|
|
||||||
var extraLabels map[string]string
|
extraLabels := map[string]string{
|
||||||
|
"connection-pooler": c.connectionPoolerName(role),
|
||||||
if moreLabels {
|
"application": "db-connection-pooler",
|
||||||
extraLabels = labels.Set(map[string]string{
|
}
|
||||||
"connection-pooler": c.connectionPoolerName(role),
|
|
||||||
"application": "db-connection-pooler",
|
if spiloRole {
|
||||||
"spilo-role": string(role),
|
extraLabels["spilo-role"] = string(role)
|
||||||
})
|
|
||||||
} 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, extraLabels)
|
connectionPoolerLabels = labels.Merge(connectionPoolerLabels, extraLabels)
|
||||||
|
|
||||||
return &metav1.LabelSelector{
|
return &metav1.LabelSelector{
|
||||||
|
|
@ -291,7 +284,7 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
|
||||||
|
|
||||||
podTemplate := &v1.PodTemplateSpec{
|
podTemplate := &v1.PodTemplateSpec{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: c.connectionPoolerLabels(role, false).MatchLabels,
|
Labels: c.connectionPoolerLabels(role, true).MatchLabels,
|
||||||
Namespace: c.Namespace,
|
Namespace: c.Namespace,
|
||||||
Annotations: c.generatePodAnnotations(spec),
|
Annotations: c.generatePodAnnotations(spec),
|
||||||
},
|
},
|
||||||
|
|
@ -396,7 +389,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.connectionPoolerLabels(connectionPooler.Role, true).MatchLabels,
|
Labels: c.connectionPoolerLabels(connectionPooler.Role, false).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"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue