Skip to content

Commit

Permalink
Apply 'app' and 'version' labels to Server Pods (#119)
Browse files Browse the repository at this point in the history
Applies 'app' and 'version' labels to Server Pods. This is a fairly
common Kubernetes standard, and also allows better tracing in Kiali for
Istio mesh network visualization.

Reference: https://linear.app/prefect/issue/PLA-410/istio-investigate-ambient-mode#comment-3ade7c6c

Related to PLA-410
  • Loading branch information
mitchnielsen authored Oct 21, 2024
1 parent 0c75169 commit d70245b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions api/v1/prefectserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
12 changes: 10 additions & 2 deletions internal/controller/prefectserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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",
}))
Expand Down

0 comments on commit d70245b

Please sign in to comment.