From abf7eeefae17c9721e50445b4eb818ae9adbf819 Mon Sep 17 00:00:00 2001 From: Gabor Burges Date: Thu, 28 Jul 2022 13:44:55 +0200 Subject: [PATCH] Label the DBs --- .../featureflags/localfeatureflags.go | 2 +- .../providers/inmemorydb/redis.go | 4 +- .../providers/kafka/strimzi.go | 40 ++++++++++++++++ tests/kuttl/test-cyndi-local-db/01-pods.yaml | 3 +- tests/kuttl/test-db-pvc-tee/01-assert.yaml | 2 + .../kuttl/test-db-resource-tee/01-assert.yaml | 3 ++ tests/kuttl/test-ff-local/01-assert.yaml | 2 + .../01-assert.yaml | 23 +++++++++ .../kuttl/test-local-db-redis/00-install.yaml | 7 +++ .../kuttl/test-local-db-redis/01-assert.yaml | 21 ++++++++ tests/kuttl/test-local-db-redis/01-pods.yaml | 48 +++++++++++++++++++ .../kuttl/test-local-db-redis/02-delete.yaml | 10 ++++ 12 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 tests/kuttl/test-local-db-redis/00-install.yaml create mode 100644 tests/kuttl/test-local-db-redis/01-assert.yaml create mode 100644 tests/kuttl/test-local-db-redis/01-pods.yaml create mode 100644 tests/kuttl/test-local-db-redis/02-delete.yaml diff --git a/controllers/cloud.redhat.com/providers/featureflags/localfeatureflags.go b/controllers/cloud.redhat.com/providers/featureflags/localfeatureflags.go index e80ae47cd..8d72b0f57 100644 --- a/controllers/cloud.redhat.com/providers/featureflags/localfeatureflags.go +++ b/controllers/cloud.redhat.com/providers/featureflags/localfeatureflags.go @@ -216,7 +216,7 @@ func makeLocalFeatureFlags(o obj.ClowdObject, objMap providers.ObjectMap, _ bool labels := o.GetLabels() labels["env-app"] = nn.Name - + labels["service"] = "featureflags" labeler := utils.MakeLabeler(nn, labels, o) labeler(dd) diff --git a/controllers/cloud.redhat.com/providers/inmemorydb/redis.go b/controllers/cloud.redhat.com/providers/inmemorydb/redis.go index 4bf1ca709..d36fe093a 100644 --- a/controllers/cloud.redhat.com/providers/inmemorydb/redis.go +++ b/controllers/cloud.redhat.com/providers/inmemorydb/redis.go @@ -10,7 +10,6 @@ import ( apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" rc "github.com/RedHatInsights/rhc-osdk-utils/resourceCache" @@ -94,11 +93,12 @@ func makeLocalRedis(o obj.ClowdObject, objMap providers.ObjectMap, _ bool, nodeP labels := o.GetLabels() labels["env-app"] = nn.Name + labels["service"] = "redis" labeler := utils.MakeLabeler(nn, labels, o) labeler(dd) - dd.Spec.Selector = &metav1.LabelSelector{MatchLabels: labels} + // dd.Spec.Selector = &metav1.LabelSelector{MatchLabels: labels} dd.Spec.Template.ObjectMeta.Labels = labels dd.Spec.Replicas = &oneReplica diff --git a/controllers/cloud.redhat.com/providers/kafka/strimzi.go b/controllers/cloud.redhat.com/providers/kafka/strimzi.go index 96a7de027..d469e7e7d 100644 --- a/controllers/cloud.redhat.com/providers/kafka/strimzi.go +++ b/controllers/cloud.redhat.com/providers/kafka/strimzi.go @@ -287,6 +287,15 @@ func (s *strimziProvider) configureKafkaCluster() error { kafLimits = *s.Env.Spec.Providers.Kafka.Cluster.Resources.Limits } + var klabels apiextensions.JSON + + err = klabels.UnmarshalJSON([]byte(`{ + "service" : "strimziKafka" + }`)) + if err != nil { + return fmt.Errorf("could not unmarshal klabels: %w", err) + } + k.Spec = &strimzi.KafkaSpec{ Kafka: strimzi.KafkaSpecKafka{ Config: &kafConfig, @@ -296,6 +305,18 @@ func (s *strimziProvider) configureKafkaCluster() error { Requests: &kafRequests, Limits: &kafLimits, }, + Template: &strimzi.KafkaSpecKafkaTemplate{ + PerPodService: &strimzi.KafkaSpecKafkaTemplatePerPodService{ + Metadata: &strimzi.KafkaSpecKafkaTemplatePerPodServiceMetadata{ + Labels: &klabels, + }, + }, + Pod: &strimzi.KafkaSpecKafkaTemplatePod{ + Metadata: &strimzi.KafkaSpecKafkaTemplatePodMetadata{ + Labels: &klabels, + }, + }, + }, }, Zookeeper: strimzi.KafkaSpecZookeeper{ Replicas: replicas, @@ -303,8 +324,27 @@ func (s *strimziProvider) configureKafkaCluster() error { Requests: &zRequests, Limits: &zLimits, }, + Template: &strimzi.KafkaSpecZookeeperTemplate{ + NodesService: &strimzi.KafkaSpecZookeeperTemplateNodesService{ + Metadata: &strimzi.KafkaSpecZookeeperTemplateNodesServiceMetadata{ + Labels: &klabels, + }, + }, + Pod: &strimzi.KafkaSpecZookeeperTemplatePod{ + Metadata: &strimzi.KafkaSpecZookeeperTemplatePodMetadata{ + Labels: &klabels, + }, + }, + }, }, EntityOperator: &strimzi.KafkaSpecEntityOperator{ + Template: &strimzi.KafkaSpecEntityOperatorTemplate{ + Pod: &strimzi.KafkaSpecEntityOperatorTemplatePod{ + Metadata: &strimzi.KafkaSpecEntityOperatorTemplatePodMetadata{ + Labels: &klabels, + }, + }, + }, TopicOperator: &strimzi.KafkaSpecEntityOperatorTopicOperator{ Resources: &strimzi.KafkaSpecEntityOperatorTopicOperatorResources{ Requests: &entityTopicRequests, diff --git a/tests/kuttl/test-cyndi-local-db/01-pods.yaml b/tests/kuttl/test-cyndi-local-db/01-pods.yaml index ccb3bd58a..165a55490 100644 --- a/tests/kuttl/test-cyndi-local-db/01-pods.yaml +++ b/tests/kuttl/test-cyndi-local-db/01-pods.yaml @@ -22,7 +22,7 @@ spec: objectStore: mode: none inMemoryDb: - mode: none + mode: redis resourceDefaults: limits: cpu: 400m @@ -49,3 +49,4 @@ spec: database: name: app-a-db version: 12 + inMemoryDb: true \ No newline at end of file diff --git a/tests/kuttl/test-db-pvc-tee/01-assert.yaml b/tests/kuttl/test-db-pvc-tee/01-assert.yaml index 5d6493d8a..1224ec25c 100644 --- a/tests/kuttl/test-db-pvc-tee/01-assert.yaml +++ b/tests/kuttl/test-db-pvc-tee/01-assert.yaml @@ -4,6 +4,8 @@ kind: Deployment metadata: name: app-a-db namespace: test-db-pvc-tee + labels: + service: db spec: template: spec: diff --git a/tests/kuttl/test-db-resource-tee/01-assert.yaml b/tests/kuttl/test-db-resource-tee/01-assert.yaml index 6cc1cfa6a..fcdb834eb 100644 --- a/tests/kuttl/test-db-resource-tee/01-assert.yaml +++ b/tests/kuttl/test-db-resource-tee/01-assert.yaml @@ -7,6 +7,9 @@ metadata: spec: template: spec: + metadata: + labels: + service: db containers: - image: quay.io/cloudservices/postgresql-rds:12-9ee2984 resources: diff --git a/tests/kuttl/test-ff-local/01-assert.yaml b/tests/kuttl/test-ff-local/01-assert.yaml index ba6c65407..e25d2f2ee 100644 --- a/tests/kuttl/test-ff-local/01-assert.yaml +++ b/tests/kuttl/test-ff-local/01-assert.yaml @@ -23,6 +23,8 @@ kind: Deployment metadata: name: test-ff-local-featureflags namespace: test-ff-local + labels: + service: featureflags spec: template: spec: diff --git a/tests/kuttl/test-kafka-strimzi-ephemeral/01-assert.yaml b/tests/kuttl/test-kafka-strimzi-ephemeral/01-assert.yaml index 59b9b08e0..622fffd88 100644 --- a/tests/kuttl/test-kafka-strimzi-ephemeral/01-assert.yaml +++ b/tests/kuttl/test-kafka-strimzi-ephemeral/01-assert.yaml @@ -35,11 +35,34 @@ spec: requests: cpu: 250m memory: 600Mi + template: + perPodService: + metadata: + labels: + service: strimziKafka + pod: + metadata: + labels: + service: strimziKafka zookeeper: replicas: 1 storage: type: ephemeral + template: + nodesService: + metadata: + labels: + service: strimziKafka + pod: + metadata: + labels: + service: strimziKafka entityOperator: + template: + pod: + metadata: + labels: + service: strimziKafka topicOperator: {} --- apiVersion: kafka.strimzi.io/v1beta2 diff --git a/tests/kuttl/test-local-db-redis/00-install.yaml b/tests/kuttl/test-local-db-redis/00-install.yaml new file mode 100644 index 000000000..dafcfa39e --- /dev/null +++ b/tests/kuttl/test-local-db-redis/00-install.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: test-local-db-redis +spec: + finalizers: + - kubernetes diff --git a/tests/kuttl/test-local-db-redis/01-assert.yaml b/tests/kuttl/test-local-db-redis/01-assert.yaml new file mode 100644 index 000000000..9c46cbfd1 --- /dev/null +++ b/tests/kuttl/test-local-db-redis/01-assert.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-a-db + namespace: test-local-db-redis +spec: + template: + spec: + metadata: + labels: + service: redis + containers: + - image: quay.io/cloudservices/redis::3.2.3-alpine + resources: + limits: + cpu: 1800m + memory: 2Gi + requests: + cpu: 1200m + memory: 1Gi diff --git a/tests/kuttl/test-local-db-redis/01-pods.yaml b/tests/kuttl/test-local-db-redis/01-pods.yaml new file mode 100644 index 000000000..41f533434 --- /dev/null +++ b/tests/kuttl/test-local-db-redis/01-pods.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: cloud.redhat.com/v1alpha1 +kind: ClowdEnvironment +metadata: + name: test-local-db-redis +spec: + targetNamespace: test-local-db-redis + providers: + web: + port: 8000 + mode: operator + metrics: + port: 9000 + mode: operator + path: "/metrics" + kafka: + mode: none + db: + mode: none + logging: + mode: none + objectStore: + mode: none + inMemoryDb: + mode: redis + pvc: false + featureFlags: + mode: none + resourceDefaults: + limits: + cpu: 400m + memory: 1024Mi + requests: + cpu: 30m + memory: 512Mi +--- +apiVersion: cloud.redhat.com/v1alpha1 +kind: ClowdApp +metadata: + name: app-a + namespace: test-local-db-redis +spec: + envName: test-local-db-redis + deployments: + - name: processor + podSpec: + image: quay.io/psav/clowder-hello + inMemoryDb: true \ No newline at end of file diff --git a/tests/kuttl/test-local-db-redis/02-delete.yaml b/tests/kuttl/test-local-db-redis/02-delete.yaml new file mode 100644 index 000000000..17923a2eb --- /dev/null +++ b/tests/kuttl/test-local-db-redis/02-delete.yaml @@ -0,0 +1,10 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: +- apiVersion: v1 + kind: Namespace + name: test-local-db-redis +- apiVersion: cloud.redhat.com/v1alpha1 + kind: ClowdEnvironment + name: test-local-db-redis