Skip to content
Permalink
Browse files

Merge pull request #65787 from luxas/kubeadm_split_componentconfig_fr…

…om_api

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

kubeadm: Use separate YAML docs for the kubelet and kube-proxy ComponentConfigs

**What this PR does / why we need it**:
This PR makes kubeadm load the ComponentConfig for the kubelet and kube-proxy from separate YAML documents in the `kubeadm init` config file. This is backwards-compatible with `v1alpha2`. The ComponentConfigs are stored internally in the internal kubeadm `MasterConfiguration` struct, but when marshalling the componentconfigs are written as separate YAML documents.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
ref: kubernetes/kubeadm#911
Depends on:
 - [x] #65776
 - [x] #65628
 - [x] #65629
 - [x] #65631
 - [x] #65940

**Special notes for your reviewer**:
Only review the last five commits please. (The last commit is purely autogenerated, so can be skipped)

**Release note**:

```release-note
kubeadm: Use separate YAML documents for the kubelet and kube-proxy ComponentConfigs
```
@kubernetes/sig-cluster-lifecycle-pr-reviews 
/assign @timothysc
  • Loading branch information...
Kubernetes Submit Queue
Kubernetes Submit Queue committed Jul 8, 2018
2 parents 5028577 + 0be8955 commit ac99da5e3e0c0df07f12cca153df3baed0b6dd49
Showing with 1,420 additions and 926 deletions.
  1. +1 −0 cmd/kubeadm/app/BUILD
  2. +1 −0 cmd/kubeadm/app/apis/kubeadm/BUILD
  3. +2 −1 cmd/kubeadm/app/apis/kubeadm/fuzzer/BUILD
  4. +16 −61 cmd/kubeadm/app/apis/kubeadm/fuzzer/fuzzer.go
  5. +9 −0 cmd/kubeadm/app/apis/kubeadm/types.go
  6. +1 −0 cmd/kubeadm/app/apis/kubeadm/v1alpha2/BUILD
  7. +5 −16 cmd/kubeadm/app/apis/kubeadm/v1alpha2/conversion.go
  8. +6 −2 cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go
  9. +1 −1 cmd/kubeadm/app/apis/kubeadm/v1alpha2/zz_generated.conversion.go
  10. +0 −1 cmd/kubeadm/app/apis/kubeadm/v1alpha3/BUILD
  11. +60 −43 cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go
  12. +2 −77 cmd/kubeadm/app/apis/kubeadm/v1alpha3/defaults.go
  13. +0 −16 cmd/kubeadm/app/apis/kubeadm/v1alpha3/types.go
  14. +6 −3 cmd/kubeadm/app/apis/kubeadm/v1alpha3/zz_generated.conversion.go
  15. +0 −46 cmd/kubeadm/app/apis/kubeadm/v1alpha3/zz_generated.deepcopy.go
  16. +0 −8 cmd/kubeadm/app/apis/kubeadm/v1alpha3/zz_generated.defaults.go
  17. +1 −5 cmd/kubeadm/app/apis/kubeadm/validation/BUILD
  18. +2 −27 cmd/kubeadm/app/apis/kubeadm/validation/validation.go
  19. +0 −304 cmd/kubeadm/app/apis/kubeadm/validation/validation_test.go
  20. +3 −2 cmd/kubeadm/app/cmd/config.go
  21. +0 −1 cmd/kubeadm/app/cmd/upgrade/BUILD
  22. +1 −7 cmd/kubeadm/app/cmd/upgrade/common.go
  23. +0 −4 cmd/kubeadm/app/cmd/upgrade/common_test.go
  24. +59 −0 cmd/kubeadm/app/componentconfigs/BUILD
  25. +120 −0 cmd/kubeadm/app/componentconfigs/defaults.go
  26. +148 −0 cmd/kubeadm/app/componentconfigs/registrations.go
  27. +41 −0 cmd/kubeadm/app/componentconfigs/scheme.go
  28. +46 −0 cmd/kubeadm/app/componentconfigs/validation.go
  29. +351 −0 cmd/kubeadm/app/componentconfigs/validation_test.go
  30. +2 −3 cmd/kubeadm/app/phases/addons/proxy/BUILD
  31. +2 −3 cmd/kubeadm/app/phases/addons/proxy/proxy.go
  32. +24 −23 cmd/kubeadm/app/phases/addons/proxy/proxy_test.go
  33. +1 −2 cmd/kubeadm/app/phases/kubelet/BUILD
  34. +3 −10 cmd/kubeadm/app/phases/kubelet/config.go
  35. +1 −3 cmd/kubeadm/app/phases/uploadconfig/BUILD
  36. +10 −4 cmd/kubeadm/app/phases/uploadconfig/uploadconfig.go
  37. +10 −23 cmd/kubeadm/app/phases/uploadconfig/uploadconfig_test.go
  38. +2 −1 cmd/kubeadm/app/util/BUILD
  39. +2 −0 cmd/kubeadm/app/util/config/BUILD
  40. +1 −0 cmd/kubeadm/app/util/config/cluster.go
  41. +11 −0 cmd/kubeadm/app/util/config/common.go
  42. +134 −3 cmd/kubeadm/app/util/config/masterconfig.go
  43. +92 −4 cmd/kubeadm/app/util/config/masterconfig_test.go
  44. +112 −110 cmd/kubeadm/app/util/config/testdata/conversion/master/v1alpha3.yaml
  45. +110 −108 cmd/kubeadm/app/util/config/testdata/defaulting/master/defaulted.yaml
  46. +1 −0 cmd/kubeadm/app/util/config/testdata/defaulting/master/incomplete.yaml
  47. +20 −4 cmd/kubeadm/app/util/marshal_test.go
