fix: also stop k8s cron tasks when calling ps:stop
This commit is contained in:
@@ -940,3 +940,32 @@ func streamLogsFromRequest(ctx context.Context, request rest.ResponseWrapper, ou
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SuspendCronJobsInput contains all the information needed to suspend a Kubernetes cron job
|
||||
type SuspendCronJobsInput struct {
|
||||
// LabelSelector is the Kubernetes label selector
|
||||
LabelSelector string
|
||||
|
||||
// Namespace is the Kubernetes namespace
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// SuspendCronJobs suspends a Kubernetes cron job
|
||||
func (k KubernetesClient) SuspendCronJobs(ctx context.Context, input SuspendCronJobsInput) error {
|
||||
cronJobs, err := k.Client.BatchV1().CronJobs(input.Namespace).List(ctx, metav1.ListOptions{
|
||||
LabelSelector: input.LabelSelector,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cronJob := range cronJobs.Items {
|
||||
cronJob.Spec.Suspend = ptr.To(true)
|
||||
_, err := k.Client.BatchV1().CronJobs(input.Namespace).Update(ctx, &cronJob, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1499,5 +1499,14 @@ func TriggerSchedulerStop(scheduler string, appName string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// get all cronjobs for the app
|
||||
err = clientset.SuspendCronJobs(ctx, SuspendCronJobsInput{
|
||||
Namespace: namespace,
|
||||
LabelSelector: fmt.Sprintf("app.kubernetes.io/part-of=%s", appName),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error suspending cron jobs: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user