Repository: kubermatic/machine-controller
Pull request #1504 (2022-12-02 08:56:04)

Set EvictionStrategy to external on KubeVirt VMs
**What this PR does / why we need it**:
This change will block automatic VMs eviction which will then need to be handled externally. #1501 

**What type of PR is this?**
<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind design

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
/kind chore
-->

**Does this PR introduce a user-facing change? Then add your Release Note here**:
<!--
Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
```release-note
KubeVirt: Set eviction strategy of VMIs to external
```

**Documentation**:
<!--
Please do one of the following options:
- Add a link to the existing documentation
- Add a link to the kubermatic/docs pull request
- If no documentation change is applicable then add:
  - TBD (documentation will be added later)
  - NONE (no documentation needed for this PR)
-->
```documentation
NONE
```


kubermatic-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/1504#" title="Author self-approved">dermorz</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign sankalp-r for approval by writing `/assign @sankalp-r` in a comment. For more information see:[The Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubermatic%2Fmachine-controller).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubermatic/machine-controller/blob/main/OWNERS)**
- ~~[pkg/cloudprovider/provider/kubevirt/OWNERS](https://github.com/kubermatic/machine-controller/blob/main/pkg/cloudprovider/provider/kubevirt/OWNERS)~~ [dermorz]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["sankalp-r"]} -->
hdurand0710: /lgtm
kubermatic-bot: LGTM label has been added.  <details>Git tree hash: 1d6b0862eaae87f7391ad6fab931f85643562884</details>
kubermatic-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/1504#" title="Author self-approved">dermorz</a>*
**Once this PR has been reviewed and has the lgtm label**, please ask for approval from hdurand0710 by writing `/assign @hdurand0710` in a comment. For more information see:[The Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubermatic%2Fmachine-controller).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubermatic/machine-controller/blob/main/OWNERS)**
- ~~[pkg/cloudprovider/provider/kubevirt/OWNERS](https://github.com/kubermatic/machine-controller/blob/main/pkg/cloudprovider/provider/kubevirt/OWNERS)~~ [dermorz]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["hdurand0710"]} -->
kubermatic-bot: LGTM label has been added.  <details>Git tree hash: 8038c9d5b656c64b94336a7fc27978a940f21571</details>
kubermatic-bot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubermatic/machine-controller/pull/1504#" title="Author self-approved">dermorz</a>*, *<a href="https://github.com/kubermatic/machine-controller/pull/1504#pullrequestreview-1202249283" title="LGTM">mfranczy</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubermatic%2Fmachine-controller).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubermatic/machine-controller/blob/main/OWNERS)~~ [mfranczy]
- ~~[pkg/cloudprovider/provider/kubevirt/OWNERS](https://github.com/kubermatic/machine-controller/blob/main/pkg/cloudprovider/provider/kubevirt/OWNERS)~~ [dermorz,mfranczy]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
kubermatic-bot: @dermorz: The following test **failed**, say `/retest` to rerun all failed tests or `/retest-required` to rerun all mandatory failed tests:

Test name | Commit | Details | Required | Rerun command
--- | --- | --- | --- | ---
pull-machine-controller-e2e-azure | b18e032fbc5e0f0a3d13157cae45c3c7ec0a9bcb | [link](https://public-prow.loodse.com/view/gs/prow-dev-public-data/pr-logs/pull/kubermatic_machine-controller/1504/pull-machine-controller-e2e-azure/1598613728943673344) | true | `/test pull-machine-controller-e2e-azure`

[Full PR test history](https://public-prow.loodse.com/pr-history?org=kubermatic&repo=machine-controller&pr=1504)

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->

Patch:
diff --git a/docs/kubevirt.md b/docs/kubevirt.md
index 2f86ba15..819d8414 100644
--- a/docs/kubevirt.md
+++ b/docs/kubevirt.md
@@ -12,6 +12,7 @@ are some things you need to keep in mind:
 
 * The machine-controller will create `VMIs` that have the same name as the underlying `machine`. To
 avoid collisions, use one namespace per cluster that runs the `machine-controller`
+* EvictionStratey of `VMIs` is set to external, so VMI eviction needs to handled properly by a custom external controller or manual action
 * Service CIDR range: The CIDR ranges of the cluster that runs Kubevirt and the cluster that hosts the machine-controller must not overlap,
 otherwise routing of services that run in the kubevirt cluster won't work anymore. This is especially important for the DNS ClusterIP.
 * `clusterName` is used to [label VMs](https://github.com/kubevirt/cloud-provider-kubevirt#prerequisites) for LoadBalancer selection
diff --git a/pkg/cloudprovider/provider/kubevirt/provider.go b/pkg/cloudprovider/provider/kubevirt/provider.go
index 9f28e1f7..e85bc265 100644
--- a/pkg/cloudprovider/provider/kubevirt/provider.go
+++ b/pkg/cloudprovider/provider/kubevirt/provider.go
@@ -597,6 +597,8 @@ func (p *provider) newVirtualMachine(ctx context.Context, c *Config, pc *provide
 	// The secret has an ownerRef on the VMI so garbace collection will take care of cleaning up.
 	terminationGracePeriodSeconds := int64(30)
 
+	evictionStrategy := kubevirtv1.EvictionStrategyExternal
+
 	resourceRequirements := kubevirtv1.ResourceRequirements{}
 	labels := map[string]string{"kubevirt.io/vm": machine.Name}
 	//Add a common label to all VirtualMachines spawned by the same MachineDeployment (= MachineDeployment name).
@@ -652,6 +654,7 @@ func (p *provider) newVirtualMachine(ctx context.Context, c *Config, pc *provide
 					Labels:      labels,
 				},
 				Spec: kubevirtv1.VirtualMachineInstanceSpec{
+					EvictionStrategy: &evictionStrategy,
 					Networks: []kubevirtv1.Network{
 						*kubevirtv1.DefaultPodNetwork(),
 					},


Test patch:
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/affinity.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/affinity.yaml
index fb239207..309e30d7 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/affinity.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/affinity.yaml
@@ -83,3 +83,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/custom-local-disk.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/custom-local-disk.yaml
index 5c1a645a..e10d07c6 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/custom-local-disk.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/custom-local-disk.yaml
@@ -75,3 +75,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/http-image-source.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/http-image-source.yaml
index b350d205..3bf7731e 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/http-image-source.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/http-image-source.yaml
@@ -74,3 +74,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-custom.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-custom.yaml
index d6e7abc6..060171c4 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-custom.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-custom.yaml
@@ -73,3 +73,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-standard.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-standard.yaml
index 19457b9c..b56229f6 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-standard.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/instancetype-preference-standard.yaml
@@ -73,3 +73,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/nominal-case.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/nominal-case.yaml
index f49ddf69..5dddb4b5 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/nominal-case.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/nominal-case.yaml
@@ -74,3 +74,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/pvc-image-source.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/pvc-image-source.yaml
index b78a189c..2cafabbd 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/pvc-image-source.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/pvc-image-source.yaml
@@ -75,3 +75,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/secondary-disks.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/secondary-disks.yaml
index ec218648..576172c9 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/secondary-disks.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/secondary-disks.yaml
@@ -110,5 +110,6 @@ spec:
             name: secondary-disks-secondarydisk0
           name: secondary-disks-secondarydisk0
         - dataVolume:
-           name: secondary-disks-secondarydisk1
+            name: secondary-disks-secondarydisk1
           name: secondary-disks-secondarydisk1
+      evictionStrategy: External
diff --git a/pkg/cloudprovider/provider/kubevirt/testdata/topologyspreadconstraints.yaml b/pkg/cloudprovider/provider/kubevirt/testdata/topologyspreadconstraints.yaml
index fdfa6fc5..a36f6b84 100644
--- a/pkg/cloudprovider/provider/kubevirt/testdata/topologyspreadconstraints.yaml
+++ b/pkg/cloudprovider/provider/kubevirt/testdata/topologyspreadconstraints.yaml
@@ -80,3 +80,4 @@ spec:
             secretRef:
               name: udsn
           name: cloudinitdisk
+      evictionStrategy: External