@@ -30,6 +30,7 @@ filegroup(
":package-srcs",
"//cmd/kubeadm/app/apis/kubeadm:all-srcs",
"//cmd/kubeadm/app/cmd:all-srcs",
"//cmd/kubeadm/app/componentconfigs:all-srcs",
"//cmd/kubeadm/app/constants:all-srcs",
"//cmd/kubeadm/app/discovery:all-srcs",
"//cmd/kubeadm/app/features:all-srcs",
@@ -26,6 +26,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/client-go/tools/bootstrap/token/api:go_default_library",
"//staging/src/k8s.io/client-go/tools/bootstrap/token/util:go_default_library",
"//vendor/github.com/google/gofuzz:go_default_library",
],
)

@@ -12,10 +12,11 @@ go_library(
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/fuzzer",
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/componentconfigs:go_default_library",
"//pkg/kubelet/apis/kubeletconfig:go_default_library",
"//pkg/kubelet/apis/kubeletconfig/scheme:go_default_library",
"//pkg/kubelet/apis/kubeletconfig/v1beta1:go_default_library",
"//pkg/proxy/apis/kubeproxyconfig:go_default_library",
"//pkg/proxy/apis/kubeproxyconfig/v1alpha1:go_default_library",
"//pkg/util/pointer:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
@@ -25,10 +25,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
kubeletconfigscheme "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/scheme"
kubeletconfigv1beta1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1"
"k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig"
kubeproxyconfigv1alpha1 "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/v1alpha1"
utilpointer "k8s.io/kubernetes/pkg/util/pointer"
)

@@ -40,11 +41,10 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
obj.KubernetesVersion = "v10"
obj.API.BindPort = 20
obj.API.AdvertiseAddress = "foo"
obj.Networking.ServiceSubnet = "foo"
obj.Networking.DNSDomain = "foo"
obj.Networking.ServiceSubnet = "10.96.0.0/12"
obj.Networking.DNSDomain = "cluster.local"
obj.CertificatesDir = "foo"
obj.APIServerCertSANs = []string{"foo"}

