Skip to content

cleaning up workspace on failure - #362

Merged
tinakurian merged 1 commit into
devfile:mainfrom
tinakurian:338-cleanup-workspace-resources-on-failure
Mar 30, 2021
Merged

tinakurian merged 1 commit into
devfile:mainfrom
tinakurian:338-cleanup-workspace-resources-on-failure

Conversation

@tinakurian

Copy link
Copy Markdown
Contributor

What does this PR do?

Cleans up cluster deployments by scaling them to 0.

What issues does this PR fix or reference?

#338

Is it tested? How?

  1. Applied a sample yaml (Theia)
  2. Wait for devworkspace to be running
  3. Add invalid storage-type label

The result:
image (7)

image (8)

@tinakurian
tinakurian force-pushed the 338-cleanup-workspace-resources-on-failure branch 2 times, most recently from 75d344b to 88582fb Compare March 29, 2021 14:48
@tinakurian

Copy link
Copy Markdown
Contributor Author

/test v5-devworkspaces-operator-e2e

@tinakurian
tinakurian force-pushed the 338-cleanup-workspace-resources-on-failure branch 4 times, most recently from 559bb1e to 78f1963 Compare March 29, 2021 20:16
@tinakurian

Copy link
Copy Markdown
Contributor Author

/test v5-devworkspaces-operator-e2e

@amisevsk amisevsk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

@JPinkney JPinkney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tinakurian

Copy link
Copy Markdown
Contributor Author

/test v5-devworkspaces-operator-e2e

@sleshchenko sleshchenko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Be in rush with merging this and make @amisevsk in charge of adapting his PR :-D

replicaCount := int32(0)
clusterDeployment.Spec.Replicas = &replicaCount

err = client.Update(ctx, clusterDeployment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we can send patch instead of update.
not sure if it's available with that client, just idea.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I should be available

// ScaleDeploymentToZero scales the cluster deployment to zero
func ScaleDeploymentToZero(ctx context.Context, workspace *devworkspace.DevWorkspace, client runtimeClient.Client) error {
	patch := []byte(`{"spec":{"replicas": 0}}`)
	err := client.Patch(context.Background(), &appsv1.Deployment{
		ObjectMeta: metav1.ObjectMeta{
			Namespace: workspace.Namespace,
			Name:      common.DeploymentName(workspace.Status.WorkspaceId),
		},
	}, runtimeClient.RawPatch(types.StrategicMergePatchType, patch))

	if err != nil {
		return err
	}

	return nil
}

@amisevsk WDYT about patching here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've never been able to figure out the semantics of patch; sometimes it does what I expect other times it does not 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've updated to use the patch!

@tinakurian
tinakurian force-pushed the 338-cleanup-workspace-resources-on-failure branch from 2d78ec0 to bfb8062 Compare March 30, 2021 17:01
@tinakurian

Copy link
Copy Markdown
Contributor Author

/test v5-devworkspaces-operator-e2e

@amisevsk amisevsk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Merge away -- I can copy the

err := provision.ScaleDeploymentToZero(workspace, r.Client)
if err != nil {
  return reconcile.Result{}, err
}

lines into my PR when I rebase.

@openshift-ci-robot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amisevsk, JPinkney, sleshchenko, tinakurian

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JPinkney,amisevsk,sleshchenko]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tinakurian
tinakurian merged commit 661c656 into devfile:main Mar 30, 2021
@tinakurian
tinakurian deleted the 338-cleanup-workspace-resources-on-failure branch March 30, 2021 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants