Skip to content

Commit 0c6c76f

Browse files
authored
Merge pull request #46 from cybertec-postgresql/test_fix
Fix for labels selector
2 parents 1f5b678 + c05d9cc commit 0c6c76f

8 files changed

Lines changed: 32 additions & 26 deletions

File tree

pkg/cluster/connection_pooler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ func (c *Cluster) poolerUser(spec *cpov1.PostgresSpec) string {
111111

112112
// when listing pooler k8s objects
113113
func (c *Cluster) poolerLabelsSet(addExtraLabels bool) labels.Set {
114-
return c.labelsSetWithType(addExtraLabels, TYPE_POOLER)
114+
115+
poolerLabels := c.labelsSet(addExtraLabels)
116+
// TODO should be config values
117+
poolerLabels["application"] = "db-connection-pooler"
118+
return poolerLabels
119+
//return c.labelsSetWithType(addExtraLabels, TYPE_POOLER)
115120
}
116121

117122
// Return connection pooler labels selector, which should from one point of view

pkg/cluster/connection_pooler_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
"strings"
88
"testing"
99

10-
"github.com/stretchr/testify/assert"
1110
cpov1 "github.com/cybertec-postgresql/cybertec-pg-operator/pkg/apis/cpo.opensource.cybertec.at/v1"
1211
fakecpov1 "github.com/cybertec-postgresql/cybertec-pg-operator/pkg/generated/clientset/versioned/fake"
1312
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util"
1413
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/config"
1514
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/constants"
1615
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/k8sutil"
16+
"github.com/stretchr/testify/assert"
1717

1818
appsv1 "k8s.io/api/apps/v1"
1919
v1 "k8s.io/api/core/v1"
@@ -65,12 +65,12 @@ func objectsAreSaved(cluster *Cluster, err error, reason SyncReason) error {
6565
}
6666

6767
for _, role := range []PostgresRole{Master, Replica} {
68-
poolerLabels := cluster.labelsSet(false)
68+
poolerLabels := cluster.poolerLabelsSet(false)
6969
poolerLabels["application"] = "db-connection-pooler"
7070
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(role)
7171

7272
if cluster.ConnectionPooler[role].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[role].Deployment.Labels, poolerLabels) {
73-
return fmt.Errorf("Deployment was not saved or labels not attached %s %s", role, cluster.ConnectionPooler[role].Deployment.Labels)
73+
return fmt.Errorf("Deployment was not saved or labels not attached role = %s Labels = %s PoolerLabels=%s", role, cluster.ConnectionPooler[role].Deployment.Labels, poolerLabels)
7474
}
7575

7676
if cluster.ConnectionPooler[role].Service == nil || !util.MapContains(cluster.ConnectionPooler[role].Service.Labels, poolerLabels) {
@@ -86,12 +86,12 @@ func MasterObjectsAreSaved(cluster *Cluster, err error, reason SyncReason) error
8686
return fmt.Errorf("Connection pooler resources are empty")
8787
}
8888

89-
poolerLabels := cluster.labelsSet(false)
89+
poolerLabels := cluster.poolerLabelsSet(false)
9090
poolerLabels["application"] = "db-connection-pooler"
9191
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(Master)
9292

9393
if cluster.ConnectionPooler[Master].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[Master].Deployment.Labels, poolerLabels) {
94-
return fmt.Errorf("Deployment was not saved or labels not attached %s", cluster.ConnectionPooler[Master].Deployment.Labels)
94+
return fmt.Errorf("Deployment was not saved or labels not attached for MAster %s pooler labels are %s", cluster.ConnectionPooler[Master].Deployment.Labels, poolerLabels)
9595
}
9696

9797
if cluster.ConnectionPooler[Master].Service == nil || !util.MapContains(cluster.ConnectionPooler[Master].Service.Labels, poolerLabels) {
@@ -106,12 +106,12 @@ func ReplicaObjectsAreSaved(cluster *Cluster, err error, reason SyncReason) erro
106106
return fmt.Errorf("Connection pooler resources are empty")
107107
}
108108

