Using Delete Step in Rolling Kubernetes Deployment to Delete Non-Harness Resources

In the below article, we will see the use of the Harness Delete Step to delete non-Harness Resources while running a workflow.

Based on the documentation here : Delete Kubernetes Resources | Harness Developer Hub
There are 2 ways to delete the resources for a rolling deployment where you can either define the resources in the delete step.

Ex: Deployment/harness-example-deployment, Configmap/harness-example-1

Or Use the file path option as defined here : Delete Kubernetes Resources | Harness Developer Hub

Also using * in the resources will remove the resources :
**Deployment/harness-example-deployment **

but not the namespace , if you need to delete namespace as well, you will need to check the :

Also, we could also make use to workflow variables to pass the resource names.

There are ways to use the workflow variables.

So the delete step can help you delete non-harness deployments but you will need to specify the resources.

You will need to do it like Kind/Name ,

Example : Deployment/harness-example-deployment-canary, in case you need to delete multiple resources you can give them with a comma separation.

Now you can create workflow variables say resource and then in the delete step provide it as ${workflow.variables.resource}
and at the runtime mention the resource you want to delete and this will execute and remove it.

Below screenshots from the test workflow :

Using workflow variable in the Resources section

Workflow variables created :

Also we are using a workflow variable for our infra as well whose namespace value we are providing at runtime.

Workflow :

At the runtime we provided all the values :

Execution of the workflow :

1 Like