diff --git a/controllers/deployment_test.go b/controllers/deployment_test.go index 949a9499..69f67806 100644 --- a/controllers/deployment_test.go +++ b/controllers/deployment_test.go @@ -116,6 +116,14 @@ var _ = Describe("TrustyAI operator", func() { return k8sClient.Get(ctx, types.NamespacedName{Name: desiredOAuthService.Name, Namespace: namespace}, oauthService) }, "failed to get OAuth Service") + // Check if the OAuth service has the expected labels + Expect(oauthService.Labels["app"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/instance"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/name"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/part-of"]).Should(Equal("trustyai")) + Expect(oauthService.Labels["app.kubernetes.io/version"]).Should(Equal("0.1.0")) + Expect(oauthService.Labels["trustyai-service-name"]).Should(Equal(instance.Name)) + }) }) @@ -189,6 +197,14 @@ var _ = Describe("TrustyAI operator", func() { return k8sClient.Get(ctx, types.NamespacedName{Name: desiredOAuthService.Name, Namespace: namespace}, oauthService) }, "failed to get OAuth Service") + // Check if the OAuth service has the expected labels + Expect(oauthService.Labels["app"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/instance"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/name"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/part-of"]).Should(Equal("trustyai")) + Expect(oauthService.Labels["app.kubernetes.io/version"]).Should(Equal("0.1.0")) + Expect(oauthService.Labels["trustyai-service-name"]).Should(Equal(instance.Name)) + }) }) @@ -336,6 +352,27 @@ var _ = Describe("TrustyAI operator", func() { Expect(deployment.Labels["app.kubernetes.io/part-of"]).Should(Equal(componentName)) Expect(deployment.Labels["app.kubernetes.io/version"]).Should(Equal("0.1.0")) + WaitFor(func() error { + err := reconciler.reconcileOAuthService(ctx, instance) + return err + }, "failed to create oauth service") + + desiredOAuthService, err := generateTrustyAIOAuthService(ctx, instance) + Expect(err).ToNot(HaveOccurred()) + + oauthService := &corev1.Service{} + WaitFor(func() error { + return k8sClient.Get(ctx, types.NamespacedName{Name: desiredOAuthService.Name, Namespace: namespace}, oauthService) + }, "failed to get OAuth Service") + + // Check if the OAuth service has the expected labels + Expect(oauthService.Labels["app"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/instance"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/name"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/part-of"]).Should(Equal("trustyai")) + Expect(oauthService.Labels["app.kubernetes.io/version"]).Should(Equal("0.1.0")) + Expect(oauthService.Labels["trustyai-service-name"]).Should(Equal(instance.Name)) + }) }) }) @@ -400,6 +437,27 @@ var _ = Describe("TrustyAI operator", func() { Expect(deployment.Spec.Template.Spec.Containers[0].Image).Should(Equal("quay.io/trustyai/trustyai-service:latest")) Expect(deployment.Spec.Template.Spec.Containers[1].Image).Should(Equal("registry.redhat.io/openshift4/ose-oauth-proxy:latest")) + WaitFor(func() error { + err := reconciler.reconcileOAuthService(ctx, instance) + return err + }, "failed to create oauth service") + + desiredOAuthService, err := generateTrustyAIOAuthService(ctx, instance) + Expect(err).ToNot(HaveOccurred()) + + oauthService := &corev1.Service{} + WaitFor(func() error { + return k8sClient.Get(ctx, types.NamespacedName{Name: desiredOAuthService.Name, Namespace: instance.Namespace}, oauthService) + }, "failed to get OAuth Service") + + // Check if the OAuth service has the expected labels + Expect(oauthService.Labels["app"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/instance"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/name"]).Should(Equal(instance.Name)) + Expect(oauthService.Labels["app.kubernetes.io/part-of"]).Should(Equal("trustyai")) + Expect(oauthService.Labels["app.kubernetes.io/version"]).Should(Equal("0.1.0")) + Expect(oauthService.Labels["trustyai-service-name"]).Should(Equal(instance.Name)) + } }) }) diff --git a/controllers/templates/service/service-tls.tmpl.yaml b/controllers/templates/service/service-tls.tmpl.yaml index d21c13af..6a5b9b62 100644 --- a/controllers/templates/service/service-tls.tmpl.yaml +++ b/controllers/templates/service/service-tls.tmpl.yaml @@ -6,6 +6,11 @@ metadata: name: {{ .Instance.Name }}-tls namespace: {{ .Instance.Namespace }} labels: + app: {{ .Instance.Name }} + app.kubernetes.io/instance: {{ .Instance.Name }} + app.kubernetes.io/name: {{ .Instance.Name }} + app.kubernetes.io/part-of: trustyai + app.kubernetes.io/version: 0.1.0 trustyai-service-name: {{ .Instance.Name }} spec: ports: