kubeadm config add support for more than one APIEndpoint

This commit is contained in:
fabriziopandini 2018-08-27 09:00:26 +02:00
parent b2b3c36ecb
commit 7dfb3c7134
48 changed files with 506 additions and 414 deletions

View File

@ -45,7 +45,28 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
func(obj *kubeadm.InitConfiguration, c fuzz.Continue) { func(obj *kubeadm.InitConfiguration, c fuzz.Continue) {
c.FuzzNoCustom(obj) c.FuzzNoCustom(obj)
fuzzClusterConfig(&obj.ClusterConfiguration) fuzzClusterConfig(&obj.ClusterConfiguration)
obj.BootstrapTokens = []kubeadm.BootstrapToken{ fuzzBootstrapTokens(&obj.BootstrapTokens)
fuzzNodeRegistration(&obj.NodeRegistration)
fuzzAPIEndpoint(&obj.APIEndpoint)
},
func(obj *kubeadm.JoinConfiguration, c fuzz.Continue) {
c.FuzzNoCustom(obj)
fuzzNodeRegistration(&obj.NodeRegistration)
fuzzAPIEndpoint(&obj.APIEndpoint)
obj.CACertPath = "foo"
obj.DiscoveryFile = "foo"
obj.DiscoveryToken = "foo"
obj.DiscoveryTokenAPIServers = []string{"foo"}
obj.DiscoveryTimeout = &metav1.Duration{Duration: 1}
obj.TLSBootstrapToken = "foo"
obj.Token = "foo"
obj.ClusterName = "foo"
},
}
}
func fuzzBootstrapTokens(obj *[]kubeadm.BootstrapToken) {
obj = &[]kubeadm.BootstrapToken{
{ {
Token: &kubeadm.BootstrapTokenString{ Token: &kubeadm.BootstrapTokenString{
ID: "abcdef", ID: "abcdef",
@ -56,34 +77,21 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
Groups: []string{"foo"}, Groups: []string{"foo"},
}, },
} }
obj.NodeRegistration = kubeadm.NodeRegistrationOptions{
CRISocket: "foo",
Name: "foo",
Taints: []v1.Taint{},
} }
},
func(obj *kubeadm.JoinConfiguration, c fuzz.Continue) { func fuzzNodeRegistration(obj *kubeadm.NodeRegistrationOptions) {
c.FuzzNoCustom(obj) obj.CRISocket = "foo"
obj.CACertPath = "foo" obj.Name = "foo"
obj.DiscoveryFile = "foo" obj.Taints = []v1.Taint{}
obj.DiscoveryToken = "foo"
obj.DiscoveryTokenAPIServers = []string{"foo"}
obj.DiscoveryTimeout = &metav1.Duration{Duration: 1}
obj.TLSBootstrapToken = "foo"
obj.Token = "foo"
obj.ClusterName = "foo"
obj.NodeRegistration = kubeadm.NodeRegistrationOptions{
CRISocket: "foo",
Name: "foo",
}
},
} }
func fuzzAPIEndpoint(obj *kubeadm.APIEndpoint) {
obj.BindPort = 20
obj.AdvertiseAddress = "foo"
} }
func fuzzClusterConfig(obj *kubeadm.ClusterConfiguration) { func fuzzClusterConfig(obj *kubeadm.ClusterConfiguration) {
obj.KubernetesVersion = "v10" obj.KubernetesVersion = "v10"
obj.API.BindPort = 20
obj.API.AdvertiseAddress = "foo"
obj.Networking.ServiceSubnet = "10.96.0.0/12" obj.Networking.ServiceSubnet = "10.96.0.0/12"
obj.Networking.DNSDomain = "cluster.local" obj.Networking.DNSDomain = "cluster.local"
obj.CertificatesDir = "foo" obj.CertificatesDir = "foo"

View File

@ -48,6 +48,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion, scheme.AddKnownTypes(SchemeGroupVersion,
&InitConfiguration{}, &InitConfiguration{},
&ClusterConfiguration{}, &ClusterConfiguration{},
&ClusterStatus{},
&JoinConfiguration{}, &JoinConfiguration{},
) )
return nil return nil

View File

@ -47,6 +47,9 @@ type InitConfiguration struct {
// NodeRegistration holds fields that relate to registering the new master node to the cluster // NodeRegistration holds fields that relate to registering the new master node to the cluster
NodeRegistration NodeRegistrationOptions NodeRegistration NodeRegistrationOptions
// APIEndpoint represents the endpoint of the instance of the API server to be deployed on this node.
APIEndpoint APIEndpoint
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@ -59,8 +62,6 @@ type ClusterConfiguration struct {
// +k8s:conversion-gen=false // +k8s:conversion-gen=false
ComponentConfigs ComponentConfigs ComponentConfigs ComponentConfigs
// API holds configuration for the k8s apiserver.
API API
// Etcd holds configuration for etcd. // Etcd holds configuration for etcd.
Etcd Etcd Etcd Etcd
@ -148,8 +149,20 @@ type ComponentConfigs struct {
// the roundtrip is considered valid, as semi-static values are set and preserved during a roundtrip. // the roundtrip is considered valid, as semi-static values are set and preserved during a roundtrip.
func (cc ComponentConfigs) Fuzz(c fuzz.Continue) {} func (cc ComponentConfigs) Fuzz(c fuzz.Continue) {}
// API struct contains elements of API server address. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type API struct {
// ClusterStatus contains the cluster status. The ClusterStatus will be stored in the kubeadm-config
// ConfigMap in the cluster, and then updated by kubeadm when additional control plane instance joins or leaves the cluster.
type ClusterStatus struct {
metav1.TypeMeta
// APIEndpoints currently available in the cluster, one for each control plane/api server instance.
// The key of the map is the IP of the host's default interface
APIEndpoints map[string]APIEndpoint
}
// APIEndpoint struct contains elements of API server instance deployed on a node.
type APIEndpoint struct {
// AdvertiseAddress sets the IP address for the API server to advertise. // AdvertiseAddress sets the IP address for the API server to advertise.
AdvertiseAddress string AdvertiseAddress string
@ -314,9 +327,8 @@ type JoinConfiguration struct {
// control plane instance. // control plane instance.
ControlPlane bool ControlPlane bool
// AdvertiseAddress sets the IP address for the API server to advertise; the // APIEndpoint represents the endpoint of the instance of the API server eventually to be deployed on this node.
// API server will be installed only on nodes hosting an additional control plane instance. APIEndpoint APIEndpoint
AdvertiseAddress string
// FeatureGates enabled by the user. // FeatureGates enabled by the user.
FeatureGates map[string]bool FeatureGates map[string]bool

View File

@ -35,6 +35,16 @@ func Convert_v1alpha2_InitConfiguration_To_kubeadm_InitConfiguration(in *InitCon
if err := split_v1alpha2_InitConfiguration_into_kubeadm_ClusterConfiguration(in, &out.ClusterConfiguration, s); err != nil { if err := split_v1alpha2_InitConfiguration_into_kubeadm_ClusterConfiguration(in, &out.ClusterConfiguration, s); err != nil {
return err return err
} }
if err := split_v1alpha2_InitConfiguration_into_kubeadm_APIEndpoint(in, &out.APIEndpoint, s); err != nil {
return err
}
return nil
}
func split_v1alpha2_InitConfiguration_into_kubeadm_APIEndpoint(in *InitConfiguration, out *kubeadm.APIEndpoint, s conversion.Scope) error {
out.AdvertiseAddress = in.API.AdvertiseAddress
out.BindPort = in.API.BindPort
// in.API.ControlPlaneEndpoint will be splitted into ClusterConfiguration
return nil return nil
} }
@ -42,9 +52,6 @@ func split_v1alpha2_InitConfiguration_into_kubeadm_ClusterConfiguration(in *Init
if err := split_v1alpha2_InitConfiguration_into_kubeadm_ComponentConfigs(in, &out.ComponentConfigs, s); err != nil { if err := split_v1alpha2_InitConfiguration_into_kubeadm_ComponentConfigs(in, &out.ComponentConfigs, s); err != nil {
return err return err
} }
if err := Convert_v1alpha2_API_To_kubeadm_API(&in.API, &out.API, s); err != nil {
return err
}
if err := Convert_v1alpha2_Networking_To_kubeadm_Networking(&in.Networking, &out.Networking, s); err != nil { if err := Convert_v1alpha2_Networking_To_kubeadm_Networking(&in.Networking, &out.Networking, s); err != nil {
return err return err
} }
@ -71,14 +78,6 @@ func split_v1alpha2_InitConfiguration_into_kubeadm_ClusterConfiguration(in *Init
return nil return nil
} }
func Convert_v1alpha2_API_To_kubeadm_API(in *API, out *kubeadm.API, s conversion.Scope) error {
if err := autoConvert_v1alpha2_API_To_kubeadm_API(in, out, s); err != nil {
return err
}
// in.ControlPlaneEndpoint is assigned outside this function
return nil
}
func split_v1alpha2_InitConfiguration_into_kubeadm_ComponentConfigs(in *InitConfiguration, out *kubeadm.ComponentConfigs, s conversion.Scope) error { func split_v1alpha2_InitConfiguration_into_kubeadm_ComponentConfigs(in *InitConfiguration, out *kubeadm.ComponentConfigs, s conversion.Scope) error {
if in.KubeProxy.Config != nil { if in.KubeProxy.Config != nil {
if out.KubeProxy == nil { if out.KubeProxy == nil {
@ -101,6 +100,15 @@ func split_v1alpha2_InitConfiguration_into_kubeadm_ComponentConfigs(in *InitConf
return nil return nil
} }
func Convert_v1alpha2_JoinConfiguration_To_kubeadm_JoinConfiguration(in *JoinConfiguration, out *kubeadm.JoinConfiguration, s conversion.Scope) error {
if err := autoConvert_v1alpha2_JoinConfiguration_To_kubeadm_JoinConfiguration(in, out, s); err != nil {
return err
}
out.APIEndpoint.AdvertiseAddress = in.AdvertiseAddress
out.APIEndpoint.BindPort = in.BindPort
return nil
}
func Convert_kubeadm_InitConfiguration_To_v1alpha2_InitConfiguration(in *kubeadm.InitConfiguration, out *InitConfiguration, s conversion.Scope) error { func Convert_kubeadm_InitConfiguration_To_v1alpha2_InitConfiguration(in *kubeadm.InitConfiguration, out *InitConfiguration, s conversion.Scope) error {
if err := autoConvert_kubeadm_InitConfiguration_To_v1alpha2_InitConfiguration(in, out, s); err != nil { if err := autoConvert_kubeadm_InitConfiguration_To_v1alpha2_InitConfiguration(in, out, s); err != nil {
return err return err
@ -108,6 +116,9 @@ func Convert_kubeadm_InitConfiguration_To_v1alpha2_InitConfiguration(in *kubeadm
if err := join_kubeadm_ClusterConfiguration_into_v1alpha2_InitConfiguration(&in.ClusterConfiguration, out, s); err != nil { if err := join_kubeadm_ClusterConfiguration_into_v1alpha2_InitConfiguration(&in.ClusterConfiguration, out, s); err != nil {
return err return err
} }
if err := join_kubeadm_APIEndpoint_into_v1alpha2_InitConfiguration(&in.APIEndpoint, out, s); err != nil {
return err
}
return nil return nil
} }
@ -115,9 +126,6 @@ func join_kubeadm_ClusterConfiguration_into_v1alpha2_InitConfiguration(in *kubea
if err := join_kubeadm_ComponentConfigs_into_v1alpha2_InitConfiguration(&in.ComponentConfigs, out, s); err != nil { if err := join_kubeadm_ComponentConfigs_into_v1alpha2_InitConfiguration(&in.ComponentConfigs, out, s); err != nil {
return err return err
} }
if err := Convert_kubeadm_API_To_v1alpha2_API(&in.API, &out.API, s); err != nil {
return err
}
if err := Convert_kubeadm_Etcd_To_v1alpha2_Etcd(&in.Etcd, &out.Etcd, s); err != nil { if err := Convert_kubeadm_Etcd_To_v1alpha2_Etcd(&in.Etcd, &out.Etcd, s); err != nil {
return err return err
} }
@ -144,11 +152,10 @@ func join_kubeadm_ClusterConfiguration_into_v1alpha2_InitConfiguration(in *kubea
return nil return nil
} }
func Convert_kubeadm_API_To_v1alpha2_API(in *kubeadm.API, out *API, s conversion.Scope) error { func join_kubeadm_APIEndpoint_into_v1alpha2_InitConfiguration(in *kubeadm.APIEndpoint, out *InitConfiguration, s conversion.Scope) error {
if err := autoConvert_kubeadm_API_To_v1alpha2_API(in, out, s); err != nil { out.API.AdvertiseAddress = in.AdvertiseAddress
return err out.API.BindPort = in.BindPort
} // out.API.ControlPlaneEndpoint will join from ClusterConfiguration
// out.ControlPlaneEndpoint is assigned outside this function
return nil return nil
} }
@ -173,3 +180,12 @@ func join_kubeadm_ComponentConfigs_into_v1alpha2_InitConfiguration(in *kubeadm.C
} }
return nil return nil
} }
func Convert_kubeadm_JoinConfiguration_To_v1alpha2_JoinConfiguration(in *kubeadm.JoinConfiguration, out *JoinConfiguration, s conversion.Scope) error {
if err := autoConvert_kubeadm_JoinConfiguration_To_v1alpha2_JoinConfiguration(in, out, s); err != nil {
return err
}
out.AdvertiseAddress = in.APIEndpoint.AdvertiseAddress
out.BindPort = in.APIEndpoint.BindPort
return nil
}

View File

@ -170,6 +170,10 @@ func SetDefaults_JoinConfiguration(obj *JoinConfiguration) {
obj.ClusterName = DefaultClusterName obj.ClusterName = DefaultClusterName
} }
if obj.BindPort == 0 {
obj.BindPort = DefaultAPIBindPort
}
SetDefaults_NodeRegistrationOptions(&obj.NodeRegistration) SetDefaults_NodeRegistrationOptions(&obj.NodeRegistration)
} }

View File

@ -285,6 +285,10 @@ type JoinConfiguration struct {
// API server will be installed only on nodes hosting an additional control plane instance. // API server will be installed only on nodes hosting an additional control plane instance.
AdvertiseAddress string `json:"advertiseAddress,omitempty"` AdvertiseAddress string `json:"advertiseAddress,omitempty"`
// BindPort sets the secure port for the API Server to bind to.
// Defaults to 6443.
BindPort int32 `json:"bindPort,omitempty"`
// FeatureGates enabled by the user. // FeatureGates enabled by the user.
FeatureGates map[string]bool `json:"featureGates,omitempty"` FeatureGates map[string]bool `json:"featureGates,omitempty"`
} }

View File

@ -72,6 +72,7 @@ func SetDefaults_InitConfiguration(obj *InitConfiguration) {
SetDefaults_ClusterConfiguration(&obj.ClusterConfiguration) SetDefaults_ClusterConfiguration(&obj.ClusterConfiguration)
SetDefaults_NodeRegistrationOptions(&obj.NodeRegistration) SetDefaults_NodeRegistrationOptions(&obj.NodeRegistration)
SetDefaults_BootstrapTokens(obj) SetDefaults_BootstrapTokens(obj)
SetDefaults_APIEndpoint(&obj.APIEndpoint)
} }
// SetDefaults_ClusterConfiguration assigns default values for the ClusterConfiguration // SetDefaults_ClusterConfiguration assigns default values for the ClusterConfiguration
@ -80,10 +81,6 @@ func SetDefaults_ClusterConfiguration(obj *ClusterConfiguration) {
obj.KubernetesVersion = DefaultKubernetesVersion obj.KubernetesVersion = DefaultKubernetesVersion
} }
if obj.API.BindPort == 0 {
obj.API.BindPort = DefaultAPIBindPort
}
if obj.Networking.ServiceSubnet == "" { if obj.Networking.ServiceSubnet == "" {
obj.Networking.ServiceSubnet = DefaultServicesSubnet obj.Networking.ServiceSubnet = DefaultServicesSubnet
} }
@ -148,6 +145,7 @@ func SetDefaults_JoinConfiguration(obj *JoinConfiguration) {
} }
SetDefaults_NodeRegistrationOptions(&obj.NodeRegistration) SetDefaults_NodeRegistrationOptions(&obj.NodeRegistration)
SetDefaults_APIEndpoint(&obj.APIEndpoint)
} }
func SetDefaults_NodeRegistrationOptions(obj *NodeRegistrationOptions) { func SetDefaults_NodeRegistrationOptions(obj *NodeRegistrationOptions) {
@ -197,3 +195,10 @@ func SetDefaults_BootstrapToken(bt *BootstrapToken) {
bt.Groups = constants.DefaultTokenGroups bt.Groups = constants.DefaultTokenGroups
} }
} }
// SetDefaults_APIEndpoint sets the defaults for the API server instance deployed on a node.
func SetDefaults_APIEndpoint(obj *APIEndpoint) {
if obj.BindPort == 0 {
obj.BindPort = DefaultAPIBindPort
}
}

