Permalink
Browse files

Merge pull request #69463 from rosti/automated-cherry-pick-of-#69426-…

…upstream-release-1.12

Automated cherry pick of #69426: kubeadm: Allow mixing Init and Join Configurations
  • Loading branch information...
k8s-ci-robot committed Oct 5, 2018
2 parents 3bf9523 + 9109e62 commit 4ed3216f3ec431b140b1d899130a69fc671678f4
@@ -93,19 +93,18 @@ func DetectUnsupportedVersion(b []byte) error {
}
knownKinds[gvk.Kind] = true
}
// InitConfiguration, MasterConfiguration and NodeConfiguration are mutually exclusive, error if more than one are specified
// InitConfiguration, MasterConfiguration and NodeConfiguration may not apply together, warn if more than one is specified
mutuallyExclusive := []string{constants.InitConfigurationKind, constants.MasterConfigurationKind, constants.JoinConfigurationKind, constants.NodeConfigurationKind}
foundOne := false
mutuallyExclusiveCount := 0
for _, kind := range mutuallyExclusive {
if knownKinds[kind] {
if !foundOne {
foundOne = true
continue
}
return fmt.Errorf("invalid configuration: kinds %v are mutually exclusive", mutuallyExclusive)
mutuallyExclusiveCount++
}
}
if mutuallyExclusiveCount > 1 {
glog.Warningf("WARNING: Detected resource kinds that may not apply: %v", mutuallyExclusive)
}
return nil
}
@@ -132,35 +132,37 @@ func TestDetectUnsupportedVersion(t *testing.T) {
fileContents: bytes.Join([][]byte{files["Foo"], files["Master_v1alpha1"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
// CanMix* cases used to be MustNotMix*, however due to UX issues DetectUnsupportedVersion had to tolerate that.
// So the following tests actually verify, that previously conflicting configs can be mixed together with no error.
{
name: "MustNotMixMasterNode",
name: "CanMixMasterNode",
fileContents: bytes.Join([][]byte{files["Master_v1alpha2"], files["Node_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
expectedErr: false,
},
{
name: "MustNotMixMasterJoin",
name: "CanMixMasterJoin",
fileContents: bytes.Join([][]byte{files["Master_v1alpha2"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
expectedErr: false,
},
{
name: "MustNotMixJoinNode",
name: "CanMixJoinNode",
fileContents: bytes.Join([][]byte{files["Join_v1alpha3"], files["Node_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
expectedErr: false,
},
{
name: "MustNotMixInitMaster",
name: "CanMixInitMaster",
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Master_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
expectedErr: false,
},
{
name: "MustNotMixInitNode",
name: "CanMixInitNode",
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Node_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
expectedErr: false,
},
{
name: "MustNotMixInitJoin",
name: "CanMixInitJoin",
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
expectedErr: false,
},
}
@@ -19,6 +19,7 @@ package config
import (
"fmt"
"io/ioutil"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
"github.com/golang/glog"
@@ -27,6 +28,7 @@ import (
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
)
// SetJoinDynamicDefaults checks and sets configuration values for the JoinConfiguration object
@@ -61,7 +63,23 @@ func NodeConfigFileAndDefaultsToInternalConfig(cfgPath string, defaultversionedc
return nil, err
}
if err := runtime.DecodeInto(kubeadmscheme.Codecs.UniversalDecoder(), b, internalcfg); err != nil {
gvkmap, err := kubeadmutil.SplitYAMLDocuments(b)
if err != nil {
return nil, err
}
joinBytes := []byte{}
for gvk, bytes := range gvkmap {
if gvk.Kind == constants.JoinConfigurationKind || gvk.Kind == constants.NodeConfigurationKind {
joinBytes = bytes
}
}
if len(joinBytes) == 0 {
return nil, fmt.Errorf("no %s found in config file %q", constants.JoinConfigurationKind, cfgPath)
}
if err := runtime.DecodeInto(kubeadmscheme.Codecs.UniversalDecoder(), joinBytes, internalcfg); err != nil {
return nil, err
}
} else {

0 comments on commit 4ed3216

Please sign in to comment.