Skip to content

Commit

Permalink
Add missing labels to OAuth service (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruivieira authored Jan 31, 2024
1 parent 7282090 commit 790a412
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
58 changes: 58 additions & 0 deletions controllers/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

})
})

Expand Down Expand Up @@ -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))

})
})

Expand Down Expand Up @@ -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))

})
})
})
Expand Down Expand Up @@ -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))

}
})
})
Expand Down
5 changes: 5 additions & 0 deletions controllers/templates/service/service-tls.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 790a412

Please sign in to comment.