Repository: kubernetes/kops (go)

Issue:
nodeAffinity for coredns-autoscaler 
/kind feature

**1. Describe IN DETAIL the feature/behavior/change you would like to see.**

It's possible to change nodeAfinity/tolarations for CoreDNS to schedule deployment on decide node group, 
but for coredns-autoscaler there is no option in [API to define nodeAfinity/tolarations see code  ](https://github.com/kubernetes/kops/blob/v1.24.1/pkg/apis/kops/cluster.go#L525)  or [see docs](https://pkg.go.dev/k8s.io/kops/pkg/apis/kops#KubeDNSConfig)
 
**2. Feel free to provide a design supporting your feature request.**


Pull request:
Set customizable affinity and tolerations for coredns-autoscaler to match main coredns deployment
Fixes #14165 

Patch:
diff --git a/upup/models/cloudup/resources/addons/coredns.addons.k8s.io/k8s-1.12.yaml.template b/upup/models/cloudup/resources/addons/coredns.addons.k8s.io/k8s-1.12.yaml.template
index ccfe6ee910..9ed316c8a9 100644
--- a/upup/models/cloudup/resources/addons/coredns.addons.k8s.io/k8s-1.12.yaml.template
+++ b/upup/models/cloudup/resources/addons/coredns.addons.k8s.io/k8s-1.12.yaml.template
@@ -348,9 +348,17 @@ spec:
           - --v=2
       priorityClassName: system-cluster-critical
       tolerations:
-      - key: "CriticalAddonsOnly"
-        operator: "Exists"
+        {{- if KubeDNS.Tolerations }}
+{{ ToYAML .KubeDNS.Tolerations | indent 8 }}
+        {{- else }}
+        - key: "CriticalAddonsOnly"
+          operator: "Exists"
+        {{- end }}
       serviceAccountName: coredns-autoscaler
       nodeSelector:
         kubernetes.io/os: linux
+{{- if .KubeDNS.Affinity }}
+      affinity:
+{{ ToYAML .KubeDNS.Affinity | indent 8 }}
+{{- end }}
 ---


Test patch:
diff --git a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/coredns.addons.k8s.io-k8s-1.12.yaml b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/coredns.addons.k8s.io-k8s-1.12.yaml
index db6c12faf7..db457bc7f6 100644
--- a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/coredns.addons.k8s.io-k8s-1.12.yaml
+++ b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/coredns.addons.k8s.io-k8s-1.12.yaml
@@ -380,6 +380,27 @@ spec:
         k8s-app: coredns-autoscaler
         kops.k8s.io/managed-by: kops
     spec:
+      affinity:
+        nodeAffinity:
+          requiredDuringSchedulingIgnoredDuringExecution:
+            nodeSelectorTerms:
+            - matchExpressions:
+              - key: kops.k8s.io/instancegroup
+                operator: In
+                values:
+                - master
+                - ondemand-nodes
+        podAntiAffinity:
+          preferredDuringSchedulingIgnoredDuringExecution:
+          - podAffinityTerm:
+              labelSelector:
+                matchExpressions:
+                - key: k8s-app
+                  operator: In
+                  values:
+                  - kube-dns
+              topologyKey: kubernetes.io/hostname
+            weight: 100
       containers:
       - command:
         - /cluster-proportional-autoscaler
@@ -400,5 +421,5 @@ spec:
       priorityClassName: system-cluster-critical
       serviceAccountName: coredns-autoscaler
       tolerations:
-      - key: CriticalAddonsOnly
+      - effect: NoSchedule
         operator: Exists
diff --git a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/manifest.yaml b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/manifest.yaml
index 1b3bbac4f3..28d06caa51 100644
--- a/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/manifest.yaml
+++ b/upup/pkg/fi/cloudup/tests/bootstrapchannelbuilder/coredns/manifest.yaml
@@ -14,7 +14,7 @@ spec:
     version: 9.99.0
   - id: k8s-1.12
     manifest: coredns.addons.k8s.io/k8s-1.12.yaml
-    manifestHash: ce6e3025ee738c71092d5800d046998a6ddae319fd1a55599f4c817b935743bc
+    manifestHash: b8b81e0980542ff1ee37db3421be070a9c618a6978b88b06c4e8907bb6c0b73f
     name: coredns.addons.k8s.io
     selector:
       k8s-addon: coredns.addons.k8s.io