diff --git a/api/v1/prefectserver_types.go b/api/v1/prefectserver_types.go index 0d02feb..60b2225 100644 --- a/api/v1/prefectserver_types.go +++ b/api/v1/prefectserver_types.go @@ -237,6 +237,8 @@ type PrefectServer struct { func (s *PrefectServer) ServerLabels() map[string]string { labels := map[string]string{ "prefect.io/server": s.Name, + "app": "prefect-server", + "version": s.getVersion(), } for k, v := range s.Spec.DeploymentLabels { labels[k] = v @@ -339,3 +341,14 @@ type PrefectServerList struct { func init() { SchemeBuilder.Register(&PrefectServer{}, &PrefectServerList{}) } + +// getVersion returns the version of Prefect. +// The `.spec.version` field is optional, so if it is +// not configured, we return the default version. +func (s *PrefectServer) getVersion() string { + if s.Spec.Version != nil && *s.Spec.Version != "" { + return *s.Spec.Version + } + + return DEFAULT_PREFECT_VERSION +} diff --git a/internal/controller/prefectserver_controller_test.go b/internal/controller/prefectserver_controller_test.go index 79fd5cf..4b2610e 100644 --- a/internal/controller/prefectserver_controller_test.go +++ b/internal/controller/prefectserver_controller_test.go @@ -119,13 +119,15 @@ var _ = Describe("PrefectServer controller", func() { }) It("should allow specifying a Prefect version", func() { + version := "3.3.3.3.3.3.3.3" + expectedImage := fmt.Sprintf("prefecthq/prefect:%s-python3.12", version) prefectserver = &prefectiov1.PrefectServer{ ObjectMeta: metav1.ObjectMeta{ Namespace: namespaceName, Name: "prefect-on-anything", }, Spec: prefectiov1.PrefectServerSpec{ - Version: ptr.To("3.3.3.3.3.3.3.3"), + Version: &version, }, } Expect(k8sClient.Create(ctx, prefectserver)).To(Succeed()) @@ -153,7 +155,9 @@ var _ = Describe("PrefectServer controller", func() { Expect(deployment.Spec.Template.Spec.Containers).To(HaveLen(1)) container := deployment.Spec.Template.Spec.Containers[0] - Expect(container.Image).To(Equal("prefecthq/prefect:3.3.3.3.3.3.3.3-python3.12")) + Expect(container.Image).To(Equal(expectedImage)) + Expect(deployment.Spec.Selector.MatchLabels).To(HaveKeyWithValue("version", version)) + Expect(deployment.Spec.Template.ObjectMeta.Labels).To(HaveKeyWithValue("version", version)) }) Context("when creating any server", func() { @@ -269,11 +273,15 @@ var _ = Describe("PrefectServer controller", func() { It("should have appropriate labels", func() { Expect(deployment.Spec.Selector.MatchLabels).To(Equal(map[string]string{ "prefect.io/server": "prefect-on-anything", + "app": "prefect-server", + "version": prefectiov1.DEFAULT_PREFECT_VERSION, "some": "additional-label", "another": "extra-label", })) Expect(deployment.Spec.Template.Labels).To(Equal(map[string]string{ "prefect.io/server": "prefect-on-anything", + "app": "prefect-server", + "version": prefectiov1.DEFAULT_PREFECT_VERSION, "some": "additional-label", "another": "extra-label", }))