Called podAntiAffinity function as suggested by slintes
@@ -437,6 +437,7 @@ func NewOperatorDeployment(namespace string, repository string, imagePrefix stri
kubeVirtVersionEnv string, virtApiShaEnv string, virtControllerShaEnv string,
virtHandlerShaEnv string, virtLauncherShaEnv string) (*appsv1.Deployment, error) {
+ podAntiAffinity := newPodAntiAffinity("kubevirt.io", "kubernetes.io/hostname", metav1.LabelSelectorOpIn, []string{"virt-operator"})
name := "virt-operator"
version = AddVersionSeparatorPrefix(version)
image := fmt.Sprintf("%s/%s%s%s", repository, imagePrefix, name, version)
@@ -481,27 +482,7 @@ func NewOperatorDeployment(namespace string, repository string, imagePrefix stri
Name: name,
},
Spec: corev1.PodSpec{
- Affinity: &corev1.Affinity{
- PodAntiAffinity: &corev1.PodAntiAffinity{
- PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
- {
- Weight: 1,
- PodAffinityTerm: corev1.PodAffinityTerm{
- LabelSelector: &metav1.LabelSelector{
- MatchExpressions: []metav1.LabelSelectorRequirement{
- {
- Key: virtv1.AppLabel,
- Operator: metav1.LabelSelectorOpIn,
- Values: []string{name},
- },
- },
- },
- TopologyKey: "kubernetes.io/hostname",
- },
- },
- },
- },
- },
+ Affinity: podAntiAffinity,
ServiceAccountName: "kubevirt-operator",
Containers: []corev1.Container{
{
