config_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package kubelet
  14. import (
  15. "testing"
  16. "k8s.io/api/core/v1"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. "k8s.io/apimachinery/pkg/runtime"
  19. "k8s.io/apimachinery/pkg/util/version"
  20. "k8s.io/client-go/kubernetes/fake"
  21. core "k8s.io/client-go/testing"
  22. "k8s.io/kubernetes/cmd/kubeadm/app/constants"
  23. kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
  24. )
  25. func TestCreateConfigMap(t *testing.T) {
  26. nodeName := "fake-node"
  27. client := fake.NewSimpleClientset()
  28. k8sVersionStr := constants.CurrentKubernetesVersion.String()
  29. cfg := &kubeletconfig.KubeletConfiguration{}
  30. client.PrependReactor("get", "nodes", func(action core.Action) (bool, runtime.Object, error) {
  31. return true, &v1.Node{
  32. ObjectMeta: metav1.ObjectMeta{
  33. Name: nodeName,
  34. },
  35. Spec: v1.NodeSpec{},
  36. }, nil
  37. })
  38. client.PrependReactor("create", "roles", func(action core.Action) (bool, runtime.Object, error) {
  39. return true, nil, nil
  40. })
  41. client.PrependReactor("create", "rolebindings", func(action core.Action) (bool, runtime.Object, error) {
  42. return true, nil, nil
  43. })
  44. client.PrependReactor("create", "configmaps", func(action core.Action) (bool, runtime.Object, error) {
  45. return true, nil, nil
  46. })
  47. if err := CreateConfigMap(cfg, k8sVersionStr, client); err != nil {
  48. t.Errorf("CreateConfigMap: unexpected error %v", err)
  49. }
  50. }
  51. func TestCreateConfigMapRBACRules(t *testing.T) {
  52. client := fake.NewSimpleClientset()
  53. client.PrependReactor("create", "roles", func(action core.Action) (bool, runtime.Object, error) {
  54. return true, nil, nil
  55. })
  56. client.PrependReactor("create", "rolebindings", func(action core.Action) (bool, runtime.Object, error) {
  57. return true, nil, nil
  58. })
  59. if err := createConfigMapRBACRules(client, version.MustParseSemantic("v1.11.0")); err != nil {
  60. t.Errorf("createConfigMapRBACRules: unexpected error %v", err)
  61. }
  62. }