109-
poolerLabels := cluster.labelsSet(false)
109+
poolerLabels := cluster.poolerLabelsSet(false)
110110
poolerLabels["application"] = "db-connection-pooler"
111111
poolerLabels["connection-pooler"] = cluster.connectionPoolerName(Replica)
112112

113113
if cluster.ConnectionPooler[Replica].Deployment == nil || !util.MapContains(cluster.ConnectionPooler[Replica].Deployment.Labels, poolerLabels) {
114-
return fmt.Errorf("Deployment was not saved or labels not attached %s", cluster.ConnectionPooler[Replica].Deployment.Labels)
114+
return fmt.Errorf("Deployment was not saved or labels not attached for Replica %s pooler labels are %s", cluster.ConnectionPooler[Replica].Deployment.Labels, poolerLabels)
115115
}
116116

117117
if cluster.ConnectionPooler[Replica].Service == nil || !util.MapContains(cluster.ConnectionPooler[Replica].Service.Labels, poolerLabels) {

pkg/cluster/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ func (c *Cluster) syncPgbackrestJob(forceRemove bool) error {
16321632
if err := c.createPgbackrestJob(job); err != nil {
16331633
return fmt.Errorf("could not create a pgbackrest cronjob: %v", err)
16341634
}
1635-
c.logger.Info("pgbackrest cronjob for %v %v has been successfully created", rep, schedul)
1635+
c.logger.Infof("pgbackrest cronjob for %v %v has been successfully created", rep, schedul)
16361636
}
16371637
}
16381638
}

pkg/cluster/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ func (c *Cluster) roleLabelsSet(shouldAddExtraLabels bool, role PostgresRole) la
557557
var lbls labels.Set
558558
// Ignore PodRoleLabel for Role ClusterPods
559559
if role != ClusterPods {
560-
lbls = c.labelsSetWithType(shouldAddExtraLabels, TYPE_POSTGRESQL)
560+
lbls = c.labelsSet(shouldAddExtraLabels) //c.labelsSetWithType(shouldAddExtraLabels, TYPE_POSTGRESQL)
561561
lbls[c.OpConfig.PodRoleLabel] = string(role)
562562
} else {
563563
lbls = c.labelsSetWithType(shouldAddExtraLabels, "")

pkg/cluster/volumes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ func (c *Cluster) syncEbsVolumes() error {
230230
func (c *Cluster) listPersistentVolumeClaims() ([]v1.PersistentVolumeClaim, error) {
231231
ns := c.Namespace
232232
listOptions := metav1.ListOptions{
233-
LabelSelector: c.labelsSetWithType(false, TYPE_POSTGRESQL).String(),
233+
//LabelSelector: c.labelsSetWithType(false, TYPE_POSTGRESQL).String(),
234+
LabelSelector: c.labelsSet(false).String(),
234235
}
235236

236237
pvcs, err := c.KubeClient.PersistentVolumeClaims(ns).List(context.TODO(), listOptions)

pkg/cluster/volumes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import (
1414
"github.com/aws/aws-sdk-go/aws"
1515
"github.com/golang/mock/gomock"
1616

17-
"github.com/stretchr/testify/assert"
1817
"github.com/cybertec-postgresql/cybertec-pg-operator/mocks"
1918
cpov1 "github.com/cybertec-postgresql/cybertec-pg-operator/pkg/apis/cpo.opensource.cybertec.at/v1"
2019
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/config"
2120
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/constants"
2221
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/k8sutil"
2322
"github.com/cybertec-postgresql/cybertec-pg-operator/pkg/util/volumes"
23+
"github.com/stretchr/testify/assert"
2424
"k8s.io/client-go/kubernetes/fake"
2525
)
2626

pkg/generated/clientset/versioned/fake/register.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/generated/clientset/versioned/scheme/register.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)