Skip to content
Permalink
Browse files

kubeadm: Remove ClusterConfiguration from InitConfiguration in v1beta2

Ever since v1alpha3, InitConfiguration is containing ClusterConfiguration
embedded in it. This was done to mimic the internal InitConfiguration, which in
turn is used throughout the kubeadm code base as if it is the old
MasterConfiguration of v1alpha2.

This, however, is confusing to users who vendor in kubeadm as the embedded
ClusterConfiguration inside InitConfiguration is not marshalled to YAML.
For this to happen, special care must be taken for the ClusterConfiguration
field to marshalled separately.

Thus, to make things smooth for users and to reduce third party exposure to
technical debt, this change removes ClusterConfiguration embedding from
InitConfiguration.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
  • Loading branch information...
rosti committed May 8, 2019
1 parent f5a1ceb commit a88ddf09bb0ae2a839eb794dc9698a051d95283d
@@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
srcs = [
"bootstraptokenstring.go",
"conversion.go",
"defaults.go",
"defaults_unix.go",
"defaults_windows.go",
@@ -0,0 +1,38 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta2

import (
conversion "k8s.io/apimachinery/pkg/conversion"
kubeadm "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
)

func Convert_kubeadm_InitConfiguration_To_v1beta2_InitConfiguration(in *kubeadm.InitConfiguration, out *InitConfiguration, s conversion.Scope) error {
return autoConvert_kubeadm_InitConfiguration_To_v1beta2_InitConfiguration(in, out, s)
}

func Convert_v1beta2_InitConfiguration_To_kubeadm_InitConfiguration(in *InitConfiguration, out *kubeadm.InitConfiguration, s conversion.Scope) error {
err := autoConvert_v1beta2_InitConfiguration_To_kubeadm_InitConfiguration(in, out, s)
if err != nil {
return err
}

// Keep the fuzzer test happy by setting out.ClusterConfiguration to defaults
clusterCfg := &ClusterConfiguration{}
SetDefaults_ClusterConfiguration(clusterCfg)
return Convert_v1beta2_ClusterConfiguration_To_kubeadm_ClusterConfiguration(clusterCfg, &out.ClusterConfiguration, s)
}
@@ -67,7 +67,6 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {

// SetDefaults_InitConfiguration assigns default values for the InitConfiguration
func SetDefaults_InitConfiguration(obj *InitConfiguration) {
SetDefaults_ClusterConfiguration(&obj.ClusterConfiguration)
SetDefaults_BootstrapTokens(obj)
SetDefaults_APIEndpoint(&obj.LocalAPIEndpoint)
}
@@ -28,12 +28,6 @@ import (
type InitConfiguration struct {
metav1.TypeMeta `json:",inline"`

// ClusterConfiguration holds the cluster-wide information, and embeds that struct (which can be (un)marshalled separately as well)
// When InitConfiguration is marshalled to bytes in the external version, this information IS NOT preserved (which can be seen from
// the `json:"-"` tag. This is due to that when InitConfiguration is (un)marshalled, it turns into two YAML documents, one for the
// InitConfiguration and ClusterConfiguration. Hence, the information must not be duplicated, and is therefore omitted here.
ClusterConfiguration `json:"-"`

// `kubeadm init`-only information. These fields are solely used the first time `kubeadm init` runs.
// After that, the information in the fields IS NOT uploaded to the `kubeadm-config` ConfigMap
// that is used by `kubeadm upgrade` for instance. These fields must be omitempty.

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

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

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

@@ -81,19 +81,17 @@ func newCmdCertsRenewal() *cobra.Command {
type renewConfig struct {
cfgPath string
kubeconfigPath string
cfg kubeadmapiv1beta2.InitConfiguration
cfg kubeadmapiv1beta2.ClusterConfiguration
useAPI bool
useCSR bool
csrPath string
}

func getRenewSubCommands(kdir string) []*cobra.Command {
cfg := &renewConfig{
cfg: kubeadmapiv1beta2.InitConfiguration{
ClusterConfiguration: kubeadmapiv1beta2.ClusterConfiguration{
// Setting kubernetes version to a default value in order to allow a not necessary internet lookup
KubernetesVersion: constants.CurrentKubernetesVersion.String(),
},
cfg: kubeadmapiv1beta2.ClusterConfiguration{
// Setting kubernetes version to a default value in order to allow a not necessary internet lookup
KubernetesVersion: constants.CurrentKubernetesVersion.String(),
},
}
// Default values for the cobra help text
@@ -169,7 +167,7 @@ func addFlags(cmd *cobra.Command, cfg *renewConfig) {
}

func renewCert(cert *certsphase.KubeadmCert, caCert *certsphase.KubeadmCert, cfg *renewConfig) {
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfg.cfgPath, &cfg.cfg)
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfg.cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, &cfg.cfg)
kubeadmutil.CheckErr(err)

// if the renewal operation is set to generate only CSR request
@@ -213,7 +211,7 @@ func renewCert(cert *certsphase.KubeadmCert, caCert *certsphase.KubeadmCert, cfg
}

func renewEmbeddedCert(kdir, k string, cfg *renewConfig) {
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfg.cfgPath, &cfg.cfg)
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfg.cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, &cfg.cfg)
kubeadmutil.CheckErr(err)

// if the renewal operation is set to generate only CSR request
@@ -61,10 +61,12 @@ func newCmdKubeConfigUtility(out io.Writer) *cobra.Command {
// newCmdUserKubeConfig returns sub commands for kubeconfig phase
func newCmdUserKubeConfig(out io.Writer) *cobra.Command {

cfg := &kubeadmapiv1beta2.InitConfiguration{}
initCfg := &kubeadmapiv1beta2.InitConfiguration{}
clusterCfg := &kubeadmapiv1beta2.ClusterConfiguration{}

// Default values for the cobra help text
kubeadmscheme.Scheme.Default(cfg)
kubeadmscheme.Scheme.Default(initCfg)
kubeadmscheme.Scheme.Default(clusterCfg)

var token, clientName string
var organizations []string
@@ -80,8 +82,8 @@ func newCmdUserKubeConfig(out io.Writer) *cobra.Command {
kubeadmutil.CheckErr(errors.New("missing required argument --client-name"))
}

// This call returns the ready-to-use configuration based on the default cfg populated by flags
internalcfg, err := configutil.DefaultedInitConfiguration(cfg)
// This call returns the ready-to-use configuration based on the defaults populated by flags
internalcfg, err := configutil.DefaultedInitConfiguration(initCfg, clusterCfg)
kubeadmutil.CheckErr(err)

// if the kubeconfig file for an additional user has to use a token, use it
@@ -95,10 +97,14 @@ func newCmdUserKubeConfig(out io.Writer) *cobra.Command {
},
}

// Add flags to the command
cmd.Flags().StringVar(&cfg.CertificatesDir, options.CertificatesDir, cfg.CertificatesDir, "The path where certificates are stored")
cmd.Flags().StringVar(&cfg.LocalAPIEndpoint.AdvertiseAddress, options.APIServerAdvertiseAddress, cfg.LocalAPIEndpoint.AdvertiseAddress, "The IP address the API server is accessible on")
cmd.Flags().Int32Var(&cfg.LocalAPIEndpoint.BindPort, options.APIServerBindPort, cfg.LocalAPIEndpoint.BindPort, "The port the API server is accessible on")
// Add ClusterConfiguration backed flags to the command
cmd.Flags().StringVar(&clusterCfg.CertificatesDir, options.CertificatesDir, clusterCfg.CertificatesDir, "The path where certificates are stored")

// Add ClusterConfiguration backed flags to the command
cmd.Flags().StringVar(&initCfg.LocalAPIEndpoint.AdvertiseAddress, options.APIServerAdvertiseAddress, initCfg.LocalAPIEndpoint.AdvertiseAddress, "The IP address the API server is accessible on")
cmd.Flags().Int32Var(&initCfg.LocalAPIEndpoint.BindPort, options.APIServerBindPort, initCfg.LocalAPIEndpoint.BindPort, "The port the API server is accessible on")

// Add command specific flags
cmd.Flags().StringVar(&token, options.TokenStr, token, "The token that should be used as the authentication mechanism for this kubeconfig, instead of client certificates")
cmd.Flags().StringVar(&clientName, "client-name", clientName, "The name of user. It will be used as the CN if client certificates are created")
cmd.Flags().StringSliceVar(&organizations, "org", organizations, "The orgnizations of the client certificate. It will be used as the O if client certificates are created")
@@ -75,7 +75,7 @@ func NewCmdSelfhosting(in io.Reader) *cobra.Command {
// getSelfhostingSubCommand returns sub commands for Self-hosting phase
func getSelfhostingSubCommand(in io.Reader) *cobra.Command {

cfg := &kubeadmapiv1beta2.InitConfiguration{}
cfg := &kubeadmapiv1beta2.ClusterConfiguration{}
// Default values for the cobra help text
kubeadmscheme.Scheme.Default(cfg)

@@ -124,10 +124,10 @@ func getSelfhostingSubCommand(in io.Reader) *cobra.Command {

// KubernetesVersion is not used, but we set it explicitly to avoid the lookup
// of the version from the internet when executing LoadOrDefaultInitConfiguration
phases.SetKubernetesVersion(&cfg.ClusterConfiguration)
phases.SetKubernetesVersion(cfg)

// This call returns the ready-to-use configuration based on the configuration file that might or might not exist and the default cfg populated by flags
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, cfg)
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, cfg)
kubeadmutil.CheckErr(err)

// Converts the Static Pod-hosted control plane into a self-hosted one

0 comments on commit a88ddf0

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