View File

@ -60,6 +60,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion, scheme.AddKnownTypes(SchemeGroupVersion,
&InitConfiguration{}, &InitConfiguration{},
&ClusterConfiguration{}, &ClusterConfiguration{},
&ClusterStatus{},
&JoinConfiguration{}, &JoinConfiguration{},
) )
metav1.AddToGroupVersion(scheme, SchemeGroupVersion) metav1.AddToGroupVersion(scheme, SchemeGroupVersion)

View File

@ -44,6 +44,9 @@ type InitConfiguration struct {
// NodeRegistration holds fields that relate to registering the new master node to the cluster // NodeRegistration holds fields that relate to registering the new master node to the cluster
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"` NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"`
// APIEndpoint represents the endpoint of the instance of the API server to be deployed on this node.
APIEndpoint APIEndpoint `json:"apiEndpoint,omitempty"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@ -52,8 +55,6 @@ type InitConfiguration struct {
type ClusterConfiguration struct { type ClusterConfiguration struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
// API holds configuration for the k8s apiserver.
API API `json:"api"`
// Etcd holds configuration for etcd. // Etcd holds configuration for etcd.
Etcd Etcd `json:"etcd"` Etcd Etcd `json:"etcd"`
@ -121,8 +122,20 @@ type ClusterConfiguration struct {
ClusterName string `json:"clusterName,omitempty"` ClusterName string `json:"clusterName,omitempty"`
} }
// API struct contains elements of API server address. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type API struct {
// ClusterStatus contains the cluster status. The ClusterStatus will be stored in the kubeadm-config
// ConfigMap in the cluster, and then updated by kubeadm when additional control plane instance joins or leaves the cluster.
type ClusterStatus struct {
metav1.TypeMeta `json:",inline"`
// APIEndpoints currently available in the cluster, one for each control plane/api server instance.
// The key of the map is the IP of the host's default interface
APIEndpoints map[string]APIEndpoint `json:"apiEndpoints"`
}
// APIEndpoint struct contains elements of API server instance deployed on a node.
type APIEndpoint struct {
// AdvertiseAddress sets the IP address for the API server to advertise. // AdvertiseAddress sets the IP address for the API server to advertise.
AdvertiseAddress string `json:"advertiseAddress"` AdvertiseAddress string `json:"advertiseAddress"`
@ -287,9 +300,8 @@ type JoinConfiguration struct {
// control plane instance. // control plane instance.
ControlPlane bool `json:"controlPlane,omitempty"` ControlPlane bool `json:"controlPlane,omitempty"`
// AdvertiseAddress sets the IP address for the API server to advertise; the // APIEndpoint represents the endpoint of the instance of the API server eventually to be deployed on this node.
// API server will be installed only on nodes hosting an additional control plane instance. APIEndpoint APIEndpoint `json:"apiEndpoint,omitempty"`
AdvertiseAddress string `json:"advertiseAddress,omitempty"`
// FeatureGates enabled by the user. // FeatureGates enabled by the user.
FeatureGates map[string]bool `json:"featureGates,omitempty"` FeatureGates map[string]bool `json:"featureGates,omitempty"`

View File

@ -48,6 +48,7 @@ func ValidateInitConfiguration(c *kubeadm.InitConfiguration) field.ErrorList {
allErrs = append(allErrs, ValidateNodeRegistrationOptions(&c.NodeRegistration, field.NewPath("nodeRegistration"))...) allErrs = append(allErrs, ValidateNodeRegistrationOptions(&c.NodeRegistration, field.NewPath("nodeRegistration"))...)
allErrs = append(allErrs, ValidateBootstrapTokens(c.BootstrapTokens, field.NewPath("bootstrapTokens"))...) allErrs = append(allErrs, ValidateBootstrapTokens(c.BootstrapTokens, field.NewPath("bootstrapTokens"))...)
allErrs = append(allErrs, ValidateClusterConfiguration(&c.ClusterConfiguration)...) allErrs = append(allErrs, ValidateClusterConfiguration(&c.ClusterConfiguration)...)
allErrs = append(allErrs, ValidateAPIEndpoint(&c.APIEndpoint, field.NewPath("apiEndpoint"))...)
return allErrs return allErrs
} }
@ -58,7 +59,6 @@ func ValidateClusterConfiguration(c *kubeadm.ClusterConfiguration) field.ErrorLi
allErrs = append(allErrs, ValidateCertSANs(c.APIServerCertSANs, field.NewPath("apiServerCertSANs"))...) allErrs = append(allErrs, ValidateCertSANs(c.APIServerCertSANs, field.NewPath("apiServerCertSANs"))...)
allErrs = append(allErrs, ValidateAbsolutePath(c.CertificatesDir, field.NewPath("certificatesDir"))...) allErrs = append(allErrs, ValidateAbsolutePath(c.CertificatesDir, field.NewPath("certificatesDir"))...)
allErrs = append(allErrs, ValidateFeatureGates(c.FeatureGates, field.NewPath("featureGates"))...) allErrs = append(allErrs, ValidateFeatureGates(c.FeatureGates, field.NewPath("featureGates"))...)
allErrs = append(allErrs, ValidateAPI(&c.API, field.NewPath("api"))...)
allErrs = append(allErrs, ValidateHostPort(c.ControlPlaneEndpoint, field.NewPath("controlPlaneEndpoint"))...) allErrs = append(allErrs, ValidateHostPort(c.ControlPlaneEndpoint, field.NewPath("controlPlaneEndpoint"))...)
allErrs = append(allErrs, ValidateEtcd(&c.Etcd, field.NewPath("etcd"))...) allErrs = append(allErrs, ValidateEtcd(&c.Etcd, field.NewPath("etcd"))...)
allErrs = append(allErrs, componentconfigs.Known.Validate(c)...) allErrs = append(allErrs, componentconfigs.Known.Validate(c)...)
@ -70,7 +70,7 @@ func ValidateJoinConfiguration(c *kubeadm.JoinConfiguration) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
allErrs = append(allErrs, ValidateDiscovery(c)...) allErrs = append(allErrs, ValidateDiscovery(c)...)
allErrs = append(allErrs, ValidateNodeRegistrationOptions(&c.NodeRegistration, field.NewPath("nodeRegistration"))...) allErrs = append(allErrs, ValidateNodeRegistrationOptions(&c.NodeRegistration, field.NewPath("nodeRegistration"))...)
allErrs = append(allErrs, ValidateIPFromString(c.AdvertiseAddress, field.NewPath("advertiseAddress"))...) allErrs = append(allErrs, ValidateAPIEndpoint(&c.APIEndpoint, field.NewPath("apiEndpoint"))...)
if !filepath.IsAbs(c.CACertPath) || !strings.HasSuffix(c.CACertPath, ".crt") { if !filepath.IsAbs(c.CACertPath) || !strings.HasSuffix(c.CACertPath, ".crt") {
allErrs = append(allErrs, field.Invalid(field.NewPath("caCertPath"), c.CACertPath, "the ca certificate path must be an absolute path")) allErrs = append(allErrs, field.Invalid(field.NewPath("caCertPath"), c.CACertPath, "the ca certificate path must be an absolute path"))
@ -405,8 +405,8 @@ func ValidateFeatureGates(featureGates map[string]bool, fldPath *field.Path) fie
return allErrs return allErrs
} }
// ValidateAPI validates API configuration // ValidateAPIEndpoint validates API server's endpoint
func ValidateAPI(c *kubeadm.API, fldPath *field.Path) field.ErrorList { func ValidateAPIEndpoint(c *kubeadm.APIEndpoint, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
allErrs = append(allErrs, ValidateIPFromString(c.AdvertiseAddress, fldPath.Child("advertiseAddress"))...) allErrs = append(allErrs, ValidateIPFromString(c.AdvertiseAddress, fldPath.Child("advertiseAddress"))...)
allErrs = append(allErrs, ValidatePort(c.BindPort, fldPath.Child("bindPort"))...) allErrs = append(allErrs, ValidatePort(c.BindPort, fldPath.Child("bindPort"))...)

View File

@ -288,15 +288,15 @@ func TestValidateHostPort(t *testing.T) {
} }
} }
func TestValidateAPI(t *testing.T) { func TestValidateAPIEndpoint(t *testing.T) {
var tests = []struct { var tests = []struct {
name string name string
s *kubeadm.API s *kubeadm.APIEndpoint
expected bool expected bool
}{ }{
{ {
name: "Valid IPv4 address / port", name: "Valid IPv4 address / port",
s: &kubeadm.API{ s: &kubeadm.APIEndpoint{
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
BindPort: 6443, BindPort: 6443,
}, },
@ -304,7 +304,7 @@ func TestValidateAPI(t *testing.T) {
}, },
{ {
name: "Valid IPv6 address / port", name: "Valid IPv6 address / port",
s: &kubeadm.API{ s: &kubeadm.APIEndpoint{
AdvertiseAddress: "2001:db7::2", AdvertiseAddress: "2001:db7::2",
BindPort: 6443, BindPort: 6443,
}, },
@ -312,7 +312,7 @@ func TestValidateAPI(t *testing.T) {
}, },
{ {
name: "Invalid IPv4 address", name: "Invalid IPv4 address",
s: &kubeadm.API{ s: &kubeadm.APIEndpoint{
AdvertiseAddress: "1.2.34", AdvertiseAddress: "1.2.34",
BindPort: 6443, BindPort: 6443,
}, },
@ -320,7 +320,7 @@ func TestValidateAPI(t *testing.T) {
}, },
{ {
name: "Invalid IPv6 address", name: "Invalid IPv6 address",
s: &kubeadm.API{ s: &kubeadm.APIEndpoint{
AdvertiseAddress: "2001:db7:1", AdvertiseAddress: "2001:db7:1",
BindPort: 6443, BindPort: 6443,
}, },
@ -328,7 +328,7 @@ func TestValidateAPI(t *testing.T) {
}, },
{ {
name: "Invalid BindPort", name: "Invalid BindPort",
s: &kubeadm.API{ s: &kubeadm.APIEndpoint{
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
BindPort: 0, BindPort: 0,
}, },
@ -336,7 +336,7 @@ func TestValidateAPI(t *testing.T) {
}, },
} }
for _, rt := range tests { for _, rt := range tests {
actual := ValidateAPI(rt.s, nil) actual := ValidateAPIEndpoint(rt.s, nil)
if (len(actual) == 0) != rt.expected { if (len(actual) == 0) != rt.expected {
t.Errorf( t.Errorf(
"%s test case failed:\n\texpected: %t\n\t actual: %t", "%s test case failed:\n\texpected: %t\n\t actual: %t",
@ -360,11 +360,11 @@ func TestValidateInitConfiguration(t *testing.T) {
&kubeadm.InitConfiguration{}, false}, &kubeadm.InitConfiguration{}, false},
{"invalid missing token with IPv4 service subnet", {"invalid missing token with IPv4 service subnet",
&kubeadm.InitConfiguration{ &kubeadm.InitConfiguration{
ClusterConfiguration: kubeadm.ClusterConfiguration{ APIEndpoint: kubeadm.APIEndpoint{
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadm.ClusterConfiguration{
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "10.96.0.1/12", ServiceSubnet: "10.96.0.1/12",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -375,11 +375,11 @@ func TestValidateInitConfiguration(t *testing.T) {
}, false}, }, false},
{"invalid missing token with IPv6 service subnet", {"invalid missing token with IPv6 service subnet",
&kubeadm.InitConfiguration{ &kubeadm.InitConfiguration{
ClusterConfiguration: kubeadm.ClusterConfiguration{ APIEndpoint: kubeadm.APIEndpoint{
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadm.ClusterConfiguration{
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "2001:db8::1/98", ServiceSubnet: "2001:db8::1/98",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -390,11 +390,11 @@ func TestValidateInitConfiguration(t *testing.T) {
}, false}, }, false},
{"invalid missing node name", {"invalid missing node name",
&kubeadm.InitConfiguration{ &kubeadm.InitConfiguration{
ClusterConfiguration: kubeadm.ClusterConfiguration{ APIEndpoint: kubeadm.APIEndpoint{
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadm.ClusterConfiguration{
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "10.96.0.1/12", ServiceSubnet: "10.96.0.1/12",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -404,11 +404,11 @@ func TestValidateInitConfiguration(t *testing.T) {
}, false}, }, false},
{"valid master configuration with incorrect IPv4 pod subnet", {"valid master configuration with incorrect IPv4 pod subnet",
&kubeadm.InitConfiguration{ &kubeadm.InitConfiguration{
ClusterConfiguration: kubeadm.ClusterConfiguration{ APIEndpoint: kubeadm.APIEndpoint{
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadm.ClusterConfiguration{
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "10.96.0.1/12", ServiceSubnet: "10.96.0.1/12",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -420,11 +420,11 @@ func TestValidateInitConfiguration(t *testing.T) {
}, false}, }, false},
{"valid master configuration with IPv4 service subnet", {"valid master configuration with IPv4 service subnet",
&kubeadm.InitConfiguration{ &kubeadm.InitConfiguration{
ClusterConfiguration: kubeadm.ClusterConfiguration{ APIEndpoint: kubeadm.APIEndpoint{
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadm.ClusterConfiguration{
Etcd: kubeadm.Etcd{ Etcd: kubeadm.Etcd{
Local: &kubeadm.LocalEtcd{ Local: &kubeadm.LocalEtcd{
DataDir: "/some/path", DataDir: "/some/path",
@ -467,11 +467,11 @@ func TestValidateInitConfiguration(t *testing.T) {
}, true}, }, true},
{"valid master configuration using IPv6 service subnet", {"valid master configuration using IPv6 service subnet",
&kubeadm.InitConfiguration{ &kubeadm.InitConfiguration{
ClusterConfiguration: kubeadm.ClusterConfiguration{ APIEndpoint: kubeadm.APIEndpoint{
API: kubeadm.API{
AdvertiseAddress: "1:2:3::4", AdvertiseAddress: "1:2:3::4",
BindPort: 3446, BindPort: 3446,
}, },
ClusterConfiguration: kubeadm.ClusterConfiguration{
Etcd: kubeadm.Etcd{ Etcd: kubeadm.Etcd{
Local: &kubeadm.LocalEtcd{ Local: &kubeadm.LocalEtcd{
DataDir: "/some/path", DataDir: "/some/path",

View File

@ -164,8 +164,8 @@ func getAllAPIObjectNames() []string {
func getDefaultedInitConfig() (*kubeadmapi.InitConfiguration, error) { func getDefaultedInitConfig() (*kubeadmapi.InitConfiguration, error) {
return configutil.ConfigFileAndDefaultsToInternalConfig("", &kubeadmapiv1alpha3.InitConfiguration{ return configutil.ConfigFileAndDefaultsToInternalConfig("", &kubeadmapiv1alpha3.InitConfiguration{
// TODO: Probably move to getDefaultedClusterConfig? // TODO: Probably move to getDefaultedClusterConfig?
APIEndpoint: kubeadmapiv1alpha3.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapiv1alpha3.ClusterConfiguration{ ClusterConfiguration: kubeadmapiv1alpha3.ClusterConfiguration{
API: kubeadmapiv1alpha3.API{AdvertiseAddress: "1.2.3.4"},
KubernetesVersion: fmt.Sprintf("v1.%d.0", constants.MinimumControlPlaneVersion.Minor()+1), KubernetesVersion: fmt.Sprintf("v1.%d.0", constants.MinimumControlPlaneVersion.Minor()+1),
}, },
BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{sillyToken}, BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{sillyToken},

View File

@ -158,11 +158,11 @@ func NewCmdInit(out io.Writer) *cobra.Command {
// AddInitConfigFlags adds init flags bound to the config to the specified flagset // AddInitConfigFlags adds init flags bound to the config to the specified flagset
func AddInitConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1alpha3.InitConfiguration, featureGatesString *string) { func AddInitConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1alpha3.InitConfiguration, featureGatesString *string) {
flagSet.StringVar( flagSet.StringVar(
&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, &cfg.APIEndpoint.AdvertiseAddress, "apiserver-advertise-address", cfg.APIEndpoint.AdvertiseAddress,
"The IP address the API Server will advertise it's listening on. Specify '0.0.0.0' to use the address of the default network interface.", "The IP address the API Server will advertise it's listening on. Specify '0.0.0.0' to use the address of the default network interface.",
) )
flagSet.Int32Var( flagSet.Int32Var(
&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, &cfg.APIEndpoint.BindPort, "apiserver-bind-port", cfg.APIEndpoint.BindPort,
"Port for the API Server to bind to.", "Port for the API Server to bind to.",
) )
flagSet.StringVar( flagSet.StringVar(

View File

@ -235,9 +235,13 @@ func AddJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1alpha3.JoinConfi
&cfg.ControlPlane, "experimental-control-plane", cfg.ControlPlane, &cfg.ControlPlane, "experimental-control-plane", cfg.ControlPlane,
"Create a new control plane instance on this node") "Create a new control plane instance on this node")
flagSet.StringVar( flagSet.StringVar(
&cfg.AdvertiseAddress, "apiserver-advertise-address", cfg.AdvertiseAddress, &cfg.APIEndpoint.AdvertiseAddress, "apiserver-advertise-address", cfg.APIEndpoint.AdvertiseAddress,
"If the node should host a new control plane instance, the IP address the API Server will advertise it's listening on.", "If the node should host a new control plane instance, the IP address the API Server will advertise it's listening on.",
) )
flagSet.Int32Var(
&cfg.APIEndpoint.BindPort, "apiserver-bind-port", cfg.APIEndpoint.BindPort,
"If the node should host a new control plane instance, the port for the API Server to bind to.",
)
} }
// AddJoinOtherFlags adds join flags that are not bound to a configuration file to the given flagset // AddJoinOtherFlags adds join flags that are not bound to a configuration file to the given flagset
@ -265,7 +269,7 @@ func NewJoin(cfgPath string, args []string, defaultcfg *kubeadmapiv1alpha3.JoinC
glog.V(1).Infoln("[join] found NodeName empty; using OS hostname as NodeName") glog.V(1).Infoln("[join] found NodeName empty; using OS hostname as NodeName")
} }
if defaultcfg.AdvertiseAddress == "" { if defaultcfg.APIEndpoint.AdvertiseAddress == "" {
glog.V(1).Infoln("[join] found advertiseAddress empty; using default interface's IP address as advertiseAddress") glog.V(1).Infoln("[join] found advertiseAddress empty; using default interface's IP address as advertiseAddress")
} }
@ -306,7 +310,7 @@ func (j *Join) Run(out io.Writer) error {
// injects into the kubeadm configuration used for init the information about the joining node // injects into the kubeadm configuration used for init the information about the joining node
clusterConfiguration.NodeRegistration = j.cfg.NodeRegistration clusterConfiguration.NodeRegistration = j.cfg.NodeRegistration
clusterConfiguration.API.AdvertiseAddress = j.cfg.AdvertiseAddress clusterConfiguration.APIEndpoint.AdvertiseAddress = j.cfg.APIEndpoint.AdvertiseAddress
// Checks if the cluster configuration supports // Checks if the cluster configuration supports
// joining a new control plane instance and if all the necessary certificates are provided // joining a new control plane instance and if all the necessary certificates are provided

View File

@ -149,8 +149,8 @@ func getAddonsSubCommands() []*cobra.Command {
cmd.Flags().StringVar(&cfg.ImageRepository, "image-repository", cfg.ImageRepository, `Choose a container registry to pull control plane images from`) cmd.Flags().StringVar(&cfg.ImageRepository, "image-repository", cfg.ImageRepository, `Choose a container registry to pull control plane images from`)
if properties.use == "all" || properties.use == "kube-proxy" { if properties.use == "all" || properties.use == "kube-proxy" {
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, `The IP address the API server is accessible on`) cmd.Flags().StringVar(&cfg.APIEndpoint.AdvertiseAddress, "apiserver-advertise-address", cfg.APIEndpoint.AdvertiseAddress, `The IP address the API server is accessible on`)
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, `The port the API server is accessible on`) cmd.Flags().Int32Var(&cfg.APIEndpoint.BindPort, "apiserver-bind-port", cfg.APIEndpoint.BindPort, `The port the API server is accessible on`)
cmd.Flags().StringVar(&cfg.Networking.PodSubnet, "pod-network-cidr", cfg.Networking.PodSubnet, `The range of IP addresses used for the Pod network`) cmd.Flags().StringVar(&cfg.Networking.PodSubnet, "pod-network-cidr", cfg.Networking.PodSubnet, `The range of IP addresses used for the Pod network`)
} }

View File

@ -152,12 +152,10 @@ func makeCmd(certSpec *certsphase.KubeadmCert, cfgPath *string, cfg *kubeadmapiv
func getSANDescription(certSpec *certsphase.KubeadmCert) string { func getSANDescription(certSpec *certsphase.KubeadmCert) string {
//Defaulted config we will use to get SAN certs //Defaulted config we will use to get SAN certs
defaultConfig := &kubeadmapiv1alpha3.InitConfiguration{ defaultConfig := &kubeadmapiv1alpha3.InitConfiguration{
ClusterConfiguration: kubeadmapiv1alpha3.ClusterConfiguration{ APIEndpoint: kubeadmapiv1alpha3.APIEndpoint{
API: kubeadmapiv1alpha3.API{
// GetAPIServerAltNames errors without an AdvertiseAddress; this is as good as any. // GetAPIServerAltNames errors without an AdvertiseAddress; this is as good as any.
AdvertiseAddress: "127.0.0.1", AdvertiseAddress: "127.0.0.1",
}, },
},
} }
defaultInternalConfig := &kubeadmapi.InitConfiguration{} defaultInternalConfig := &kubeadmapi.InitConfiguration{}
@ -192,7 +190,7 @@ func addFlags(cmd *cobra.Command, cfgPath *string, cfg *kubeadmapiv1alpha3.InitC
cmd.Flags().StringVar(&cfg.Networking.DNSDomain, "service-dns-domain", cfg.Networking.DNSDomain, "Alternative domain for services, to use for the API server serving cert") cmd.Flags().StringVar(&cfg.Networking.DNSDomain, "service-dns-domain", cfg.Networking.DNSDomain, "Alternative domain for services, to use for the API server serving cert")
cmd.Flags().StringVar(&cfg.Networking.ServiceSubnet, "service-cidr", cfg.Networking.ServiceSubnet, "Alternative range of IP address for service VIPs, from which derives the internal API server VIP that will be added to the API Server serving cert") cmd.Flags().StringVar(&cfg.Networking.ServiceSubnet, "service-cidr", cfg.Networking.ServiceSubnet, "Alternative range of IP address for service VIPs, from which derives the internal API server VIP that will be added to the API Server serving cert")
cmd.Flags().StringSliceVar(&cfg.APIServerCertSANs, "apiserver-cert-extra-sans", []string{}, "Optional extra altnames to use for the API server serving cert. Can be both IP addresses and DNS names") cmd.Flags().StringSliceVar(&cfg.APIServerCertSANs, "apiserver-cert-extra-sans", []string{}, "Optional extra altnames to use for the API server serving cert. Can be both IP addresses and DNS names")
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address the API server is accessible on, to use for the API server serving cert") cmd.Flags().StringVar(&cfg.APIEndpoint.AdvertiseAddress, "apiserver-advertise-address", cfg.APIEndpoint.AdvertiseAddress, "The IP address the API server is accessible on, to use for the API server serving cert")
} }
} }

View File

@ -265,8 +265,8 @@ func TestSubCmdCertsCreateFilesWithConfigFile(t *testing.T) {
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
CertificatesDir: tmpdir, CertificatesDir: tmpdir,
}, },
NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"},

View File

@ -143,8 +143,8 @@ func getControlPlaneSubCommands(outDir, defaultKubernetesVersion string) []*cobr
cmd.Flags().StringVar(&cfg.KubernetesVersion, "kubernetes-version", cfg.KubernetesVersion, `Choose a specific Kubernetes version for the control plane`) cmd.Flags().StringVar(&cfg.KubernetesVersion, "kubernetes-version", cfg.KubernetesVersion, `Choose a specific Kubernetes version for the control plane`)
if properties.use == "all" || properties.use == "apiserver" { if properties.use == "all" || properties.use == "apiserver" {
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address of the API server is accessible on") cmd.Flags().StringVar(&cfg.APIEndpoint.AdvertiseAddress, "apiserver-advertise-address", cfg.APIEndpoint.AdvertiseAddress, "The IP address of the API server is accessible on")
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, "The port the API server is accessible on") cmd.Flags().Int32Var(&cfg.APIEndpoint.BindPort, "apiserver-bind-port", cfg.APIEndpoint.BindPort, "The port the API server is accessible on")
cmd.Flags().StringVar(&cfg.Networking.ServiceSubnet, "service-cidr", cfg.Networking.ServiceSubnet, "The range of IP address used for service VIPs") cmd.Flags().StringVar(&cfg.Networking.ServiceSubnet, "service-cidr", cfg.Networking.ServiceSubnet, "The range of IP address used for service VIPs")
cmd.Flags().StringVar(&featureGatesString, "feature-gates", featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+ cmd.Flags().StringVar(&featureGatesString, "feature-gates", featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+
"Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n")) "Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n"))

View File

@ -173,8 +173,8 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st
cmd.Flags().StringVar(&cfgPath, "config", cfgPath, "Path to kubeadm config file. WARNING: Usage of a configuration file is experimental") cmd.Flags().StringVar(&cfgPath, "config", cfgPath, "Path to kubeadm config file. WARNING: Usage of a configuration file is experimental")
} }
cmd.Flags().StringVar(&cfg.CertificatesDir, "cert-dir", cfg.CertificatesDir, "The path where certificates are stored") cmd.Flags().StringVar(&cfg.CertificatesDir, "cert-dir", cfg.CertificatesDir, "The path where certificates are stored")
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address the API server is accessible on") cmd.Flags().StringVar(&cfg.APIEndpoint.AdvertiseAddress, "apiserver-advertise-address", cfg.APIEndpoint.AdvertiseAddress, "The IP address the API server is accessible on")
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, "The port the API server is accessible on") cmd.Flags().Int32Var(&cfg.APIEndpoint.BindPort, "apiserver-bind-port", cfg.APIEndpoint.BindPort, "The port the API server is accessible on")
cmd.Flags().StringVar(&outDir, "kubeconfig-dir", outDir, "The path where to save the kubeconfig file") cmd.Flags().StringVar(&outDir, "kubeconfig-dir", outDir, "The path where to save the kubeconfig file")
if properties.use == "all" || properties.use == "kubelet" { if properties.use == "all" || properties.use == "kubelet" {
cmd.Flags().StringVar(&cfg.NodeRegistration.Name, "node-name", cfg.NodeRegistration.Name, `The node name that should be used for the kubelet client certificate`) cmd.Flags().StringVar(&cfg.NodeRegistration.Name, "node-name", cfg.NodeRegistration.Name, `The node name that should be used for the kubelet client certificate`)

View File

@ -277,8 +277,8 @@ func TestKubeConfigSubCommandsThatCreateFilesWithConfigFile(t *testing.T) {
// Adds a master configuration file // Adds a master configuration file
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"},

View File

@ -43,9 +43,6 @@ func TestPrintConfiguration(t *testing.T) {
}, },
}, },
expectedBytes: []byte(`[upgrade/config] Configuration used: expectedBytes: []byte(`[upgrade/config] Configuration used:
api:
advertiseAddress: ""
bindPort: 0
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
auditPolicy: auditPolicy:
logDir: "" logDir: ""
@ -79,9 +76,6 @@ func TestPrintConfiguration(t *testing.T) {
}, },
}, },
expectedBytes: []byte(`[upgrade/config] Configuration used: expectedBytes: []byte(`[upgrade/config] Configuration used:
api:
advertiseAddress: ""
bindPort: 0
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
auditPolicy: auditPolicy:
logDir: "" logDir: ""

View File

@ -239,7 +239,7 @@ func RunUpgradeControlPlane(flags *controlplaneUpgradeFlags) error {
//TODO: as soon as the new config wil be in place check if the node is a known control plane instance //TODO: as soon as the new config wil be in place check if the node is a known control plane instance
// and retrive corresponding infos (now are temporary managed as flag) // and retrive corresponding infos (now are temporary managed as flag)
cfg.NodeRegistration.Name = flags.nodeName cfg.NodeRegistration.Name = flags.nodeName
cfg.API.AdvertiseAddress = flags.advertiseAddress cfg.APIEndpoint.AdvertiseAddress = flags.advertiseAddress
// Rotate API server certificate if needed // Rotate API server certificate if needed
if err := upgrade.BackupAPIServerCertIfNeeded(cfg, flags.dryRun); err != nil { if err := upgrade.BackupAPIServerCertIfNeeded(cfg, flags.dryRun); err != nil {

View File

@ -171,11 +171,11 @@ func TestEnsureProxyAddon(t *testing.T) {
client := clientsetfake.NewSimpleClientset() client := clientsetfake.NewSimpleClientset()
// TODO: Consider using a YAML file instead for this that makes it possible to specify YAML documents for the ComponentConfigs // TODO: Consider using a YAML file instead for this that makes it possible to specify YAML documents for the ComponentConfigs
masterConfig := &kubeadmapiv1alpha3.InitConfiguration{ masterConfig := &kubeadmapiv1alpha3.InitConfiguration{
ClusterConfiguration: kubeadmapiv1alpha3.ClusterConfiguration{ APIEndpoint: kubeadmapiv1alpha3.APIEndpoint{
API: kubeadmapiv1alpha3.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 1234, BindPort: 1234,
}, },
ClusterConfiguration: kubeadmapiv1alpha3.ClusterConfiguration{
Networking: kubeadmapiv1alpha3.Networking{ Networking: kubeadmapiv1alpha3.Networking{
PodSubnet: "5.6.7.8/24", PodSubnet: "5.6.7.8/24",
}, },
@ -191,9 +191,9 @@ func TestEnsureProxyAddon(t *testing.T) {
return true, nil, apierrors.NewUnauthorized("") return true, nil, apierrors.NewUnauthorized("")
}) })
case InvalidMasterEndpoint: case InvalidMasterEndpoint:
masterConfig.API.AdvertiseAddress = "1.2.3" masterConfig.APIEndpoint.AdvertiseAddress = "1.2.3"
case IPv6SetBindAddress: case IPv6SetBindAddress:
masterConfig.API.AdvertiseAddress = "1:2::3:4" masterConfig.APIEndpoint.AdvertiseAddress = "1:2::3:4"
masterConfig.Networking.PodSubnet = "2001:101::/96" masterConfig.Networking.PodSubnet = "2001:101::/96"
} }

View File

@ -400,8 +400,8 @@ func TestUsingExternalCA(t *testing.T) {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4"},
Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"}, Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"},
CertificatesDir: dir, CertificatesDir: dir,
}, },
@ -569,8 +569,8 @@ func TestCreateCertificateFilesMethods(t *testing.T) {
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4"},
Etcd: kubeadmapi.Etcd{Local: &kubeadmapi.LocalEtcd{}}, Etcd: kubeadmapi.Etcd{Local: &kubeadmapi.LocalEtcd{}},
Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"}, Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"},
CertificatesDir: tmpdir, CertificatesDir: tmpdir,

View File

@ -253,9 +253,9 @@ func pathForPublicKey(pkiPath, name string) string {
// GetAPIServerAltNames builds an AltNames object for to be used when generating apiserver certificate // GetAPIServerAltNames builds an AltNames object for to be used when generating apiserver certificate
func GetAPIServerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) { func GetAPIServerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) {
// advertise address // advertise address
advertiseAddress := net.ParseIP(cfg.API.AdvertiseAddress) advertiseAddress := net.ParseIP(cfg.APIEndpoint.AdvertiseAddress)
if advertiseAddress == nil { if advertiseAddress == nil {
return nil, fmt.Errorf("error parsing API AdvertiseAddress %v: is not a valid textual representation of an IP address", cfg.API.AdvertiseAddress) return nil, fmt.Errorf("error parsing APIEndpoint AdvertiseAddress %v: is not a valid textual representation of an IP address", cfg.APIEndpoint.AdvertiseAddress)
} }
// internal IP address for the API server // internal IP address for the API server
@ -326,9 +326,9 @@ func GetEtcdAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, err
// The user can override the listen address with `Etcd.ExtraArgs` and add SANs with `Etcd.PeerCertSANs`. // The user can override the listen address with `Etcd.ExtraArgs` and add SANs with `Etcd.PeerCertSANs`.
func GetEtcdPeerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) { func GetEtcdPeerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) {
// advertise address // advertise address
advertiseAddress := net.ParseIP(cfg.API.AdvertiseAddress) advertiseAddress := net.ParseIP(cfg.APIEndpoint.AdvertiseAddress)
if advertiseAddress == nil { if advertiseAddress == nil {
return nil, fmt.Errorf("error parsing API AdvertiseAddress %v: is not a valid textual representation of an IP address", cfg.API.AdvertiseAddress) return nil, fmt.Errorf("error parsing APIEndpoint AdvertiseAddress %v: is not a valid textual representation of an IP address", cfg.APIEndpoint.AdvertiseAddress)
} }
// create AltNames with defaults DNSNames/IPs // create AltNames with defaults DNSNames/IPs

View File

@ -446,8 +446,8 @@ func TestGetAPIServerAltNames(t *testing.T) {
{ {
name: "ControlPlaneEndpoint DNS", name: "ControlPlaneEndpoint DNS",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4"},
ControlPlaneEndpoint: "api.k8s.io:6443", ControlPlaneEndpoint: "api.k8s.io:6443",
Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"}, Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"},
APIServerCertSANs: []string{"10.1.245.94", "10.1.245.95", "1.2.3.L", "invalid,commas,in,DNS"}, APIServerCertSANs: []string{"10.1.245.94", "10.1.245.95", "1.2.3.L", "invalid,commas,in,DNS"},
@ -460,8 +460,8 @@ func TestGetAPIServerAltNames(t *testing.T) {
{ {
name: "ControlPlaneEndpoint IP", name: "ControlPlaneEndpoint IP",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4"},
ControlPlaneEndpoint: "4.5.6.7:6443", ControlPlaneEndpoint: "4.5.6.7:6443",
Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"}, Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"},
APIServerCertSANs: []string{"10.1.245.94", "10.1.245.95", "1.2.3.L", "invalid,commas,in,DNS"}, APIServerCertSANs: []string{"10.1.245.94", "10.1.245.95", "1.2.3.L", "invalid,commas,in,DNS"},
@ -569,8 +569,8 @@ func TestGetEtcdPeerAltNames(t *testing.T) {
proxyIP := "10.10.10.100" proxyIP := "10.10.10.100"
advertiseIP := "1.2.3.4" advertiseIP := "1.2.3.4"
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: advertiseIP},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: advertiseIP},
Etcd: kubeadmapi.Etcd{ Etcd: kubeadmapi.Etcd{
Local: &kubeadmapi.LocalEtcd{ Local: &kubeadmapi.LocalEtcd{
PeerCertSANs: []string{ PeerCertSANs: []string{

View File

@ -77,7 +77,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.InitConfiguration, k8sVersion *version.Ve
ImagePullPolicy: v1.PullIfNotPresent, ImagePullPolicy: v1.PullIfNotPresent,
Command: getAPIServerCommand(cfg), Command: getAPIServerCommand(cfg),
VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeAPIServer)), VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeAPIServer)),
LivenessProbe: staticpodutil.ComponentProbe(cfg, kubeadmconstants.KubeAPIServer, int(cfg.API.BindPort), "/healthz", v1.URISchemeHTTPS), LivenessProbe: staticpodutil.ComponentProbe(cfg, kubeadmconstants.KubeAPIServer, int(cfg.APIEndpoint.BindPort), "/healthz", v1.URISchemeHTTPS),
Resources: staticpodutil.ComponentResources("250m"), Resources: staticpodutil.ComponentResources("250m"),
Env: getProxyEnvVars(), Env: getProxyEnvVars(),
}, mounts.GetVolumes(kubeadmconstants.KubeAPIServer)), }, mounts.GetVolumes(kubeadmconstants.KubeAPIServer)),
@ -139,7 +139,7 @@ func createStaticPodFiles(manifestDir string, cfg *kubeadmapi.InitConfiguration,
// getAPIServerCommand builds the right API server command from the given config object and version // getAPIServerCommand builds the right API server command from the given config object and version
func getAPIServerCommand(cfg *kubeadmapi.InitConfiguration) []string { func getAPIServerCommand(cfg *kubeadmapi.InitConfiguration) []string {
defaultArguments := map[string]string{ defaultArguments := map[string]string{
"advertise-address": cfg.API.AdvertiseAddress, "advertise-address": cfg.APIEndpoint.AdvertiseAddress,
"insecure-port": "0", "insecure-port": "0",
"enable-admission-plugins": "NodeRestriction", "enable-admission-plugins": "NodeRestriction",
"service-cluster-ip-range": cfg.Networking.ServiceSubnet, "service-cluster-ip-range": cfg.Networking.ServiceSubnet,
@ -150,7 +150,7 @@ func getAPIServerCommand(cfg *kubeadmapi.InitConfiguration) []string {
"kubelet-client-certificate": filepath.Join(cfg.CertificatesDir, kubeadmconstants.APIServerKubeletClientCertName), "kubelet-client-certificate": filepath.Join(cfg.CertificatesDir, kubeadmconstants.APIServerKubeletClientCertName),
"kubelet-client-key": filepath.Join(cfg.CertificatesDir, kubeadmconstants.APIServerKubeletClientKeyName), "kubelet-client-key": filepath.Join(cfg.CertificatesDir, kubeadmconstants.APIServerKubeletClientKeyName),
"enable-bootstrap-token-auth": "true", "enable-bootstrap-token-auth": "true",
"secure-port": fmt.Sprintf("%d", cfg.API.BindPort), "secure-port": fmt.Sprintf("%d", cfg.APIEndpoint.BindPort),
"allow-privileged": "true", "allow-privileged": "true",
"kubelet-preferred-address-types": "InternalIP,ExternalIP,Hostname", "kubelet-preferred-address-types": "InternalIP,ExternalIP,Hostname",
// add options to configure the front proxy. Without the generated client cert, this will never be useable // add options to configure the front proxy. Without the generated client cert, this will never be useable

View File

@ -145,16 +145,18 @@ func TestCreateStaticPodFilesAndWrappers(t *testing.T) {
func TestGetAPIServerCommand(t *testing.T) { func TestGetAPIServerCommand(t *testing.T) {
var tests = []struct { var tests = []struct {
name string name string
cfg *kubeadmapi.ClusterConfiguration cfg *kubeadmapi.InitConfiguration
expected []string expected []string
}{ }{
{ {
name: "testing defaults", name: "testing defaults",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "1.2.3.4"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -187,8 +189,9 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "ignores the audit policy if the feature gate is not enabled", name: "ignores the audit policy if the feature gate is not enabled",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "4.3.2.1"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "4.3.2.1"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
AuditPolicyConfiguration: kubeadmapi.AuditPolicyConfiguration{ AuditPolicyConfiguration: kubeadmapi.AuditPolicyConfiguration{
@ -197,6 +200,7 @@ func TestGetAPIServerCommand(t *testing.T) {
LogMaxAge: utilpointer.Int32Ptr(10), LogMaxAge: utilpointer.Int32Ptr(10),
}, },
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -229,11 +233,13 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "ipv6 advertise address", name: "ipv6 advertise address",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "2001:db8::1"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "2001:db8::1"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -266,8 +272,9 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "an external etcd with custom ca, certs and keys", name: "an external etcd with custom ca, certs and keys",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "2001:db8::1"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "2001:db8::1"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
FeatureGates: map[string]bool{features.HighAvailability: true}, FeatureGates: map[string]bool{features.HighAvailability: true},
Etcd: kubeadmapi.Etcd{ Etcd: kubeadmapi.Etcd{
@ -280,6 +287,7 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -313,8 +321,9 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "an insecure etcd", name: "an insecure etcd",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "2001:db8::1"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "2001:db8::1"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
Etcd: kubeadmapi.Etcd{ Etcd: kubeadmapi.Etcd{
External: &kubeadmapi.ExternalEtcd{ External: &kubeadmapi.ExternalEtcd{
@ -323,6 +332,7 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -352,8 +362,9 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "auditing and HA are enabled with a custom log max age of 0", name: "auditing and HA are enabled with a custom log max age of 0",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "2001:db8::1"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "2001:db8::1"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
FeatureGates: map[string]bool{features.HighAvailability: true, features.Auditing: true}, FeatureGates: map[string]bool{features.HighAvailability: true, features.Auditing: true},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
@ -361,6 +372,7 @@ func TestGetAPIServerCommand(t *testing.T) {
LogMaxAge: utilpointer.Int32Ptr(0), LogMaxAge: utilpointer.Int32Ptr(0),
}, },
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -397,12 +409,14 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "ensure the DynamicKubelet flag gets passed through", name: "ensure the DynamicKubelet flag gets passed through",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "1.2.3.4"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
FeatureGates: map[string]bool{features.DynamicKubeletConfig: true}, FeatureGates: map[string]bool{features.DynamicKubeletConfig: true},
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -436,8 +450,9 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "test APIServerExtraArgs works as expected", name: "test APIServerExtraArgs works as expected",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "1.2.3.4"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
FeatureGates: map[string]bool{features.DynamicKubeletConfig: true, features.Auditing: true}, FeatureGates: map[string]bool{features.DynamicKubeletConfig: true, features.Auditing: true},
@ -448,6 +463,7 @@ func TestGetAPIServerCommand(t *testing.T) {
"audit-log-path": "/var/log/kubernetes", "audit-log-path": "/var/log/kubernetes",
}, },
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -484,14 +500,16 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "authorization-mode extra-args ABAC", name: "authorization-mode extra-args ABAC",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "1.2.3.4"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
APIServerExtraArgs: map[string]string{ APIServerExtraArgs: map[string]string{
"authorization-mode": authzmodes.ModeABAC, "authorization-mode": authzmodes.ModeABAC,
}, },
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -524,14 +542,16 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "insecure-port extra-args", name: "insecure-port extra-args",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "1.2.3.4"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
APIServerExtraArgs: map[string]string{ APIServerExtraArgs: map[string]string{
"insecure-port": "1234", "insecure-port": "1234",
}, },
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=1234", "--insecure-port=1234",
@ -564,14 +584,16 @@ func TestGetAPIServerCommand(t *testing.T) {
}, },
{ {
name: "authorization-mode extra-args Webhook", name: "authorization-mode extra-args Webhook",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{BindPort: 123, AdvertiseAddress: "1.2.3.4"}, APIEndpoint: kubeadmapi.APIEndpoint{BindPort: 123, AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Networking: kubeadmapi.Networking{ServiceSubnet: "bar"}, Networking: kubeadmapi.Networking{ServiceSubnet: "bar"},
CertificatesDir: testCertsDir, CertificatesDir: testCertsDir,
APIServerExtraArgs: map[string]string{ APIServerExtraArgs: map[string]string{
"authorization-mode": authzmodes.ModeWebhook, "authorization-mode": authzmodes.ModeWebhook,
}, },
}, },
},
expected: []string{ expected: []string{
"kube-apiserver", "kube-apiserver",
"--insecure-port=0", "--insecure-port=0",
@ -606,11 +628,7 @@ func TestGetAPIServerCommand(t *testing.T) {
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.name, func(t *testing.T) { t.Run(rt.name, func(t *testing.T) {
// TODO: Make getAPIServerCommand accept a ClusterConfiguration object instead of InitConfiguration actual := getAPIServerCommand(rt.cfg)
initcfg := &kubeadmapi.InitConfiguration{
ClusterConfiguration: *rt.cfg,
}
actual := getAPIServerCommand(initcfg)
sort.Strings(actual) sort.Strings(actual)
sort.Strings(rt.expected) sort.Strings(rt.expected)
if !reflect.DeepEqual(actual, rt.expected) { if !reflect.DeepEqual(actual, rt.expected) {
@ -829,17 +847,19 @@ func TestGetControllerManagerCommandExternalCA(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
cfg *kubeadmapi.ClusterConfiguration cfg *kubeadmapi.InitConfiguration
caKeyPresent bool caKeyPresent bool
expectedArgFunc func(dir string) []string expectedArgFunc func(dir string) []string
}{ }{
{ {
name: "caKeyPresent-false", name: "caKeyPresent-false",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
KubernetesVersion: "v1.7.0", KubernetesVersion: "v1.7.0",
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4"},
Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"}, Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"},
}, },
},
caKeyPresent: false, caKeyPresent: false,
expectedArgFunc: func(tmpdir string) []string { expectedArgFunc: func(tmpdir string) []string {
return []string{ return []string{
@ -858,11 +878,13 @@ func TestGetControllerManagerCommandExternalCA(t *testing.T) {
}, },
{ {
name: "caKeyPresent true", name: "caKeyPresent true",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
KubernetesVersion: "v1.7.0", KubernetesVersion: "v1.7.0",
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4"},
Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"}, Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"},
}, },
},
caKeyPresent: true, caKeyPresent: true,
expectedArgFunc: func(tmpdir string) []string { expectedArgFunc: func(tmpdir string) []string {
return []string{ return []string{
@ -887,12 +909,7 @@ func TestGetControllerManagerCommandExternalCA(t *testing.T) {
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
test.cfg.CertificatesDir = tmpdir test.cfg.CertificatesDir = tmpdir
// TODO: Make getControllerManagerCommand and CreatePKIAssets accept a ClusterConfiguration object instead of InitConfiguration if err := certs.CreatePKIAssets(test.cfg); err != nil {
initcfg := &kubeadmapi.InitConfiguration{
ClusterConfiguration: *test.cfg,
}
if err := certs.CreatePKIAssets(initcfg); err != nil {
t.Errorf("failed creating pki assets: %v", err) t.Errorf("failed creating pki assets: %v", err)
} }
@ -906,7 +923,7 @@ func TestGetControllerManagerCommandExternalCA(t *testing.T) {
} }
} }
actual := getControllerManagerCommand(initcfg, version.MustParseSemantic(test.cfg.KubernetesVersion)) actual := getControllerManagerCommand(test.cfg, version.MustParseSemantic(test.cfg.KubernetesVersion))
expected := test.expectedArgFunc(tmpdir) expected := test.expectedArgFunc(tmpdir)
sort.Strings(actual) sort.Strings(actual)
sort.Strings(expected) sort.Strings(expected)

View File

@ -66,39 +66,39 @@ func TestGetKubeConfigSpecs(t *testing.T) {
// Creates Master Configurations pointing to the pkidir folder // Creates Master Configurations pointing to the pkidir folder
cfgs := []*kubeadmapi.InitConfiguration{ cfgs := []*kubeadmapi.InitConfiguration{
{ {
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"},
}, },
{ {
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ControlPlaneEndpoint: "api.k8s.io", ControlPlaneEndpoint: "api.k8s.io",
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"},
}, },
{ {
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ControlPlaneEndpoint: "api.k8s.io:4321", ControlPlaneEndpoint: "api.k8s.io:4321",
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"},
}, },
{ {
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ControlPlaneEndpoint: "api.k8s.io", ControlPlaneEndpoint: "api.k8s.io",
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "valid-node-name"},
}, },
{ {
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ControlPlaneEndpoint: "api.k8s.io:4321", ControlPlaneEndpoint: "api.k8s.io:4321",
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
@ -320,8 +320,8 @@ func TestCreateKubeconfigFilesAndWrappers(t *testing.T) {
// Creates a Master Configuration pointing to the pkidir folder // Creates a Master Configuration pointing to the pkidir folder
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
} }
@ -397,8 +397,8 @@ func TestWriteKubeConfig(t *testing.T) {
// Creates a Master Configuration pointing to the pkidir folder // Creates a Master Configuration pointing to the pkidir folder
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4", BindPort: 1234},
CertificatesDir: pkidir, CertificatesDir: pkidir,
}, },
} }

View File

@ -130,8 +130,8 @@ func TestRollbackFiles(t *testing.T) {
func TestShouldBackupAPIServerCertAndKey(t *testing.T) { func TestShouldBackupAPIServerCertAndKey(t *testing.T) {
cfg := &kubeadmapi.InitConfiguration{ cfg := &kubeadmapi.InitConfiguration{
APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "1.2.3.4"},
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "1.2.3.4"},
Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"}, Networking: kubeadmapi.Networking{ServiceSubnet: "10.96.0.0/12", DNSDomain: "cluster.local"},
}, },
NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "test-node"}, NodeRegistration: kubeadmapi.NodeRegistrationOptions{Name: "test-node"},

View File

@ -65,10 +65,10 @@ func TestUploadConfiguration(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t2 *testing.T) { t.Run(tt.name, func(t2 *testing.T) {
initialcfg := &kubeadmapiv1alpha3.InitConfiguration{ initialcfg := &kubeadmapiv1alpha3.InitConfiguration{
ClusterConfiguration: kubeadmapiv1alpha3.ClusterConfiguration{ APIEndpoint: kubeadmapiv1alpha3.APIEndpoint{
API: kubeadmapiv1alpha3.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
}, },
ClusterConfiguration: kubeadmapiv1alpha3.ClusterConfiguration{
KubernetesVersion: "v1.10.10", KubernetesVersion: "v1.10.10",
}, },
BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{ BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{

View File

@ -855,15 +855,15 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigu
manifestsDir := filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName) manifestsDir := filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName)
checks := []Checker{ checks := []Checker{
KubernetesVersionCheck{KubernetesVersion: cfg.KubernetesVersion, KubeadmVersion: kubeadmversion.Get().GitVersion}, KubernetesVersionCheck{KubernetesVersion: cfg.KubernetesVersion, KubeadmVersion: kubeadmversion.Get().GitVersion},
FirewalldCheck{ports: []int{int(cfg.API.BindPort), 10250}}, FirewalldCheck{ports: []int{int(cfg.APIEndpoint.BindPort), 10250}},
PortOpenCheck{port: int(cfg.API.BindPort)}, PortOpenCheck{port: int(cfg.APIEndpoint.BindPort)},
PortOpenCheck{port: 10251}, PortOpenCheck{port: 10251},
PortOpenCheck{port: 10252}, PortOpenCheck{port: 10252},
FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.KubeAPIServer, manifestsDir)}, FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.KubeAPIServer, manifestsDir)},
FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.KubeControllerManager, manifestsDir)}, FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.KubeControllerManager, manifestsDir)},
FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.KubeScheduler, manifestsDir)}, FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.KubeScheduler, manifestsDir)},
FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.Etcd, manifestsDir)}, FileAvailableCheck{Path: kubeadmconstants.GetStaticPodFilepath(kubeadmconstants.Etcd, manifestsDir)},
HTTPProxyCheck{Proto: "https", Host: cfg.API.AdvertiseAddress}, HTTPProxyCheck{Proto: "https", Host: cfg.APIEndpoint.AdvertiseAddress},
HTTPProxyCIDRCheck{Proto: "https", CIDR: cfg.Networking.ServiceSubnet}, HTTPProxyCIDRCheck{Proto: "https", CIDR: cfg.Networking.ServiceSubnet},
HTTPProxyCIDRCheck{Proto: "https", CIDR: cfg.Networking.PodSubnet}, HTTPProxyCIDRCheck{Proto: "https", CIDR: cfg.Networking.PodSubnet},
} }
@ -898,7 +898,7 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigu
checks = append(checks, ExternalEtcdVersionCheck{Etcd: cfg.Etcd}) checks = append(checks, ExternalEtcdVersionCheck{Etcd: cfg.Etcd})
} }
if ip := net.ParseIP(cfg.API.AdvertiseAddress); ip != nil { if ip := net.ParseIP(cfg.APIEndpoint.AdvertiseAddress); ip != nil {
if ip.To4() == nil && ip.To16() != nil { if ip.To4() == nil && ip.To16() != nil {
checks = append(checks, checks = append(checks,
FileContentCheck{Path: bridgenf6, Content: []byte{'1'}}, FileContentCheck{Path: bridgenf6, Content: []byte{'1'}},

View File

@ -186,49 +186,52 @@ func (pfct preflightCheckTest) Check() (warning, errors []error) {
func TestRunInitMasterChecks(t *testing.T) { func TestRunInitMasterChecks(t *testing.T) {
var tests = []struct { var tests = []struct {
name string name string
cfg *kubeadmapi.ClusterConfiguration cfg *kubeadmapi.InitConfiguration
expected bool expected bool
}{ }{
{name: "Test valid advertised address", {name: "Test valid advertised address",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "foo"}, APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "foo"},
}, },
expected: false, expected: false,
}, },
{ {
name: "Test CA file exists if specfied", name: "Test CA file exists if specfied",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CAFile: "/foo"}}, Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CAFile: "/foo"}},
}, },
},
expected: false, expected: false,
}, },
{ {
name: "Test Cert file exists if specfied", name: "Test Cert file exists if specfied",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CertFile: "/foo"}}, Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CertFile: "/foo"}},
}, },
},
expected: false, expected: false,
}, },
{ {
name: "Test Key file exists if specfied", name: "Test Key file exists if specfied",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CertFile: "/foo"}}, Etcd: kubeadmapi.Etcd{External: &kubeadmapi.ExternalEtcd{CertFile: "/foo"}},
}, },
},
expected: false, expected: false,
}, },
{ {
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{AdvertiseAddress: "2001:1234::1:15"}, APIEndpoint: kubeadmapi.APIEndpoint{AdvertiseAddress: "2001:1234::1:15"},
}, },
expected: false, expected: false,
}, },
} }
for _, rt := range tests { for _, rt := range tests {
// TODO: Make RunInitMasterChecks accept a ClusterConfiguration object instead of InitConfiguration // TODO: Make RunInitMasterChecks accept a ClusterConfiguration object instead of InitConfiguration
initcfg := &kubeadmapi.InitConfiguration{ actual := RunInitMasterChecks(exec.New(), rt.cfg, sets.NewString())
ClusterConfiguration: *rt.cfg,
}
actual := RunInitMasterChecks(exec.New(), initcfg, sets.NewString())
if (actual == nil) != rt.expected { if (actual == nil) != rt.expected {
t.Errorf( t.Errorf(
"failed RunInitMasterChecks:\n\texpected: %t\n\t actual: %t\n\t error: %v", "failed RunInitMasterChecks:\n\texpected: %t\n\t actual: %t\n\t error: %v",

View File

@ -42,9 +42,9 @@ func FetchConfigFromFileOrCluster(client clientset.Interface, w io.Writer, logPr
if err != nil { if err != nil {
return nil, err return nil, err
} }
// In this function we're only interested in the ClusterConfiguration part.
// TODO: As described above, the return value of this func actually should be a ClusterConfiguration //TODO: this will be reviewed in the following PR for reading/storing the kubeadm-config ConfigMap
if err := SetClusterDynamicDefaults(&initcfg.ClusterConfiguration); err != nil { if err := SetInitDynamicDefaults(initcfg); err != nil {
return nil, err return nil, err
} }
return initcfg, err return initcfg, err

View File

@ -41,12 +41,12 @@ func TestFetchConfigFromFileOrCluster(t *testing.T) {
{ {
name: "fetch valid config from configMap", name: "fetch valid config from configMap",
testCfg: &kubeadmapi.InitConfiguration{ testCfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
KubernetesVersion: "v1.10.3",
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
KubernetesVersion: "v1.10.3",
Etcd: kubeadm.Etcd{ Etcd: kubeadm.Etcd{
Local: &kubeadm.LocalEtcd{ Local: &kubeadm.LocalEtcd{
DataDir: "/some/path", DataDir: "/some/path",
@ -76,12 +76,12 @@ func TestFetchConfigFromFileOrCluster(t *testing.T) {
{ {
name: "fetch invalid config from configMap", name: "fetch invalid config from configMap",
testCfg: &kubeadmapi.InitConfiguration{ testCfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
KubernetesVersion: "v1.10.3",
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
KubernetesVersion: "v1.10.3",
Etcd: kubeadm.Etcd{ Etcd: kubeadm.Etcd{
Local: &kubeadm.LocalEtcd{ Local: &kubeadm.LocalEtcd{
DataDir: "/some/path", DataDir: "/some/path",
@ -113,12 +113,12 @@ func TestFetchConfigFromFileOrCluster(t *testing.T) {
name: "fetch valid config from cfgPath", name: "fetch valid config from cfgPath",
cfgPath: "testdata/conversion/master/v1alpha3.yaml", cfgPath: "testdata/conversion/master/v1alpha3.yaml",
testCfg: &kubeadmapi.InitConfiguration{ testCfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
KubernetesVersion: "v1.10.3",
API: kubeadm.API{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
KubernetesVersion: "v1.10.3",
Etcd: kubeadm.Etcd{ Etcd: kubeadm.Etcd{
Local: &kubeadm.LocalEtcd{ Local: &kubeadm.LocalEtcd{
DataDir: "/some/path", DataDir: "/some/path",

View File

@ -43,12 +43,29 @@ import (
// SetInitDynamicDefaults checks and sets configuration values for the InitConfiguration object // SetInitDynamicDefaults checks and sets configuration values for the InitConfiguration object
func SetInitDynamicDefaults(cfg *kubeadmapi.InitConfiguration) error { func SetInitDynamicDefaults(cfg *kubeadmapi.InitConfiguration) error {
if err := SetBootstrapTokensDynamicDefaults(&cfg.BootstrapTokens); err != nil {
return err
}
if err := SetNodeRegistrationDynamicDefaults(&cfg.NodeRegistration, true); err != nil {
return err
}
if err := SetAPIEndpointDynamicDefaults(&cfg.APIEndpoint); err != nil {
return err
}
if err := SetClusterDynamicDefaults(&cfg.ClusterConfiguration, cfg.APIEndpoint.AdvertiseAddress); err != nil {
return err
}
return nil
}
// SetBootstrapTokensDynamicDefaults checks and sets configuration values for the BootstrapTokens object
func SetBootstrapTokensDynamicDefaults(cfg *[]kubeadmapi.BootstrapToken) error {
// Populate the .Token field with a random value if unset // Populate the .Token field with a random value if unset
// We do this at this layer, and not the API defaulting layer // We do this at this layer, and not the API defaulting layer
// because of possible security concerns, and more practically // because of possible security concerns, and more practically
// because we can't return errors in the API object defaulting // because we can't return errors in the API object defaulting
// process but here we can. // process but here we can.
for i, bt := range cfg.BootstrapTokens { for i, bt := range *cfg {
if bt.Token != nil && len(bt.Token.String()) > 0 { if bt.Token != nil && len(bt.Token.String()) > 0 {
continue continue
} }
@ -61,33 +78,34 @@ func SetInitDynamicDefaults(cfg *kubeadmapi.InitConfiguration) error {
if err != nil { if err != nil {
return err return err
} }
cfg.BootstrapTokens[i].Token = token (*cfg)[i].Token = token
} }
return nil
}
// SetNodeRegistrationDynamicDefaults checks and sets configuration values for the NodeRegistration object
func SetNodeRegistrationDynamicDefaults(cfg *kubeadmapi.NodeRegistrationOptions, masterTaint bool) error {
var err error var err error
cfg.NodeRegistration.Name, err = nodeutil.GetHostname(cfg.NodeRegistration.Name) cfg.Name, err = nodeutil.GetHostname(cfg.Name)
if err != nil { if err != nil {
return err return err
} }
// Only if the slice is nil, we should append the master taint. This allows the user to specify an empty slice for no default master taint // Only if the slice is nil, we should append the master taint. This allows the user to specify an empty slice for no default master taint
if cfg.NodeRegistration.Taints == nil { if masterTaint && cfg.Taints == nil {
cfg.NodeRegistration.Taints = []v1.Taint{kubeadmconstants.MasterTaint} cfg.Taints = []v1.Taint{kubeadmconstants.MasterTaint}
} }
// Do all the defaulting for the nested ClusterConfiguration as well return nil
return SetClusterDynamicDefaults(&cfg.ClusterConfiguration)
} }
// SetClusterDynamicDefaults checks and sets configuration values for the InitConfiguration object // SetAPIEndpointDynamicDefaults checks and sets configuration values for the APIEndpoint object
func SetClusterDynamicDefaults(cfg *kubeadmapi.ClusterConfiguration) error { func SetAPIEndpointDynamicDefaults(cfg *kubeadmapi.APIEndpoint) error {
// Default all the embedded ComponentConfig structs
componentconfigs.Known.Default(cfg)
// validate cfg.API.AdvertiseAddress. // validate cfg.API.AdvertiseAddress.
addressIP := net.ParseIP(cfg.API.AdvertiseAddress) addressIP := net.ParseIP(cfg.AdvertiseAddress)
if addressIP == nil && cfg.API.AdvertiseAddress != "" { if addressIP == nil && cfg.AdvertiseAddress != "" {
return fmt.Errorf("couldn't use \"%s\" as \"apiserver-advertise-address\", must be ipv4 or ipv6 address", cfg.API.AdvertiseAddress) return fmt.Errorf("couldn't use \"%s\" as \"apiserver-advertise-address\", must be ipv4 or ipv6 address", cfg.AdvertiseAddress)
} }
// Choose the right address for the API Server to advertise. If the advertise address is localhost or 0.0.0.0, the default interface's IP address is used // Choose the right address for the API Server to advertise. If the advertise address is localhost or 0.0.0.0, the default interface's IP address is used
// This is the same logic as the API Server uses // This is the same logic as the API Server uses
@ -95,13 +113,23 @@ func SetClusterDynamicDefaults(cfg *kubeadmapi.ClusterConfiguration) error {
if err != nil { if err != nil {
return err return err
} }
cfg.API.AdvertiseAddress = ip.String() cfg.AdvertiseAddress = ip.String()
ip = net.ParseIP(cfg.API.AdvertiseAddress)
return nil
}
// SetClusterDynamicDefaults checks and sets configuration values for the InitConfiguration object
func SetClusterDynamicDefaults(cfg *kubeadmapi.ClusterConfiguration, advertiseAddress string) error {
// Default all the embedded ComponentConfig structs
componentconfigs.Known.Default(cfg)
ip := net.ParseIP(advertiseAddress)
if ip.To4() != nil { if ip.To4() != nil {
cfg.ComponentConfigs.KubeProxy.BindAddress = kubeadmapiv1alpha3.DefaultProxyBindAddressv4 cfg.ComponentConfigs.KubeProxy.BindAddress = kubeadmapiv1alpha3.DefaultProxyBindAddressv4
} else { } else {
cfg.ComponentConfigs.KubeProxy.BindAddress = kubeadmapiv1alpha3.DefaultProxyBindAddressv6 cfg.ComponentConfigs.KubeProxy.BindAddress = kubeadmapiv1alpha3.DefaultProxyBindAddressv6
} }
// Resolve possible version labels and validate version string // Resolve possible version labels and validate version string
if err := NormalizeKubernetesVersion(cfg); err != nil { if err := NormalizeKubernetesVersion(cfg); err != nil {
return err return err

View File

@ -23,28 +23,21 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
netutil "k8s.io/apimachinery/pkg/util/net"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme" kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3" kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation" "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
"k8s.io/kubernetes/pkg/util/node"
) )
// SetJoinDynamicDefaults checks and sets configuration values for the JoinConfiguration object // SetJoinDynamicDefaults checks and sets configuration values for the JoinConfiguration object
func SetJoinDynamicDefaults(cfg *kubeadmapi.JoinConfiguration) error { func SetJoinDynamicDefaults(cfg *kubeadmapi.JoinConfiguration) error {
nodeName, err := node.GetHostname(cfg.NodeRegistration.Name)
if err != nil {
return err
}
cfg.NodeRegistration.Name = nodeName
if cfg.AdvertiseAddress == "" { if err := SetNodeRegistrationDynamicDefaults(&cfg.NodeRegistration, cfg.ControlPlane); err != nil {
ip, err := netutil.ChooseBindAddress(nil)
if err != nil {
return err return err
} }
cfg.AdvertiseAddress = ip.String()
if err := SetAPIEndpointDynamicDefaults(&cfg.APIEndpoint); err != nil {
return err
} }
return nil return nil

View File

@ -1,4 +1,4 @@
API: APIEndpoint:
AdvertiseAddress: 192.168.2.2 AdvertiseAddress: 192.168.2.2
BindPort: 6443 BindPort: 6443
APIServerCertSANs: null APIServerCertSANs: null

View File

@ -1,3 +1,6 @@
apiEndpoint:
advertiseAddress: 192.168.2.2
bindPort: 6443
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
bootstrapTokens: bootstrapTokens:
- groups: - groups:
@ -15,9 +18,6 @@ nodeRegistration:
- effect: NoSchedule - effect: NoSchedule
key: node-role.kubernetes.io/master key: node-role.kubernetes.io/master
--- ---
api:
advertiseAddress: 192.168.2.2
bindPort: 6443
apiServerExtraArgs: apiServerExtraArgs:
authorization-mode: Node,RBAC,Webhook authorization-mode: Node,RBAC,Webhook
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3

View File

@ -1,4 +1,6 @@
APIEndpoint:
AdvertiseAddress: 192.168.2.2 AdvertiseAddress: 192.168.2.2
BindPort: 6443
CACertPath: /etc/kubernetes/pki/ca.crt CACertPath: /etc/kubernetes/pki/ca.crt
ClusterName: kubernetes ClusterName: kubernetes
ControlPlane: false ControlPlane: false

View File

@ -1,4 +1,6 @@
apiEndpoint:
advertiseAddress: 192.168.2.2 advertiseAddress: 192.168.2.2
bindPort: 6443
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
caCertPath: /etc/kubernetes/pki/ca.crt caCertPath: /etc/kubernetes/pki/ca.crt
clusterName: kubernetes clusterName: kubernetes

View File

@ -1,3 +1,6 @@
apiEndpoint:
advertiseAddress: 192.168.2.2
bindPort: 6443
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
bootstrapTokens: bootstrapTokens:
- groups: - groups:
@ -15,9 +18,6 @@ nodeRegistration:
- effect: NoSchedule - effect: NoSchedule
key: node-role.kubernetes.io/master key: node-role.kubernetes.io/master
--- ---
api:
advertiseAddress: 192.168.2.2
bindPort: 6443
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
auditPolicy: auditPolicy:
logDir: /var/log/kubernetes/audit logDir: /var/log/kubernetes/audit

View File

@ -1,4 +1,6 @@
apiEndpoint:
advertiseAddress: 192.168.2.2 advertiseAddress: 192.168.2.2
bindPort: 6443
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
caCertPath: /etc/kubernetes/pki/ca.crt caCertPath: /etc/kubernetes/pki/ca.crt
clusterName: kubernetes clusterName: kubernetes

View File

@ -32,15 +32,15 @@ import (
// - Otherwise, in case the ControlPlaneEndpoint is not defined, use the api.AdvertiseAddress + the api.BindPort. // - Otherwise, in case the ControlPlaneEndpoint is not defined, use the api.AdvertiseAddress + the api.BindPort.
func GetMasterEndpoint(cfg *kubeadmapi.InitConfiguration) (string, error) { func GetMasterEndpoint(cfg *kubeadmapi.InitConfiguration) (string, error) {
// parse the bind port // parse the bind port
bindPortString := strconv.Itoa(int(cfg.API.BindPort)) bindPortString := strconv.Itoa(int(cfg.APIEndpoint.BindPort))
if _, err := ParsePort(bindPortString); err != nil { if _, err := ParsePort(bindPortString); err != nil {
return "", fmt.Errorf("invalid value %q given for api.bindPort: %s", cfg.API.BindPort, err) return "", fmt.Errorf("invalid value %q given for api.bindPort: %s", cfg.APIEndpoint.BindPort, err)
} }
// parse the AdvertiseAddress // parse the AdvertiseAddress
var ip = net.ParseIP(cfg.API.AdvertiseAddress) var ip = net.ParseIP(cfg.APIEndpoint.AdvertiseAddress)
if ip == nil { if ip == nil {
return "", fmt.Errorf("invalid value `%s` given for api.advertiseAddress", cfg.API.AdvertiseAddress) return "", fmt.Errorf("invalid value `%s` given for api.advertiseAddress", cfg.APIEndpoint.AdvertiseAddress)
} }
// set the master url using cfg.API.AdvertiseAddress + the cfg.API.BindPort // set the master url using cfg.API.AdvertiseAddress + the cfg.API.BindPort

View File

@ -32,11 +32,11 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "use ControlPlaneEndpoint (dns) if fully defined", name: "use ControlPlaneEndpoint (dns) if fully defined",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControlPlaneEndpoint: "cp.k8s.io:1234", ControlPlaneEndpoint: "cp.k8s.io:1234",
}, },
}, },
@ -45,11 +45,11 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "use ControlPlaneEndpoint (ipv4) if fully defined", name: "use ControlPlaneEndpoint (ipv4) if fully defined",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControlPlaneEndpoint: "1.2.3.4:1234", ControlPlaneEndpoint: "1.2.3.4:1234",
}, },
}, },
@ -58,11 +58,11 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "use ControlPlaneEndpoint (ipv6) if fully defined", name: "use ControlPlaneEndpoint (ipv6) if fully defined",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControlPlaneEndpoint: "[2001:db8::1]:1234", ControlPlaneEndpoint: "[2001:db8::1]:1234",
}, },
}, },
@ -71,11 +71,12 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "use ControlPlaneEndpoint (dns) + BindPort if ControlPlaneEndpoint defined without port", name: "use ControlPlaneEndpoint (dns) + BindPort if ControlPlaneEndpoint defined without port",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControlPlaneEndpoint: "cp.k8s.io", ControlPlaneEndpoint: "cp.k8s.io",
}, },
}, },
@ -84,11 +85,11 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "use ControlPlaneEndpoint (ipv4) + BindPort if ControlPlaneEndpoint defined without port", name: "use ControlPlaneEndpoint (ipv4) + BindPort if ControlPlaneEndpoint defined without port",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControlPlaneEndpoint: "1.2.3.4", ControlPlaneEndpoint: "1.2.3.4",
}, },
}, },
@ -97,11 +98,12 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "use ControlPlaneEndpoint (ipv6) + BindPort if ControlPlaneEndpoint defined without port", name: "use ControlPlaneEndpoint (ipv6) + BindPort if ControlPlaneEndpoint defined without port",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControlPlaneEndpoint: "2001:db8::1", ControlPlaneEndpoint: "2001:db8::1",
}, },
}, },
@ -110,45 +112,36 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "use AdvertiseAddress (ipv4) + BindPort if ControlPlaneEndpoint is not defined", name: "use AdvertiseAddress (ipv4) + BindPort if ControlPlaneEndpoint is not defined",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "4.5.6.7", AdvertiseAddress: "4.5.6.7",
}, },
}, },
},
expectedEndpoint: "https://4.5.6.7:4567", expectedEndpoint: "https://4.5.6.7:4567",
}, },
{ {
name: "use AdvertiseAddress (ipv6) + BindPort if ControlPlaneEndpoint is not defined", name: "use AdvertiseAddress (ipv6) + BindPort if ControlPlaneEndpoint is not defined",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 4567, BindPort: 4567,
AdvertiseAddress: "2001:db8::1", AdvertiseAddress: "2001:db8::1",
}, },
}, },
},
expectedEndpoint: "https://[2001:db8::1]:4567", expectedEndpoint: "https://[2001:db8::1]:4567",
}, },
{ {
name: "fail if invalid BindPort", name: "fail if invalid BindPort",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
BindPort: 0, BindPort: 0,
}, },
}, },
},
expectedError: true, expectedError: true,
}, },
{ {
name: "fail if invalid ControlPlaneEndpoint (dns)", name: "fail if invalid ControlPlaneEndpoint (dns)",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{
BindPort: 4567,
},
ControlPlaneEndpoint: "bad!!.cp.k8s.io", ControlPlaneEndpoint: "bad!!.cp.k8s.io",
}, },
}, },
@ -158,9 +151,6 @@ func TestGetMasterEndpoint(t *testing.T) {
name: "fail if invalid ControlPlaneEndpoint (ip4)", name: "fail if invalid ControlPlaneEndpoint (ip4)",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{
BindPort: 4567,
},
ControlPlaneEndpoint: "1..0", ControlPlaneEndpoint: "1..0",
}, },
}, },
@ -170,9 +160,6 @@ func TestGetMasterEndpoint(t *testing.T) {
name: "fail if invalid ControlPlaneEndpoint (ip6)", name: "fail if invalid ControlPlaneEndpoint (ip6)",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{
BindPort: 4567,
},
ControlPlaneEndpoint: "1200::AB00:1234::2552:7777:1313", ControlPlaneEndpoint: "1200::AB00:1234::2552:7777:1313",
}, },
}, },
@ -182,9 +169,6 @@ func TestGetMasterEndpoint(t *testing.T) {
name: "fail if invalid ControlPlaneEndpoint (port)", name: "fail if invalid ControlPlaneEndpoint (port)",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ ClusterConfiguration: kubeadmapi.ClusterConfiguration{
API: kubeadmapi.API{
BindPort: 4567,
},
ControlPlaneEndpoint: "cp.k8s.io:0", ControlPlaneEndpoint: "cp.k8s.io:0",
}, },
}, },
@ -193,25 +177,21 @@ func TestGetMasterEndpoint(t *testing.T) {
{ {
name: "fail if invalid AdvertiseAddress (ip4)", name: "fail if invalid AdvertiseAddress (ip4)",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
AdvertiseAddress: "1..0", AdvertiseAddress: "1..0",
BindPort: 4567, BindPort: 4567,
}, },
}, },
},
expectedError: true, expectedError: true,
}, },
{ {
name: "fail if invalid AdvertiseAddress (ip6)", name: "fail if invalid AdvertiseAddress (ip6)",
cfg: &kubeadmapi.InitConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{ APIEndpoint: kubeadmapi.APIEndpoint{
API: kubeadmapi.API{
AdvertiseAddress: "1200::AB00:1234::2552:7777:1313", AdvertiseAddress: "1200::AB00:1234::2552:7777:1313",
BindPort: 4567, BindPort: 4567,
}, },
}, },
},
expectedError: true, expectedError: true,
}, },
} }

View File

@ -230,8 +230,8 @@ func GetProbeAddress(cfg *kubeadmapi.InitConfiguration, componentName string) st
// the node's IP. The only option then is to use localhost. // the node's IP. The only option then is to use localhost.
if features.Enabled(cfg.FeatureGates, features.SelfHosting) { if features.Enabled(cfg.FeatureGates, features.SelfHosting) {
return "127.0.0.1" return "127.0.0.1"
} else if cfg.API.AdvertiseAddress != "" { } else if cfg.APIEndpoint.AdvertiseAddress != "" {
return cfg.API.AdvertiseAddress return cfg.APIEndpoint.AdvertiseAddress
} }
case componentName == kubeadmconstants.KubeControllerManager: case componentName == kubeadmconstants.KubeControllerManager:
if addr, exists := cfg.ControllerManagerExtraArgs[kubeControllerManagerAddressArg]; exists { if addr, exists := cfg.ControllerManagerExtraArgs[kubeControllerManagerAddressArg]; exists {

View File

@ -46,7 +46,7 @@ func TestComponentResources(t *testing.T) {
func TestComponentProbe(t *testing.T) { func TestComponentProbe(t *testing.T) {
var tests = []struct { var tests = []struct {
name string name string
cfg *kubeadmapi.ClusterConfiguration cfg *kubeadmapi.InitConfiguration
component string component string
port int port int
path string path string
@ -55,8 +55,8 @@ func TestComponentProbe(t *testing.T) {
}{ }{
{ {
name: "default apiserver advertise address with http", name: "default apiserver advertise address with http",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{ APIEndpoint: kubeadmapi.APIEndpoint{
AdvertiseAddress: "", AdvertiseAddress: "",
}, },
}, },
@ -68,14 +68,16 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "default apiserver advertise address with http", name: "default apiserver advertise address with http",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{ APIEndpoint: kubeadmapi.APIEndpoint{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
}, },
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
FeatureGates: map[string]bool{ FeatureGates: map[string]bool{
features.SelfHosting: true, features.SelfHosting: true,
}, },
}, },
},
component: kubeadmconstants.KubeAPIServer, component: kubeadmconstants.KubeAPIServer,
port: 1, port: 1,
path: "foo", path: "foo",
@ -84,8 +86,8 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "default apiserver advertise address with https", name: "default apiserver advertise address with https",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{ APIEndpoint: kubeadmapi.APIEndpoint{
AdvertiseAddress: "", AdvertiseAddress: "",
}, },
}, },
@ -97,8 +99,8 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "valid ipv4 apiserver advertise address with http", name: "valid ipv4 apiserver advertise address with http",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{ APIEndpoint: kubeadmapi.APIEndpoint{
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
}, },
}, },
@ -110,8 +112,8 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "valid ipv6 apiserver advertise address with http", name: "valid ipv6 apiserver advertise address with http",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
API: kubeadmapi.API{ APIEndpoint: kubeadmapi.APIEndpoint{
AdvertiseAddress: "2001:db8::1", AdvertiseAddress: "2001:db8::1",
}, },
}, },
@ -123,9 +125,11 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "valid IPv4 controller-manager probe", name: "valid IPv4 controller-manager probe",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControllerManagerExtraArgs: map[string]string{"address": "1.2.3.4"}, ControllerManagerExtraArgs: map[string]string{"address": "1.2.3.4"},
}, },
},
component: kubeadmconstants.KubeControllerManager, component: kubeadmconstants.KubeControllerManager,
port: 1, port: 1,
path: "foo", path: "foo",
@ -134,9 +138,11 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "valid IPv6 controller-manager probe", name: "valid IPv6 controller-manager probe",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
ControllerManagerExtraArgs: map[string]string{"address": "2001:db8::1"}, ControllerManagerExtraArgs: map[string]string{"address": "2001:db8::1"},
}, },
},
component: kubeadmconstants.KubeControllerManager, component: kubeadmconstants.KubeControllerManager,
port: 1, port: 1,
path: "foo", path: "foo",
@ -145,9 +151,11 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "valid IPv4 scheduler probe", name: "valid IPv4 scheduler probe",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
SchedulerExtraArgs: map[string]string{"address": "1.2.3.4"}, SchedulerExtraArgs: map[string]string{"address": "1.2.3.4"},
}, },
},
component: kubeadmconstants.KubeScheduler, component: kubeadmconstants.KubeScheduler,
port: 1, port: 1,
path: "foo", path: "foo",
@ -156,9 +164,11 @@ func TestComponentProbe(t *testing.T) {
}, },
{ {
name: "valid IPv6 scheduler probe", name: "valid IPv6 scheduler probe",
cfg: &kubeadmapi.ClusterConfiguration{ cfg: &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
SchedulerExtraArgs: map[string]string{"address": "2001:db8::1"}, SchedulerExtraArgs: map[string]string{"address": "2001:db8::1"},
}, },
},
component: kubeadmconstants.KubeScheduler, component: kubeadmconstants.KubeScheduler,
port: 1, port: 1,
path: "foo", path: "foo",
@ -167,11 +177,7 @@ func TestComponentProbe(t *testing.T) {
}, },
} }
for _, rt := range tests { for _, rt := range tests {
// TODO: Make ComponentProbe accept a ClusterConfiguration object instead of InitConfiguration actual := ComponentProbe(rt.cfg, rt.component, rt.port, rt.path, rt.scheme)
initcfg := &kubeadmapi.InitConfiguration{
ClusterConfiguration: *rt.cfg,
}
actual := ComponentProbe(initcfg, rt.component, rt.port, rt.path, rt.scheme)
if actual.Handler.HTTPGet.Host != rt.expected { if actual.Handler.HTTPGet.Host != rt.expected {
t.Errorf("%s test case failed:\n\texpected: %s\n\t actual: %s", t.Errorf("%s test case failed:\n\texpected: %s\n\t actual: %s",
rt.name, rt.expected, rt.name, rt.expected,

View File

@ -55,15 +55,15 @@ func SetupInitConfigurationFile(t *testing.T, tmpdir string, cfg *kubeadmapi.Ini
cfgTemplate := template.Must(template.New("init").Parse(dedent.Dedent(` cfgTemplate := template.Must(template.New("init").Parse(dedent.Dedent(`
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
kind: InitConfiguration kind: InitConfiguration
apiEndpoint:
advertiseAddress: {{.APIEndpoint.AdvertiseAddress}}
bindPort: {{.APIEndpoint.BindPort}}
nodeRegistration: nodeRegistration:
name: {{.NodeRegistration.Name}} name: {{.NodeRegistration.Name}}
--- ---
apiVersion: kubeadm.k8s.io/v1alpha3 apiVersion: kubeadm.k8s.io/v1alpha3
kind: ClusterConfiguration kind: ClusterConfiguration
certificatesDir: {{.CertificatesDir}} certificatesDir: {{.CertificatesDir}}
api:
advertiseAddress: {{.API.AdvertiseAddress}}
bindPort: {{.API.BindPort}}
kubernetesVersion: v1.10.0 kubernetesVersion: v1.10.0
`))) `)))