obj.BootstrapTokens = []kubeadm.BootstrapToken{
{
Token: &kubeadm.BootstrapTokenString{
@@ -68,9 +68,6 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
MountPath: "foo",
Writable: false,
}}
// Note: We don't set values here for obj.Etcd.External, as these are mutually exlusive.
// And to make sure the fuzzer doesn't set a random value for obj.Etcd.External, we let
// kubeadmapi.Etcd implement fuzz.Interface (we handle that ourselves)
obj.Etcd.Local = &kubeadm.LocalEtcd{
Image: "foo",
DataDir: "foo",
@@ -83,65 +80,23 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
Name: "foo",
Taints: []v1.Taint{},
}
extkubeletconfig := &kubeletconfigv1beta1.KubeletConfiguration{
StaticPodPath: "foo",
ClusterDNS: []string{"foo"},
ClusterDomain: "foo",
Authorization: kubeletconfigv1beta1.KubeletAuthorization{
Mode: "Webhook",
},
Authentication: kubeletconfigv1beta1.KubeletAuthentication{
X509: kubeletconfigv1beta1.KubeletX509Authentication{
ClientCAFile: "/etc/kubernetes/pki/ca.crt",
},
Anonymous: kubeletconfigv1beta1.KubeletAnonymousAuthentication{
Enabled: utilpointer.BoolPtr(false),
},
},
RotateCertificates: true,
}
obj.ComponentConfigs.Kubelet = &kubeletconfig.KubeletConfiguration{}
kubeletconfigv1beta1.SetDefaults_KubeletConfiguration(extkubeletconfig)
scheme, _, _ := kubeletconfigscheme.NewSchemeAndCodecs()
scheme.Convert(extkubeletconfig, obj.ComponentConfigs.Kubelet, nil)
obj.ComponentConfigs.KubeProxy = &kubeproxyconfig.KubeProxyConfiguration{
FeatureGates: map[string]bool{"foo": true},
BindAddress: "foo",
HealthzBindAddress: "foo:10256",
MetricsBindAddress: "foo:",
EnableProfiling: bool(true),
ClusterCIDR: "foo",
HostnameOverride: "foo",
ClientConnection: kubeproxyconfig.ClientConnectionConfiguration{
KubeConfigFile: "foo",
AcceptContentTypes: "foo",
ContentType: "foo",
QPS: float32(5),
Burst: 10,
},
IPVS: kubeproxyconfig.KubeProxyIPVSConfiguration{
SyncPeriod: metav1.Duration{Duration: 1},
},
IPTables: kubeproxyconfig.KubeProxyIPTablesConfiguration{
MasqueradeBit: utilpointer.Int32Ptr(0),
SyncPeriod: metav1.Duration{Duration: 1},
},
OOMScoreAdj: utilpointer.Int32Ptr(0),
ResourceContainer: "foo",
UDPIdleTimeout: metav1.Duration{Duration: 1},
Conntrack: kubeproxyconfig.KubeProxyConntrackConfiguration{
MaxPerCore: utilpointer.Int32Ptr(2),
Min: utilpointer.Int32Ptr(1),
TCPEstablishedTimeout: &metav1.Duration{Duration: 5},
TCPCloseWaitTimeout: &metav1.Duration{Duration: 5},
},
ConfigSyncPeriod: metav1.Duration{Duration: 1},
}
obj.AuditPolicyConfiguration = kubeadm.AuditPolicyConfiguration{
Path: "foo",
LogDir: "/foo",
LogMaxAge: utilpointer.Int32Ptr(0),
}
// Set the Kubelet ComponentConfig to an empty, defaulted struct
extkubeletconfig := &kubeletconfigv1beta1.KubeletConfiguration{}
obj.ComponentConfigs.Kubelet = &kubeletconfig.KubeletConfiguration{}
componentconfigs.Scheme.Default(extkubeletconfig)
componentconfigs.Scheme.Convert(extkubeletconfig, obj.ComponentConfigs.Kubelet, nil)
componentconfigs.DefaultKubeletConfiguration(obj)
// Set the KubeProxy ComponentConfig to an empty, defaulted struct
extkubeproxyconfig := &kubeproxyconfigv1alpha1.KubeProxyConfiguration{}
obj.ComponentConfigs.KubeProxy = &kubeproxyconfig.KubeProxyConfiguration{}
componentconfigs.Scheme.Default(extkubeproxyconfig)
componentconfigs.Scheme.Convert(extkubeproxyconfig, obj.ComponentConfigs.KubeProxy, nil)
componentconfigs.DefaultKubeProxyConfiguration(obj)
},
func(obj *kubeadm.NodeConfiguration, c fuzz.Continue) {
c.FuzzNoCustom(obj)
@@ -17,6 +17,8 @@ limitations under the License.
package kubeadm

import (
fuzz "github.com/google/gofuzz"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
@@ -42,6 +44,7 @@ type MasterConfiguration struct {
NodeRegistration NodeRegistrationOptions

// ComponentConfigs holds internal ComponentConfig struct types known to kubeadm, should long-term only exist in the internal kubeadm API
// +k8s:conversion-gen=false
ComponentConfigs ComponentConfigs

// Cluster-wide configuration
@@ -117,6 +120,12 @@ type ComponentConfigs struct {
KubeProxy *kubeproxyconfig.KubeProxyConfiguration
}

// Fuzz is a dummy function here to get the roundtrip tests working in cmd/kubeadm/app/apis/kubeadm/fuzzer working.
// This makes the fuzzer not go and randomize all fields in the ComponentConfigs struct, as that wouldn't work for
// a roundtrip. A roundtrip to the v1alpha3 API obviously doesn't work as it's not stored there at all. With this,
// the roundtrip is considered valid, as semi-static values are set and preserved during a roundtrip.
func (cc ComponentConfigs) Fuzz(c fuzz.Continue) {}

// API struct contains elements of API server address.
type API struct {
// AdvertiseAddress sets the IP address for the API server to advertise.
@@ -19,6 +19,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/componentconfigs:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//pkg/kubelet/apis/kubeletconfig:go_default_library",
"//pkg/kubelet/apis/kubeletconfig/scheme:go_default_library",
@@ -19,11 +19,10 @@ package v1alpha2
import (
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
kubeletconfigscheme "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/scheme"
kubeletconfigv1beta1 "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/v1beta1"
"k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig"
kubeproxyconfigscheme "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/scheme"
kubeproxyconfigv1alpha1 "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/v1alpha1"
)

@@ -37,7 +36,7 @@ func Convert_v1alpha2_MasterConfiguration_To_kubeadm_MasterConfiguration(in *Mas
out.ComponentConfigs.KubeProxy = &kubeproxyconfig.KubeProxyConfiguration{}
}

if err := kubeproxyconfigscheme.Scheme.Convert(in.KubeProxy.Config, out.ComponentConfigs.KubeProxy, nil); err != nil {
if err := componentconfigs.Scheme.Convert(in.KubeProxy.Config, out.ComponentConfigs.KubeProxy, nil); err != nil {
return err
}
}
@@ -46,12 +45,7 @@ func Convert_v1alpha2_MasterConfiguration_To_kubeadm_MasterConfiguration(in *Mas
out.ComponentConfigs.Kubelet = &kubeletconfig.KubeletConfiguration{}
}

scheme, _, err := kubeletconfigscheme.NewSchemeAndCodecs()
if err != nil {
return err
}

if err := scheme.Convert(in.KubeletConfiguration.BaseConfig, out.ComponentConfigs.Kubelet, nil); err != nil {
if err := componentconfigs.Scheme.Convert(in.KubeletConfiguration.BaseConfig, out.ComponentConfigs.Kubelet, nil); err != nil {
return err
}
}
@@ -69,7 +63,7 @@ func Convert_kubeadm_MasterConfiguration_To_v1alpha2_MasterConfiguration(in *kub
out.KubeProxy.Config = &kubeproxyconfigv1alpha1.KubeProxyConfiguration{}
}

if err := kubeproxyconfigscheme.Scheme.Convert(in.ComponentConfigs.KubeProxy, out.KubeProxy.Config, nil); err != nil {
if err := componentconfigs.Scheme.Convert(in.ComponentConfigs.KubeProxy, out.KubeProxy.Config, nil); err != nil {
return err
}
}
@@ -78,12 +72,7 @@ func Convert_kubeadm_MasterConfiguration_To_v1alpha2_MasterConfiguration(in *kub
out.KubeletConfiguration.BaseConfig = &kubeletconfigv1beta1.KubeletConfiguration{}
}

scheme, _, err := kubeletconfigscheme.NewSchemeAndCodecs()
if err != nil {
return err
}

if err := scheme.Convert(in.ComponentConfigs.Kubelet, out.KubeletConfiguration.BaseConfig, nil); err != nil {
if err := componentconfigs.Scheme.Convert(in.ComponentConfigs.Kubelet, out.KubeletConfiguration.BaseConfig, nil); err != nil {
return err
}
}
@@ -127,6 +127,8 @@ func SetDefaults_Etcd(obj *MasterConfiguration) {

// SetDefaults_ProxyConfiguration assigns default values for the Proxy
func SetDefaults_ProxyConfiguration(obj *MasterConfiguration) {
// IMPORTANT NOTE: If you're changing this code you should mirror it to cmd/kubeadm/app/componentconfig/defaults.go
// and cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go.
if obj.KubeProxy.Config == nil {
obj.KubeProxy.Config = &kubeproxyconfigv1alpha1.KubeProxyConfiguration{}
}
@@ -173,6 +175,8 @@ func SetDefaults_NodeConfiguration(obj *NodeConfiguration) {

// SetDefaults_KubeletConfiguration assigns default values to kubelet
func SetDefaults_KubeletConfiguration(obj *MasterConfiguration) {
// IMPORTANT NOTE: If you're changing this code you should mirror it to cmd/kubeadm/app/componentconfig/defaults.go
// and cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go.
if obj.KubeletConfiguration.BaseConfig == nil {
obj.KubeletConfiguration.BaseConfig = &kubeletconfigv1beta1.KubeletConfiguration{}
}
@@ -247,8 +251,8 @@ func SetDefaults_BootstrapTokens(obj *MasterConfiguration) {
obj.BootstrapTokens = []BootstrapToken{{}}
}

for _, bt := range obj.BootstrapTokens {
SetDefaults_BootstrapToken(&bt)
for i := range obj.BootstrapTokens {
SetDefaults_BootstrapToken(&obj.BootstrapTokens[i])
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -26,7 +26,6 @@ go_library(
"//pkg/proxy/apis/kubeproxyconfig:go_default_library",
"//pkg/proxy/apis/kubeproxyconfig/scheme:go_default_library",
"//pkg/proxy/apis/kubeproxyconfig/v1alpha1:go_default_library",
"//pkg/util/pointer:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
Oops, something went wrong.

0 comments on commit ac99da5

Please sign in to comment.
You can’t perform that action at this time.