proxy_addon_test.go 3.1 KB

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