mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #69426 from rosti/allow-init-join-mix
kubeadm: Allow mixing Init and Join Configurations
This commit is contained in:
commit
1aba19a26e
@ -93,19 +93,19 @@ func DetectUnsupportedVersion(b []byte) error {
|
|||||||
}
|
}
|
||||||
knownKinds[gvk.Kind] = true
|
knownKinds[gvk.Kind] = true
|
||||||
}
|
}
|
||||||
// InitConfiguration, MasterConfiguration and NodeConfiguration are mutually exclusive, error if more than one are specified
|
|
||||||
|
// InitConfiguration and JoinConfiguration may not apply together, warn if more than one is specified
|
||||||
mutuallyExclusive := []string{constants.InitConfigurationKind, constants.JoinConfigurationKind}
|
mutuallyExclusive := []string{constants.InitConfigurationKind, constants.JoinConfigurationKind}
|
||||||
foundOne := false
|
mutuallyExclusiveCount := 0
|
||||||
for _, kind := range mutuallyExclusive {
|
for _, kind := range mutuallyExclusive {
|
||||||
if knownKinds[kind] {
|
if knownKinds[kind] {
|
||||||
if !foundOne {
|
mutuallyExclusiveCount++
|
||||||
foundOne = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("invalid configuration: kinds %v are mutually exclusive", mutuallyExclusive)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if mutuallyExclusiveCount > 1 {
|
||||||
|
glog.Warningf("WARNING: Detected resource kinds that may not apply: %v", mutuallyExclusive)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,25 +163,27 @@ func TestDetectUnsupportedVersion(t *testing.T) {
|
|||||||
name: "Ignore other Kind",
|
name: "Ignore other Kind",
|
||||||
fileContents: bytes.Join([][]byte{files["Foo"], files["Master_v1beta1"]}, []byte(constants.YAMLDocumentSeparator)),
|
fileContents: bytes.Join([][]byte{files["Foo"], files["Master_v1beta1"]}, []byte(constants.YAMLDocumentSeparator)),
|
||||||
},
|
},
|
||||||
|
// CanMixInitJoin cases used to be MustNotMixInitJoin, however due to UX issues DetectUnsupportedVersion had to tolerate that.
|
||||||
|
// So the following tests actually verify, that Init and Join can be mixed together with no error.
|
||||||
{
|
{
|
||||||
name: "MustNotMixInitJoin v1alpha3",
|
name: "CanMixInitJoin v1alpha3",
|
||||||
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
|
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
|
||||||
expectedErr: true,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "MustNotMixInitJoin v1alpha3 - v1beta1",
|
name: "CanMixInitJoin v1alpha3 - v1beta1",
|
||||||
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Join_v1beta1"]}, []byte(constants.YAMLDocumentSeparator)),
|
fileContents: bytes.Join([][]byte{files["Init_v1alpha3"], files["Join_v1beta1"]}, []byte(constants.YAMLDocumentSeparator)),
|
||||||
expectedErr: true,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "MustNotMixInitJoin v1beta1 - v1alpha3",
|
name: "CanMixInitJoin v1beta1 - v1alpha3",
|
||||||
fileContents: bytes.Join([][]byte{files["Init_v1beta1"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
|
fileContents: bytes.Join([][]byte{files["Init_v1beta1"], files["Join_v1alpha3"]}, []byte(constants.YAMLDocumentSeparator)),
|
||||||
expectedErr: true,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "MustNotMixInitJoin v1beta1",
|
name: "CanMixInitJoin v1beta1",
|
||||||
fileContents: bytes.Join([][]byte{files["Init_v1beta1"], files["Join_v1beta1"]}, []byte(constants.YAMLDocumentSeparator)),
|
fileContents: bytes.Join([][]byte{files["Init_v1beta1"], files["Join_v1beta1"]}, []byte(constants.YAMLDocumentSeparator)),
|
||||||
expectedErr: true,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ import (
|
|||||||
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
||||||
kubeadmapiv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
|
kubeadmapiv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
|
"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
|
// SetJoinDynamicDefaults checks and sets configuration values for the JoinConfiguration object
|
||||||
@ -61,7 +63,23 @@ func NodeConfigFileAndDefaultsToInternalConfig(cfgPath string, defaultversionedc
|
|||||||
return nil, err
|
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 {
|
||||||
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user