@Override
	public void postHook(WorkflowContext context) throws HyscaleException {
		logger.debug("Cleaning up stale volumes ");
		ApiClient apiClient = clientProvider.get((K8sAuthorisation) context.getAuthConfig());
		String serviceName = context.getServiceName();
		String appName = context.getAppName();
		String namespace = context.getNamespace();
		String envName = context.getEnvName();
		List<Manifest> mainfestList = (List<Manifest>) context.getAttribute(WorkflowConstants.GENERATED_MANIFESTS);
		if (mainfestList == null || mainfestList.isEmpty()) {
			logger.debug("No resource to cleanup");
			return;
		}
		String selector = ResourceSelectorUtil.getSelector(appName, envName, serviceName);
		for (Manifest manifest : mainfestList) {
			try {
				KubernetesResource k8sResource = KubernetesResourceUtil.getKubernetesResource(manifest, namespace);
				if(k8sResource == null) continue;
				ResourceLifeCycleHandler lifeCycleHandler = ResourceHandlers.getHandlerOf(k8sResource.getKind());
				if (lifeCycleHandler != null) {
					if (ResourceKind.STATEFUL_SET.getKind().equalsIgnoreCase(lifeCycleHandler.getKind())) {
						cleanUpOldVolumes(false, apiClient, selector, namespace);
					} else if (ResourceKind.DEPLOYMENT.getKind().equalsIgnoreCase(lifeCycleHandler.getKind())) {
						// Delete all pvcs
						cleanUpOldVolumes(true, apiClient, selector, namespace);
					}
				}
			} catch (Exception e) {
				HyscaleException ex = new HyscaleException(e, DeployerErrorCodes.FAILED_TO_READ_MANIFEST);
				logger.error("Error while cleaning old pvcs", ex);
				return;
			}
		}
	}
Hook to clean up stale volumes on the cluster

@author tushart
workflow-controller/controller-service/src/main/java/io/hyscale/controller/hooks/VolumeCleanUpHook.java