mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Rename MasterConfiguration to InitConfiguration in v1alpha3, but support both names for this release of kubeadm
This commit is contained in:
parent
52f0591ad9
commit
c48dfa6fe9
@ -58,9 +58,9 @@ func Resource(resource string) schema.GroupResource {
|
||||
|
||||
func addKnownTypes(scheme *runtime.Scheme) error {
|
||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||
&InitConfiguration{},
|
||||
&NodeConfiguration{},
|
||||
)
|
||||
scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("MasterConfiguration"), &InitConfiguration{})
|
||||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
|
||||
return nil
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
availableAPIObjects = []string{constants.InitConfigurationKind, constants.NodeConfigurationKind}
|
||||
defaultAPIObjects = []string{constants.InitConfigurationKind, constants.NodeConfigurationKind}
|
||||
availableAPIObjects = []string{constants.InitConfigurationKind, constants.MasterConfigurationKind, constants.NodeConfigurationKind}
|
||||
// sillyToken is only set statically to make kubeadm not randomize the token on every run
|
||||
sillyToken = kubeadmapiv1alpha3.BootstrapToken{
|
||||
Token: &kubeadmapiv1alpha3.BootstrapTokenString{
|
||||
@ -105,7 +106,7 @@ func NewCmdConfigPrintDefault(out io.Writer) *cobra.Command {
|
||||
`), sillyToken),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(apiObjects) == 0 {
|
||||
apiObjects = availableAPIObjects
|
||||
apiObjects = defaultAPIObjects
|
||||
}
|
||||
allBytes := [][]byte{}
|
||||
for _, apiObject := range apiObjects {
|
||||
@ -125,7 +126,7 @@ func getDefaultAPIObjectBytes(apiObject string) ([]byte, error) {
|
||||
var internalcfg runtime.Object
|
||||
var err error
|
||||
switch apiObject {
|
||||
case constants.InitConfigurationKind:
|
||||
case constants.InitConfigurationKind, constants.MasterConfigurationKind:
|
||||
internalcfg, err = configutil.ConfigFileAndDefaultsToInternalConfig("", &kubeadmapiv1alpha3.InitConfiguration{
|
||||
API: kubeadmapiv1alpha3.API{AdvertiseAddress: "1.2.3.4"},
|
||||
BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{sillyToken},
|
||||
|
@ -289,6 +289,10 @@ const (
|
||||
// InitConfigurationKind is the string kind value for the InitConfiguration struct
|
||||
InitConfigurationKind = "InitConfiguration"
|
||||
|
||||
// MasterConfigurationKind is the string kind value for the v1alpha2-named MasterConfiguration struct
|
||||
// In v1alpha3 and higher, this struct is now named InitConfiguration
|
||||
MasterConfigurationKind = "MasterConfiguration"
|
||||
|
||||
// NodeConfigurationKind is the string kind value for the InitConfiguration struct
|
||||
NodeConfigurationKind = "NodeConfiguration"
|
||||
|
||||
|
@ -45,7 +45,7 @@ func AnyConfigFileAndDefaultsToInternal(cfgPath string) (runtime.Object, error)
|
||||
}
|
||||
|
||||
// First, check if the gvk list has InitConfiguration and in that case try to unmarshal it
|
||||
if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvks) {
|
||||
if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvks...) {
|
||||
return ConfigFileAndDefaultsToInternalConfig(cfgPath, &kubeadmapiv1alpha3.InitConfiguration{})
|
||||
}
|
||||
if kubeadmutil.GroupVersionKindsHasNodeConfiguration(gvks) {
|
||||
|
@ -163,7 +163,7 @@ func BytesToInternalConfig(b []byte) (*kubeadmapi.InitConfiguration, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if gvk.Kind == kubeadmconstants.InitConfigurationKind {
|
||||
if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvk) {
|
||||
if err := runtime.DecodeInto(kubeadmscheme.Codecs.UniversalDecoder(), fileContent, internalcfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ etcd:
|
||||
dataDir: /var/lib/etcd
|
||||
image: ""
|
||||
imageRepository: k8s.gcr.io
|
||||
kind: MasterConfiguration
|
||||
kind: InitConfiguration
|
||||
kubernetesVersion: v1.10.2
|
||||
networking:
|
||||
dnsDomain: cluster.local
|
||||
|
@ -22,7 +22,7 @@ etcd:
|
||||
dataDir: /var/lib/etcd
|
||||
image: ""
|
||||
imageRepository: my-company.com
|
||||
kind: MasterConfiguration
|
||||
kind: InitConfiguration
|
||||
kubernetesVersion: v1.10.2
|
||||
networking:
|
||||
dnsDomain: cluster.global
|
||||
|
@ -148,8 +148,10 @@ func GroupVersionKindsHasKind(gvks []schema.GroupVersionKind, kind string) bool
|
||||
}
|
||||
|
||||
// GroupVersionKindsHasInitConfiguration returns whether the following gvk slice contains a InitConfiguration object
|
||||
func GroupVersionKindsHasInitConfiguration(gvks []schema.GroupVersionKind) bool {
|
||||
return GroupVersionKindsHasKind(gvks, constants.InitConfigurationKind)
|
||||
func GroupVersionKindsHasInitConfiguration(gvks ...schema.GroupVersionKind) bool {
|
||||
// Finding a MasterConfiguration kind is also okay, as it will decode and convert into an InitConfiguration struct eventually
|
||||
// TODO: When we remove support for the v1alpha2 API, remove support for MasterConfiguration
|
||||
return GroupVersionKindsHasKind(gvks, constants.InitConfigurationKind) || GroupVersionKindsHasKind(gvks, constants.MasterConfigurationKind)
|
||||
}
|
||||
|
||||
// GroupVersionKindsHasNodeConfiguration returns whether the following gvk slice contains a NodeConfiguration object
|
||||
|
@ -366,7 +366,7 @@ func TestGroupVersionKindsHasInitConfiguration(t *testing.T) {
|
||||
for _, rt := range tests {
|
||||
t.Run(rt.name, func(t2 *testing.T) {
|
||||
|
||||
actual := GroupVersionKindsHasInitConfiguration(rt.gvks)
|
||||
actual := GroupVersionKindsHasInitConfiguration(rt.gvks...)
|
||||
if rt.expected != actual {
|
||||
t2.Errorf("expected gvks has InitConfiguration: %t\n\tactual: %t\n", rt.expected, actual)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user