
kubeadm's current implementation of component config support is "kind" centric. This has its downsides. Namely: - Kind names and numbers can change between config versions. Newer kinds can be ignored. Therefore, detection of a version change is considerably harder. - A component config can have only one kind that is managed by kubeadm. Thus a more appropriate way to identify component configs is required. Probably the best solution identified so far is a config group. A group name is unlikely to change between versions, while the kind names and structure can. Tracking component configs by group name allows us to: - Spot more easily config version changes and manage alternate versions. - Support more than one kind in a config group/version. - Abstract component configs by hiding their exact structure. Hence, this change rips off the old kind based support for component configs and replaces it with a group name based one. This also has the following extra benefits: - More tests were added. - kubeadm now errors out if an unsupported version of a known component group is used. Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
80 lines
2.7 KiB
Go
80 lines
2.7 KiB
Go
/*
|
|
Copyright 2017 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 kubelet
|
|
|
|
import (
|
|
"testing"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/util/version"
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
core "k8s.io/client-go/testing"
|
|
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
|
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
|
)
|
|
|
|
func TestCreateConfigMap(t *testing.T) {
|
|
nodeName := "fake-node"
|
|
client := fake.NewSimpleClientset()
|
|
client.PrependReactor("get", "nodes", func(action core.Action) (bool, runtime.Object, error) {
|
|
return true, &v1.Node{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: nodeName,
|
|
},
|
|
Spec: v1.NodeSpec{},
|
|
}, nil
|
|
})
|
|
client.PrependReactor("create", "roles", func(action core.Action) (bool, runtime.Object, error) {
|
|
return true, nil, nil
|
|
})
|
|
client.PrependReactor("create", "rolebindings", func(action core.Action) (bool, runtime.Object, error) {
|
|
return true, nil, nil
|
|
})
|
|
client.PrependReactor("create", "configmaps", func(action core.Action) (bool, runtime.Object, error) {
|
|
return true, nil, nil
|
|
})
|
|
|
|
clusterCfg := &kubeadmapiv1beta2.ClusterConfiguration{
|
|
KubernetesVersion: constants.CurrentKubernetesVersion.String(),
|
|
}
|
|
internalcfg, err := configutil.DefaultedInitConfiguration(&kubeadmapiv1beta2.InitConfiguration{}, clusterCfg)
|
|
if err != nil {
|
|
t.Fatalf("unexpected failure by DefaultedInitConfiguration: %v", err)
|
|
}
|
|
|
|
if err := CreateConfigMap(&internalcfg.ClusterConfiguration, client); err != nil {
|
|
t.Errorf("CreateConfigMap: unexpected error %v", err)
|
|
}
|
|
}
|
|
|
|
func TestCreateConfigMapRBACRules(t *testing.T) {
|
|
client := fake.NewSimpleClientset()
|
|
client.PrependReactor("create", "roles", func(action core.Action) (bool, runtime.Object, error) {
|
|
return true, nil, nil
|
|
})
|
|
client.PrependReactor("create", "rolebindings", func(action core.Action) (bool, runtime.Object, error) {
|
|
return true, nil, nil
|
|
})
|
|
|
|
if err := createConfigMapRBACRules(client, version.MustParseSemantic("v1.11.0")); err != nil {
|
|
t.Errorf("createConfigMapRBACRules: unexpected error %v", err)
|
|
}
|
|
}
|