Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting nodeSelector for Deployment, Job #125

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1/prefectserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type PrefectServerSpec struct {

// MigrationJobLabels defines additional labels to add to the migration Job
MigrationJobLabels map[string]string `json:"migrationJobLabels,omitempty"`

// NodeSelector defines the node selector for the Prefect Server Deployment and migration Job
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

type EphemeralConfiguration struct {
Expand Down
7 changes: 7 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,12 @@ spec:
description: MigrationJobLabels defines additional labels to add to
the migration Job
type: object
nodeSelector:
additionalProperties:
type: string
description: NodeSelector defines the node selector for the Prefect
Server Deployment and migration Job
type: object
postgres:
description: |-
Postgres defines whether the server will be deployed with a PostgreSQL backend connecting to the
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/prefectserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func (r *PrefectServerReconciler) ephemeralDeploymentSpec(server *prefectiov1.Pr
Labels: server.ServerLabels(),
},
Spec: corev1.PodSpec{
NodeSelector: server.Spec.NodeSelector,
Volumes: []corev1.Volume{
{
Name: "prefect-data",
Expand Down Expand Up @@ -419,6 +420,7 @@ func (r *PrefectServerReconciler) sqliteDeploymentSpec(server *prefectiov1.Prefe
Labels: server.ServerLabels(),
},
Spec: corev1.PodSpec{
NodeSelector: server.Spec.NodeSelector,
Volumes: []corev1.Volume{
{
Name: "prefect-data",
Expand Down Expand Up @@ -486,6 +488,7 @@ func (r *PrefectServerReconciler) postgresDeploymentSpec(server *prefectiov1.Pre
Labels: server.ServerLabels(),
},
Spec: corev1.PodSpec{
NodeSelector: server.Spec.NodeSelector,
InitContainers: []corev1.Container{
r.initContainerWaitForPostgres(server),
},
Expand Down Expand Up @@ -534,6 +537,7 @@ func (r *PrefectServerReconciler) postgresMigrationJob(server *prefectiov1.Prefe
Labels: server.MigrationJobLabels(),
},
Spec: corev1.PodSpec{
NodeSelector: server.Spec.NodeSelector,
InitContainers: []corev1.Container{
r.initContainerWaitForPostgres(server),
},
Expand Down
14 changes: 14 additions & 0 deletions internal/controller/prefectserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ var _ = Describe("PrefectServer controller", func() {
"some": "additional-label",
"another": "extra-label",
},
NodeSelector: map[string]string{
"some": "node-selector",
},
},
}
Expect(k8sClient.Create(ctx, prefectserver)).To(Succeed())
Expand Down Expand Up @@ -377,6 +380,10 @@ var _ = Describe("PrefectServer controller", func() {
FailureThreshold: 2,
}))
})

It("should have the correct nodeSelector value", func() {
Expect(deployment.Spec.Template.Spec.NodeSelector).To(HaveKeyWithValue("some", "node-selector"))
})
})

Describe("the Service", func() {
Expand Down Expand Up @@ -1192,6 +1199,9 @@ var _ = Describe("PrefectServer controller", func() {
"some": "additional-label-for-migrations",
"another": "extra-label-for-migrations",
},
NodeSelector: map[string]string{
"some": "node-selector",
},
},
}
Expect(k8sClient.Create(ctx, prefectserver)).To(Succeed())
Expand Down Expand Up @@ -1331,6 +1341,10 @@ var _ = Describe("PrefectServer controller", func() {
{Name: "PREFECT_API_DATABASE_MIGRATE_ON_START", Value: "False"},
}))
})

It("should have the correct nodeSelector value", func() {
Expect(migrateJob.Spec.Template.Spec.NodeSelector).To(HaveKeyWithValue("some", "node-selector"))
})
})
})

Expand Down