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 extra args in Deployment command #129

Merged
merged 1 commit into from
Nov 1, 2024
Merged
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
8 changes: 7 additions & 1 deletion api/v1/prefectserver_types.go
Original file line number Diff line number Diff line change
@@ -45,6 +45,9 @@ type PrefectServerSpec struct {
// ExtraServicePorts defines additional ports to expose on the Prefect Server Service
ExtraServicePorts []corev1.ServicePort `json:"extraServicePorts,omitempty"`

// ExtraArgs defines additional arguments to pass to the Prefect Server Deployment
ExtraArgs []string `json:"extraArgs,omitempty"`

// Ephemeral defines whether the Prefect Server will be deployed with an ephemeral storage backend
Ephemeral *EphemeralConfiguration `json:"ephemeral,omitempty"`

@@ -281,7 +284,10 @@ func (s *PrefectServer) Image() string {
}

func (s *PrefectServer) Command() []string {
return []string{"prefect", "server", "start", "--host", "0.0.0.0"}
command := []string{"prefect", "server", "start", "--host", "0.0.0.0"}
command = append(command, s.Spec.ExtraArgs...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this really be extraCommands since args are their own field in k8s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm. technically yes, but here we're shoving args into the command field and not specifying any args directly, even though everything after the first one is an arg 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah totally fair


return command
}

func (s *PrefectServer) ToEnvVars() []corev1.EnvVar {
5 changes: 5 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
@@ -60,6 +60,12 @@ spec:
description: Ephemeral defines whether the Prefect Server will be
deployed with an ephemeral storage backend
type: object
extraArgs:
description: ExtraArgs defines additional arguments to pass to the
Prefect Server Deployment
items:
type: string
type: array
extraContainers:
description: ExtraContainers defines additional containers to add
to the Prefect Server Deployment
29 changes: 29 additions & 0 deletions internal/controller/prefectserver_controller_test.go
Original file line number Diff line number Diff line change
@@ -602,6 +602,35 @@ var _ = Describe("PrefectServer controller", func() {
port := service.Spec.Ports[1]
Expect(port.Name).To(Equal("extra-port"))
})

It("should update the Command with the extra args", func() {
// Update the PrefectServer with an extra args
Expect(k8sClient.Get(ctx, name, prefectserver)).To(Succeed())
prefectserver.Spec.ExtraArgs = []string{"--some-arg", "some-value"}

Expect(k8sClient.Update(ctx, prefectserver)).To(Succeed())
// Reconcile to apply the changes
controllerReconciler := &PrefectServerReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
}
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
NamespacedName: name,
})
Expect(err).NotTo(HaveOccurred())

// Check if the Deployment was updated with the extra args
deployment := &appsv1.Deployment{}
Eventually(func() error {
return k8sClient.Get(ctx, types.NamespacedName{
Namespace: namespaceName,
Name: "prefect-on-anything",
}, deployment)
}).Should(Succeed())

container := deployment.Spec.Template.Spec.Containers[0]
Expect(container.Command).To(Equal([]string{"prefect", "server", "start", "--host", "0.0.0.0", "--some-arg", "some-value"}))
})
})

Context("When evaluating changes with any server", func() {