mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #92716 from rajansandeep/removefederation
[kubeadm]: Remove kube-dns translation for federation
This commit is contained in:
commit
bf94f27e76
@ -51,7 +51,6 @@ const (
|
|||||||
KubeDNSServiceAccountName = "kube-dns"
|
KubeDNSServiceAccountName = "kube-dns"
|
||||||
kubeDNSStubDomain = "stubDomains"
|
kubeDNSStubDomain = "stubDomains"
|
||||||
kubeDNSUpstreamNameservers = "upstreamNameservers"
|
kubeDNSUpstreamNameservers = "upstreamNameservers"
|
||||||
kubeDNSFederation = "federations"
|
|
||||||
unableToDecodeCoreDNS = "unable to decode CoreDNS"
|
unableToDecodeCoreDNS = "unable to decode CoreDNS"
|
||||||
coreDNSReplicas = 2
|
coreDNSReplicas = 2
|
||||||
kubeDNSReplicas = 1
|
kubeDNSReplicas = 1
|
||||||
@ -226,16 +225,11 @@ func coreDNSAddon(cfg *kubeadmapi.ClusterConfiguration, client clientset.Interfa
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
coreDNSDomain := cfg.Networking.DNSDomain
|
coreDNSDomain := cfg.Networking.DNSDomain
|
||||||
federations, err := translateFederationsofKubeDNSToCoreDNS(kubeDNSFederation, coreDNSDomain, kubeDNSConfigMap)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the config file for CoreDNS
|
// Get the config file for CoreDNS
|
||||||
coreDNSConfigMapBytes, err := kubeadmutil.ParseTemplate(CoreDNSConfigMap, struct{ DNSDomain, UpstreamNameserver, Federation, StubDomain string }{
|
coreDNSConfigMapBytes, err := kubeadmutil.ParseTemplate(CoreDNSConfigMap, struct{ DNSDomain, UpstreamNameserver, StubDomain string }{
|
||||||
DNSDomain: coreDNSDomain,
|
DNSDomain: coreDNSDomain,
|
||||||
UpstreamNameserver: upstreamNameserver,
|
UpstreamNameserver: upstreamNameserver,
|
||||||
Federation: federations,
|
|
||||||
StubDomain: stubDomain,
|
StubDomain: stubDomain,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -580,47 +574,6 @@ func translateUpstreamNameServerOfKubeDNSToUpstreamForwardCoreDNS(dataField stri
|
|||||||
return "/etc/resolv.conf", nil
|
return "/etc/resolv.conf", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// translateFederationsofKubeDNSToCoreDNS translates Federations Data in kube-dns ConfigMap
|
|
||||||
// to Federation for CoreDNS Corefile.
|
|
||||||
func translateFederationsofKubeDNSToCoreDNS(dataField, coreDNSDomain string, kubeDNSConfigMap *v1.ConfigMap) (string, error) {
|
|
||||||
if kubeDNSConfigMap == nil {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if federation, ok := kubeDNSConfigMap.Data[dataField]; ok {
|
|
||||||
var (
|
|
||||||
federationStanza []interface{}
|
|
||||||
body [][]string
|
|
||||||
)
|
|
||||||
federationData := make(map[string]string)
|
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(federation), &federationData)
|
|
||||||
if err != nil {
|
|
||||||
return "", errors.Wrap(err, "failed to parse JSON from kube-dns ConfigMap")
|
|
||||||
}
|
|
||||||
fStanza := map[string]interface{}{}
|
|
||||||
|
|
||||||
for name, domain := range federationData {
|
|
||||||
body = append(body, []string{name, domain})
|
|
||||||
}
|
|
||||||
federationStanza = append(federationStanza, fStanza)
|
|
||||||
fStanza["keys"] = []string{"federation " + coreDNSDomain}
|
|
||||||
fStanza["body"] = body
|
|
||||||
stanzasBytes, err := json.Marshal(federationStanza)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
corefileStanza, err := caddyfile.FromJSON(stanzasBytes)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prepCorefileFormat(string(corefileStanza), 8), nil
|
|
||||||
}
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepCorefileFormat indents the output of the Corefile caddytext and replaces tabs with spaces
|
// prepCorefileFormat indents the output of the Corefile caddytext and replaces tabs with spaces
|
||||||
// to neatly format the configmap, making it readable.
|
// to neatly format the configmap, making it readable.
|
||||||
func prepCorefileFormat(s string, indentation int) string {
|
func prepCorefileFormat(s string, indentation int) string {
|
||||||
|
@ -139,9 +139,8 @@ func TestCompileManifests(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "CoreDNSConfigMap manifest",
|
name: "CoreDNSConfigMap manifest",
|
||||||
manifest: CoreDNSConfigMap,
|
manifest: CoreDNSConfigMap,
|
||||||
data: struct{ DNSDomain, Federation, UpstreamNameserver, StubDomain string }{
|
data: struct{ DNSDomain, UpstreamNameserver, StubDomain string }{
|
||||||
DNSDomain: "foo",
|
DNSDomain: "foo",
|
||||||
Federation: "foo",
|
|
||||||
UpstreamNameserver: "foo",
|
UpstreamNameserver: "foo",
|
||||||
StubDomain: "foo",
|
StubDomain: "foo",
|
||||||
},
|
},
|
||||||
@ -496,80 +495,6 @@ func TestTranslateUpstreamKubeDNSToCoreDNS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTranslateFederationKubeDNSToCoreDNS(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
name string
|
|
||||||
configMap *v1.ConfigMap
|
|
||||||
expectOne string
|
|
||||||
expectTwo string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "valid call",
|
|
||||||
configMap: &v1.ConfigMap{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "kube-dns",
|
|
||||||
Namespace: "kube-system",
|
|
||||||
},
|
|
||||||
Data: map[string]string{
|
|
||||||
"federations": `{"foo" : "foo.feddomain.com", "bar" : "bar.feddomain.com"}`,
|
|
||||||
"stubDomains": `{"foo.com" : ["1.2.3.4:5300","3.3.3.3"], "my.cluster.local" : ["2.3.4.5"]}`,
|
|
||||||
"upstreamNameservers": `["8.8.8.8", "8.8.4.4"]`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
expectOne: `
|
|
||||||
federation cluster.local {
|
|
||||||
foo foo.feddomain.com
|
|
||||||
bar bar.feddomain.com
|
|
||||||
}`,
|
|
||||||
expectTwo: `
|
|
||||||
federation cluster.local {
|
|
||||||
bar bar.feddomain.com
|
|
||||||
foo foo.feddomain.com
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "empty data",
|
|
||||||
configMap: &v1.ConfigMap{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "kubedns",
|
|
||||||
Namespace: "kube-system",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
expectOne: "",
|
|
||||||
expectTwo: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "missing federations data",
|
|
||||||
configMap: &v1.ConfigMap{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "kube-dns",
|
|
||||||
Namespace: "kube-system",
|
|
||||||
},
|
|
||||||
Data: map[string]string{
|
|
||||||
"stubDomains": `{"foo.com" : ["1.2.3.4:5300"], "my.cluster.local" : ["2.3.4.5"]}`,
|
|
||||||
"upstreamNameservers": `["8.8.8.8", "8.8.4.4"]`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
expectOne: "",
|
|
||||||
expectTwo: "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, testCase := range testCases {
|
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
|
||||||
out, err := translateFederationsofKubeDNSToCoreDNS(kubeDNSFederation, "cluster.local", testCase.configMap)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if !strings.EqualFold(out, testCase.expectOne) && !strings.EqualFold(out, testCase.expectTwo) {
|
|
||||||
t.Errorf("expected to find %q or %q in output: %q", testCase.expectOne, testCase.expectTwo, out)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDeploymentsHaveSystemClusterCriticalPriorityClassName(t *testing.T) {
|
func TestDeploymentsHaveSystemClusterCriticalPriorityClassName(t *testing.T) {
|
||||||
replicas := int32(coreDNSReplicas)
|
replicas := int32(coreDNSReplicas)
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -318,7 +318,7 @@ data:
|
|||||||
pods insecure
|
pods insecure
|
||||||
fallthrough in-addr.arpa ip6.arpa
|
fallthrough in-addr.arpa ip6.arpa
|
||||||
ttl 30
|
ttl 30
|
||||||
}{{ .Federation }}
|
}
|
||||||
prometheus :9153
|
prometheus :9153
|
||||||
forward . {{ .UpstreamNameserver }}
|
forward . {{ .UpstreamNameserver }}
|
||||||
cache 30
|
cache 30
|
||||||
|
@ -17,12 +17,15 @@ limitations under the License.
|
|||||||
package upgrade
|
package upgrade
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/coredns/corefile-migration/migration"
|
"github.com/coredns/corefile-migration/migration"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
@ -68,6 +71,11 @@ func RunCoreDNSMigrationCheck(client clientset.Interface, ignorePreflightErrors
|
|||||||
client: client,
|
client: client,
|
||||||
f: checkMigration,
|
f: checkMigration,
|
||||||
},
|
},
|
||||||
|
&CoreDNSCheck{
|
||||||
|
name: "kubeDNSTranslation",
|
||||||
|
client: client,
|
||||||
|
f: checkKubeDNSConfigMap,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return preflight.RunChecks(migrationChecks, os.Stderr, ignorePreflightErrors)
|
return preflight.RunChecks(migrationChecks, os.Stderr, ignorePreflightErrors)
|
||||||
@ -114,3 +122,21 @@ func checkMigration(client clientset.Interface) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkKubeDNSConfigMap checks if the translation of kube-dns to CoreDNS ConfigMap is supported
|
||||||
|
func checkKubeDNSConfigMap(client clientset.Interface) error {
|
||||||
|
kubeDNSConfigMap, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(context.TODO(), kubeadmconstants.KubeDNSConfigMap, metav1.GetOptions{})
|
||||||
|
if err != nil && !apierrors.IsNotFound(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if kubeDNSConfigMap == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := kubeDNSConfigMap.Data["federations"]; ok {
|
||||||
|
klog.V(1).Infoln("CoreDNS no longer supports Federation and " +
|
||||||
|
"hence will not translate the federation data from kube-dns to CoreDNS ConfigMap")
|
||||||
|
return errors.Wrap(err, "kube-dns Federation data will not be translated")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user