Skip to content

Commit 5a0fc87

Browse files
authored
postStart hook commands timeout (#1440)
* feat: timeout the postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * chore: run make update_devworkspace_api update_devworkspace_crds generate_all Signed-off-by: Oleksii Kurinnyi <[email protected]> * test: add/update tests related to postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! chore: run make update_devworkspace_api update_devworkspace_crds generate_all Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! test: add/update tests related to postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! feat: timeout the postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! test: add/update tests related to postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! feat: timeout the postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! fixup! test: add/update tests related to postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! fixup! feat: timeout the postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! fixup! fixup! test: add/update tests related to postStart hook commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fix: fall back to the original behaviour if timeout is disabled Signed-off-by: Oleksii Kurinnyi <[email protected]> * fix: add postStartTimeout Signed-off-by: Oleksii Kurinnyi <[email protected]> * fix: remove default postStartTimeout value Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fix: remove default postStartTimeout value Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fix: fall back to the original behaviour if timeout is disabled Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! fix: fall back to the original behaviour if timeout is disabled Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! fixup! fix: fall back to the original behaviour if timeout is disabled Signed-off-by: Oleksii Kurinnyi <[email protected]> * fix: support env var for postStart commands Signed-off-by: Oleksii Kurinnyi <[email protected]> * fix: change type `*int32` to `string` Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fix: change type `*int32` to `string` Signed-off-by: Oleksii Kurinnyi <[email protected]> * fixup! fixup! fix: change type `*int32` to `string` Signed-off-by: Oleksii Kurinnyi <[email protected]> --------- Signed-off-by: Oleksii Kurinnyi <[email protected]>
1 parent a6a3e62 commit 5a0fc87

19 files changed

+887
-26
lines changed

apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ type WorkspaceConfig struct {
189189
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
190190
// CleanupCronJobConfig defines configuration options for a cron job that automatically cleans up stale DevWorkspaces.
191191
CleanupCronJob *CleanupCronJobConfig `json:"cleanupCronJob,omitempty"`
192+
// PostStartTimeout defines the maximum duration the PostStart hook can run
193+
// before it is automatically failed. This timeout is used for the postStart lifecycle hook
194+
// that is used to run commands in the workspace container. The timeout is specified in seconds.
195+
// Duration should be specified in a format parseable by Go's time package, e.g. "20s", "2m".
196+
// If not specified or "0", the timeout is disabled.
197+
// +kubebuilder:validation:Optional
198+
PostStartTimeout string `json:"postStartTimeout,omitempty"`
192199
}
193200

194201
type WebhookConfig struct {

controllers/workspace/devworkspace_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
327327
&workspace.Spec.Template,
328328
workspace.Config.Workspace.ContainerSecurityContext,
329329
workspace.Config.Workspace.ImagePullPolicy,
330-
workspace.Config.Workspace.DefaultContainerResources)
330+
workspace.Config.Workspace.DefaultContainerResources,
331+
workspace.Config.Workspace.PostStartTimeout,
332+
)
331333
if err != nil {
332334
return r.failWorkspace(workspace, fmt.Sprintf("Error processing devfile: %s", err), metrics.ReasonBadRequest, reqLogger, &reconcileStatus), nil
333335
}

deploy/bundle/manifests/controller.devfile.io_devworkspaceoperatorconfigs.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/deployment/kubernetes/combined.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/deployment/kubernetes/objects/devworkspaceoperatorconfigs.controller.devfile.io.CustomResourceDefinition.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/deployment/openshift/combined.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/deployment/openshift/objects/devworkspaceoperatorconfigs.controller.devfile.io.CustomResourceDefinition.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/templates/crd/bases/controller.devfile.io_devworkspaceoperatorconfigs.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/sync.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ func mergeConfig(from, to *controller.OperatorConfiguration) {
431431
to.Workspace.CleanupCronJob.Schedule = from.Workspace.CleanupCronJob.Schedule
432432
}
433433
}
434+
435+
if from.Workspace.PostStartTimeout != "" {
436+
to.Workspace.PostStartTimeout = from.Workspace.PostStartTimeout
437+
}
434438
}
435439
}
436440

@@ -601,6 +605,9 @@ func GetCurrentConfigString(currConfig *controller.OperatorConfiguration) string
601605
if workspace.IdleTimeout != defaultConfig.Workspace.IdleTimeout {
602606
config = append(config, fmt.Sprintf("workspace.idleTimeout=%s", workspace.IdleTimeout))
603607
}
608+
if workspace.PostStartTimeout != defaultConfig.Workspace.PostStartTimeout {
609+
config = append(config, fmt.Sprintf("workspace.postStartTimeout=%s", workspace.PostStartTimeout))
610+
}
604611
if workspace.ProgressTimeout != "" && workspace.ProgressTimeout != defaultConfig.Workspace.ProgressTimeout {
605612
config = append(config, fmt.Sprintf("workspace.progressTimeout=%s", workspace.ProgressTimeout))
606613
}

pkg/library/container/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
// rewritten as Volumes are added to PodAdditions, in order to support e.g. using one PVC to hold all volumes
4646
//
4747
// Note: Requires DevWorkspace to be flattened (i.e. the DevWorkspace contains no Parent or Components of type Plugin)
48-
func GetKubeContainersFromDevfile(workspace *dw.DevWorkspaceTemplateSpec, securityContext *corev1.SecurityContext, pullPolicy string, defaultResources *corev1.ResourceRequirements) (*v1alpha1.PodAdditions, error) {
48+
func GetKubeContainersFromDevfile(workspace *dw.DevWorkspaceTemplateSpec, securityContext *corev1.SecurityContext, pullPolicy string, defaultResources *corev1.ResourceRequirements, postStartTimeout string) (*v1alpha1.PodAdditions, error) {
4949
if !flatten.DevWorkspaceIsFlattened(workspace, nil) {
5050
return nil, fmt.Errorf("devfile is not flattened")
5151
}
@@ -77,7 +77,7 @@ func GetKubeContainersFromDevfile(workspace *dw.DevWorkspaceTemplateSpec, securi
7777
podAdditions.Containers = append(podAdditions.Containers, *k8sContainer)
7878
}
7979

80-
if err := lifecycle.AddPostStartLifecycleHooks(workspace, podAdditions.Containers); err != nil {
80+
if err := lifecycle.AddPostStartLifecycleHooks(workspace, podAdditions.Containers, postStartTimeout); err != nil {
8181
return nil, err
8282
}
8383

0 commit comments

Comments
 (0)