Remove volumeMount on pvc delete

12/6/2019

My usecase is as follows: I have a deployment for a multi-tenant service. This deployment has many mountVolumes associated with it, which are pvcs specific to a tenant. When I delete a tenant, I want to delete the associated pvc as well. And in turn also delete it from the deployment.

I tried using strategic-merge for this:

x.yaml - this contains the patch yaml:

spec:
  template:
    spec:
      volumes:
      - $patch: delete
        name: "tenant-helloworld"

\======================== invoking method:

name = 'test-ms'
with open('resources/x.yaml') as filein:
x_yaml = yaml.load(filein)
pprint(x_yaml)
api_response=client.ExtensionsV1beta1Api(). patch_namespaced_deployment(name=name,namespace=namespace,body=x_yaml,

pretty=True)

\======================== exception on invoking patch_namespaced_deployments:

"status": "Failure", "message": "Deployment.apps \"test-ms\" is invalid: spec.template.spec.containers[0].volumeMounts[9].name: Not found: \"tenant-helloworld\"", "reason": "Invalid", "details": { "name": "test-ms", "group": "apps", "kind": "Deployment", "causes": [ { "reason": "FieldValueNotFound", "message": "Not found: \"tenant-helloworld\"", "field": "spec.template.spec.containers[0].volumeMounts[9].name" } ] }, "code": 422 }

The field is present at volumeMount[9]. Any pointers on where am I going wrong.

-- Anjana
kubernetes
kubernetes-python-client

1 Answer

12/11/2019

The issue was related to formatting of yaml. Hence closing the issue.

-- Anjana
Source: StackOverflow