proxy_addon_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. Copyright 2019 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 kubeadm
  14. import (
  15. authv1 "k8s.io/api/authorization/v1"
  16. rbacv1 "k8s.io/api/rbac/v1"
  17. "k8s.io/kubernetes/test/e2e/framework"
  18. "github.com/onsi/ginkgo"
  19. "github.com/onsi/gomega"
  20. )
  21. const (
  22. kubeProxyServiceAccountName = "kube-proxy"
  23. kubeProxyConfigMap = "kube-proxy"
  24. kubeProxyConfigMapKey = "config.conf"
  25. kubeProxyConfigMapKeyKubeconfig = "kubeconfig.conf"
  26. kubeProxyClusterRoleName = "system:node-proxier"
  27. kubeProxyClusterRoleBindingName = "kubeadm:node-proxier"
  28. kubeProxyRoleName = "kube-proxy"
  29. kubeProxyRoleBindingName = kubeProxyRoleName
  30. kubeProxyDaemonSetName = "kube-proxy"
  31. )
  32. var (
  33. kubeProxyConfigMapResource = &authv1.ResourceAttributes{
  34. Namespace: kubeSystemNamespace,
  35. Name: kubeProxyConfigMap,
  36. Resource: "configmaps",
  37. Verb: "get",
  38. }
  39. )
  40. // Define container for all the test specification aimed at verifying
  41. // that kubeadm configures the proxy addon as expected
  42. var _ = Describe("proxy addon", func() {
  43. // Get an instance of the k8s test framework
  44. f := framework.NewDefaultFramework("proxy")
  45. // Tests in this container are not expected to create new objects in the cluster
  46. // so we are disabling the creation of a namespace in order to get a faster execution
  47. f.SkipNamespaceCreation = true
  48. ginkgo.Context("kube-proxy ServiceAccount", func() {
  49. ginkgo.It("should exist", func() {
  50. ExpectServiceAccount(f.ClientSet, kubeSystemNamespace, kubeProxyServiceAccountName)
  51. })
  52. ginkgo.It("should be bound to the system:node-proxier cluster role", func() {
  53. ExpectClusterRoleBindingWithSubjectAndRole(f.ClientSet,
  54. kubeProxyClusterRoleBindingName,
  55. rbacv1.ServiceAccountKind, kubeProxyServiceAccountName,
  56. kubeProxyClusterRoleName,
  57. )
  58. })
  59. })
  60. ginkgo.Context("kube-proxy ConfigMap", func() {
  61. ginkgo.It("should exist and be properly configured", func() {
  62. cm := GetConfigMap(f.ClientSet, kubeSystemNamespace, kubeProxyConfigMap)
  63. gomega.Expect(cm.Data).To(gomega.HaveKey(kubeProxyConfigMapKey))
  64. gomega.Expect(cm.Data).To(gomega.HaveKey(kubeProxyConfigMapKeyKubeconfig))
  65. })
  66. ginkgo.It("should have related Role and RoleBinding", func() {
  67. ExpectRole(f.ClientSet, kubeSystemNamespace, kubeProxyRoleName)
  68. ExpectRoleBinding(f.ClientSet, kubeSystemNamespace, kubeProxyRoleBindingName)
  69. })
  70. ginkgo.It("should be accessible by bootstrap tokens", func() {
  71. ExpectSubjectHasAccessToResource(f.ClientSet,
  72. rbacv1.GroupKind, bootstrapTokensGroup,
  73. kubeProxyConfigMapResource,
  74. )
  75. })
  76. })
  77. ginkgo.Context("kube-proxy DaemonSet", func() {
  78. ginkgo.It("should exist and be properly configured", func() {
  79. ds := GetDaemonSet(f.ClientSet, kubeSystemNamespace, kubeProxyDaemonSetName)
  80. framework.ExpectEqual(ds.Spec.Template.Spec.ServiceAccountName, kubeProxyServiceAccountName)
  81. })
  82. })
  83. })