|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * virt/managing-vms/virt-enabling-disabling-vm-delete-protection.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="virt-removing-vm-delete-protection_{context}"] |
| 7 | + |
| 8 | += Removing the virtual machine delete protection option |
| 9 | + |
| 10 | +When you enable delete protection on a virtual machine (VM), you ensure that the VM cannot be inadvertently deleted. You can also choose to disable the protection for a VM. |
| 11 | + |
| 12 | +As a cluster administrator, you can choose not to make the VM delete protection option available. VMs with delete protection already enabled retain that setting; for any new VMs that are created, enabling the option is not allowed. |
| 13 | + |
| 14 | +You can remove the delete protection option by establishing a validation admission policy for the cluster and then creating the necessary binding to use the policy in the cluster. |
| 15 | + |
| 16 | +.Prerequisites |
| 17 | + |
| 18 | +* You must have cluster administrator privileges. |
| 19 | + |
| 20 | +.Procedure |
| 21 | + |
| 22 | +. Create the validation admission policy, as shown in the following example: |
| 23 | ++ |
| 24 | +.Example validation admission policy file |
| 25 | +[source,yaml] |
| 26 | +---- |
| 27 | +apiVersion: admissionregistration.k8s.io/v1 |
| 28 | +kind: ValidatingAdmissionPolicy |
| 29 | +metadata: |
| 30 | + name: "disable-vm-delete-protection" |
| 31 | +spec: |
| 32 | + failurePolicy: Fail |
| 33 | + matchConstraints: |
| 34 | + resourceRules: |
| 35 | + - apiGroups: ["kubevirt.io"] |
| 36 | + apiVersions: ["*"] |
| 37 | + operations: ["UPDATE", "CREATE"] |
| 38 | + resources: ["virtualmachines"] |
| 39 | + variables: |
| 40 | + - expression: string('kubevirt.io/vm-delete-protection') |
| 41 | + name: vmDeleteProtectionLabel |
| 42 | + validations: |
| 43 | + - expression: "!has(object.metadata.labels) || !object.metadata.labels.exists(label, label == variables.vmDeleteProtectionLabel) || has(oldObject.metadata.labels) && \ |
| 44 | + oldObject.metadata.labels.exists(label, label == variables.vmDeleteProtectionLabel)" |
| 45 | + message: "Virtual Machine delete protection feature is disabled" |
| 46 | +---- |
| 47 | + |
| 48 | +. Apply the validation admission policy to the cluster: |
| 49 | ++ |
| 50 | +[source,terminal] |
| 51 | +---- |
| 52 | +$ oc apply -f disable-vm-delete-protection.yaml |
| 53 | +---- |
| 54 | + |
| 55 | +. Create the validation admission policy binding, as shown in the following example: |
| 56 | ++ |
| 57 | +.Example validation admission policy binding file |
| 58 | +[source,yaml] |
| 59 | +---- |
| 60 | +apiVersion: admissionregistration.k8s.io/v1 |
| 61 | +kind: ValidatingAdmissionPolicyBinding |
| 62 | +metadata: |
| 63 | + name: "disable-vm-delete-protection-binding" |
| 64 | +spec: |
| 65 | + policyName: "disable-vm-delete-protection" |
| 66 | + validationActions: [Deny] |
| 67 | + matchResources: |
| 68 | +---- |
| 69 | + |
| 70 | +. Apply the validation admission policy binding to the cluster: |
| 71 | ++ |
| 72 | +[source,terminal] |
| 73 | +---- |
| 74 | +$ oc apply -f disable-vm-delete-protection-binding.yaml |
| 75 | +---- |
0 commit comments