From 362601cd664255602ba9c874475fdce8b80ae6e4 Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Wed, 21 Dec 2022 18:26:36 +0200 Subject: [PATCH 1/2] Allow migration from Gossip DNS to no DNS --- pkg/apis/kops/cluster.go | 6 +++--- upup/pkg/fi/cloudup/template_functions.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/apis/kops/cluster.go b/pkg/apis/kops/cluster.go index f18c679d63..81f65d8241 100644 --- a/pkg/apis/kops/cluster.go +++ b/pkg/apis/kops/cluster.go @@ -820,10 +820,10 @@ func (c *Cluster) IsSharedAzureRouteTable() bool { } func (c *Cluster) IsGossip() bool { - if dns.IsGossipClusterName(c.Name) { - return true + if c.UsesNoneDNS() || !dns.IsGossipClusterName(c.Name) { + return false } - return false + return true } func (c *Cluster) UsesPublicDNS() bool { diff --git a/upup/pkg/fi/cloudup/template_functions.go b/upup/pkg/fi/cloudup/template_functions.go index 507268faae..6441128ea2 100644 --- a/upup/pkg/fi/cloudup/template_functions.go +++ b/upup/pkg/fi/cloudup/template_functions.go @@ -45,15 +45,14 @@ import ( "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" - "k8s.io/kops/pkg/flagbuilder" - "sigs.k8s.io/yaml" - kopscontrollerconfig "k8s.io/kops/cmd/kops-controller/pkg/config" "k8s.io/kops/pkg/apis/kops" apiModel "k8s.io/kops/pkg/apis/kops/model" "k8s.io/kops/pkg/apis/kops/util" "k8s.io/kops/pkg/apis/nodeup" + "k8s.io/kops/pkg/dns" "k8s.io/kops/pkg/featureflag" + "k8s.io/kops/pkg/flagbuilder" "k8s.io/kops/pkg/kubemanifest" "k8s.io/kops/pkg/model" "k8s.io/kops/pkg/model/components/kopscontroller" @@ -66,6 +65,7 @@ import ( gcetpm "k8s.io/kops/upup/pkg/fi/cloudup/gce/tpm" "k8s.io/kops/upup/pkg/fi/cloudup/hetzner" "k8s.io/kops/util/pkg/env" + "sigs.k8s.io/yaml" ) // TemplateFunctions provides a collection of methods used throughout the templates @@ -127,7 +127,7 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS dest["GossipDomains"] = func() []string { var names []string - if cluster.IsGossip() { + if dns.IsGossipClusterName(cluster.Name) { names = append(names, "k8s.local") } From b08d53a131535ef678e285cba99acd79cfc46053 Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Fri, 23 Dec 2022 08:04:13 +0200 Subject: [PATCH 2/2] Refactor Gossip usage in addon templates --- .../k8s-1.12.yaml.template | 8 ++++---- .../k8s-1.16.yaml.template | 4 ++-- upup/pkg/fi/cloudup/template_functions.go | 17 ++++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) 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 71b43de01d..db376a4cb1 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 @@ -76,8 +76,8 @@ data: fallthrough in-addr.arpa ip6.arpa ttl 30 } - {{- if GossipDomains }} - hosts /rootfs/etc/hosts {{ join " " GossipDomains }} { + {{- if GossipName }} + hosts /rootfs/etc/hosts k8s.local { ttl 30 fallthrough } @@ -167,7 +167,7 @@ spec: - name: config-volume mountPath: /etc/coredns readOnly: true -{{- if GossipDomains }} +{{- if GossipName }} - name: etc-hosts mountPath: /rootfs/etc/hosts readOnly: true @@ -209,7 +209,7 @@ spec: - name: config-volume configMap: name: coredns -{{- if GossipDomains }} +{{- if GossipName }} - name: etc-hosts hostPath: path: /etc/hosts diff --git a/upup/models/cloudup/resources/addons/kops-controller.addons.k8s.io/k8s-1.16.yaml.template b/upup/models/cloudup/resources/addons/kops-controller.addons.k8s.io/k8s-1.16.yaml.template index 27a3a2e685..c5ea3352b8 100644 --- a/upup/models/cloudup/resources/addons/kops-controller.addons.k8s.io/k8s-1.16.yaml.template +++ b/upup/models/cloudup/resources/addons/kops-controller.addons.k8s.io/k8s-1.16.yaml.template @@ -141,7 +141,7 @@ rules: - list - watch - patch -{{- if GossipDomains }} +{{- if GossipEnabled }} - apiGroups: - "" resources: @@ -213,7 +213,7 @@ rules: - leases verbs: - create -{{- if GossipDomains }} +{{- if GossipEnabled }} - apiGroups: - "" resources: diff --git a/upup/pkg/fi/cloudup/template_functions.go b/upup/pkg/fi/cloudup/template_functions.go index 6441128ea2..fd1f7eb5d9 100644 --- a/upup/pkg/fi/cloudup/template_functions.go +++ b/upup/pkg/fi/cloudup/template_functions.go @@ -124,14 +124,17 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS return cluster.Spec.KubeDNS } - dest["GossipDomains"] = func() []string { - var names []string - - if dns.IsGossipClusterName(cluster.Name) { - names = append(names, "k8s.local") + dest["GossipEnabled"] = func() bool { + if cluster.IsGossip() { + return true } - - return names + return false + } + dest["GossipName"] = func() bool { + if dns.IsGossipClusterName(cluster.Name) { + return true + } + return false } dest["NodeLocalDNSClusterIP"] = func() string {