controller_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2018 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 kubeletconfig
  14. import (
  15. "testing"
  16. apiv1 "k8s.io/api/core/v1"
  17. "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/checkpoint"
  18. "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/checkpoint/store"
  19. "k8s.io/kubernetes/pkg/kubelet/kubeletconfig/status"
  20. )
  21. func TestGraduateAssignedToLastKnownGood(t *testing.T) {
  22. realSource1, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{
  23. ConfigMap: &apiv1.ConfigMapNodeConfigSource{
  24. Namespace: "foo",
  25. Name: "1",
  26. KubeletConfigKey: "kubelet",
  27. },
  28. })
  29. if err != nil {
  30. t.Fatalf("unexpected error: %v", err)
  31. }
  32. realSource2, _, err := checkpoint.NewRemoteConfigSource(&apiv1.NodeConfigSource{
  33. ConfigMap: &apiv1.ConfigMapNodeConfigSource{
  34. Namespace: "foo",
  35. Name: "2",
  36. KubeletConfigKey: "kubelet",
  37. },
  38. })
  39. if err != nil {
  40. t.Fatalf("unexpected error: %v", err)
  41. }
  42. cases := []struct {
  43. name string
  44. assigned checkpoint.RemoteConfigSource
  45. lkg checkpoint.RemoteConfigSource
  46. }{
  47. {
  48. name: "nil lkg to non-nil lkg",
  49. assigned: realSource1,
  50. lkg: nil,
  51. },
  52. {
  53. name: "non-nil lkg to non-nil lkg",
  54. assigned: realSource2,
  55. lkg: realSource1,
  56. },
  57. }
  58. for _, tc := range cases {
  59. t.Run(tc.name, func(t *testing.T) {
  60. controller := &Controller{
  61. configStatus: status.NewNodeConfigStatus(),
  62. checkpointStore: store.NewFakeStore(),
  63. }
  64. controller.checkpointStore.SetLastKnownGood(tc.lkg)
  65. controller.checkpointStore.SetAssigned(tc.assigned)
  66. if err := controller.graduateAssignedToLastKnownGood(); err != nil {
  67. t.Fatalf("unexpected error: %v", err)
  68. }
  69. })
  70. }
  71. }