Skip to content
Permalink
Browse files

Merge pull request #65952 from luxas/kubeadm_init_join_exclusive

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

kubeadm: Make the kubeadm config kinds mutually exclusive

**What this PR does / why we need it**:
Right now it would be possible to feed kubeadm with a YAML document with all the four different Config kinds kubeadm at HEAD supports, `MasterConfiguration`, `InitConfiguration`, `JoinConfiguration` and `NodeConfiguration`. This PR makes them mutually exclusive so that kubeadm can know how to handle the config file properly.

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

**Special notes for your reviewer**:
Please only review the last commit

**Release note**:

```release-note
NONE
```
@kubernetes/sig-cluster-lifecycle-pr-reviews
  • Loading branch information...
Kubernetes Submit Queue
Kubernetes Submit Queue committed Jul 17, 2018
2 parents 0e1eec5 + 728b30b commit 0e097af8d8208a02dc477a874e8dac39835c1983
Showing with 89 additions and 9 deletions.
  1. +15 −0 cmd/kubeadm/app/util/config/common.go
  2. +74 −9 cmd/kubeadm/app/util/config/common_test.go
@@ -82,10 +82,25 @@ func DetectUnsupportedVersion(b []byte) error {
"kubeadm.k8s.io/v1alpha1": "v1.11",
}
// If we find an old API version in this gvk list, error out and tell the user why this doesn't work
knownKinds := map[string]bool{}
for _, gvk := range gvks {
if useKubeadmVersion := oldKnownAPIVersions[gvk.GroupVersion().String()]; len(useKubeadmVersion) != 0 {
return fmt.Errorf("your configuration file uses an old API spec: %q. Please use kubeadm %s instead and run 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.", gvk.GroupVersion().String(), useKubeadmVersion)
}
knownKinds[gvk.Kind] = true
}
// InitConfiguration, MasterConfiguration and NodeConfiguration are mutually exclusive, error if more than one are specified
mutuallyExclusive := []string{constants.InitConfigurationKind, constants.MasterConfigurationKind, constants.JoinConfigurationKind, constants.NodeConfigurationKind}
foundOne := false
for _, kind := range mutuallyExclusive {
if knownKinds[kind] {
if !foundOne {
foundOne = true
continue
}

return fmt.Errorf("invalid configuration: kinds %v are mutually exclusive", mutuallyExclusive)
}
}
return nil
}
@@ -31,13 +31,21 @@ kind: InitConfiguration
`),
"Node_v1alpha1": []byte(`
apiVersion: kubeadm.k8s.io/v1alpha1
kind: JoinConfiguration
kind: NodeConfiguration
`),
"Master_v1alpha2": []byte(`
apiVersion: kubeadm.k8s.io/v1alpha2
kind: MasterConfiguration
`),
"Node_v1alpha2": []byte(`
apiVersion: kubeadm.k8s.io/v1alpha2
kind: NodeConfiguration
`),
"Master_v1alpha3": []byte(`
"Init_v1alpha3": []byte(`
apiVersion: kubeadm.k8s.io/v1alpha3
kind: InitConfiguration
`),
"Node_v1alpha3": []byte(`
"Join_v1alpha3": []byte(`
apiVersion: kubeadm.k8s.io/v1alpha3
kind: JoinConfiguration
`),
@@ -50,6 +58,10 @@ bar: bar
kind: Bar
foo: foo
bar: bar
`),
"Foo": []byte(`
apiVersion: foo.k8s.io/v1
kind: Foo
`),
}

@@ -70,16 +82,39 @@ func TestDetectUnsupportedVersion(t *testing.T) {
expectedErr: true,
},
{
name: "Master_v1alpha3",
fileContents: files["Master_v1alpha3"],
name: "Master_v1alpha2",
fileContents: files["Master_v1alpha2"],
},
{
name: "Node_v1alpha3",
fileContents: files["Node_v1alpha3"],
name: "Node_v1alpha2",
fileContents: files["Node_v1alpha2"],
},
{
name: "Init_v1alpha3",
fileContents: files["Init_v1alpha3"],
},
{
name: "Join_v1alpha3",
fileContents: files["Join_v1alpha3"],
},
{
name: "DuplicateMaster",
fileContents: bytes.Join([][]byte{files["Master_v1alpha3"], files["Master_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
fileContents: bytes.Join([][]byte{files["Master_v1alpha2"], files["Master_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "DuplicateNode",
fileContents: bytes.Join([][]byte{files["Node_v1alpha2"], files["Node_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "DuplicateInit",
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Init_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "DuplicateJoin",
fileContents: bytes.Join([][]byte{files["Join_v1alpha3"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
@@ -94,7 +129,37 @@ func TestDetectUnsupportedVersion(t *testing.T) {
},
{
name: "v1alpha1InMultiple",
fileContents: bytes.Join([][]byte{files["Master_v1alpha3"], files["Master_v1alpha1"]}, []byte(constants.YAMLDocumentSeparator)),
fileContents: bytes.Join([][]byte{files["Foo"], files["Master_v1alpha1"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "MustNotMixMasterNode",
fileContents: bytes.Join([][]byte{files["Master_v1alpha2"], files["Node_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "MustNotMixMasterJoin",
fileContents: bytes.Join([][]byte{files["Master_v1alpha2"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "MustNotMixJoinNode",
fileContents: bytes.Join([][]byte{files["Join_v1alpha3"], files["Node_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "MustNotMixInitMaster",
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Master_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "MustNotMixInitNode",
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Node_v1alpha2"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
{
name: "MustNotMixInitJoin",
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
expectedErr: true,
},
}

0 comments on commit 0e097af

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