|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2e_kubeadm |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + rbacv1 "k8s.io/api/rbac/v1" |
| 22 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 | + "k8s.io/apimachinery/pkg/labels" |
| 24 | + "k8s.io/client-go/kubernetes" |
| 25 | + "k8s.io/client-go/rest" |
| 26 | + bootstrapapi "k8s.io/client-go/tools/bootstrap/token/api" |
| 27 | + "k8s.io/kubernetes/test/e2e/framework" |
| 28 | + |
| 29 | + . "github.com/onsi/ginkgo" |
| 30 | + . "github.com/onsi/gomega" |
| 31 | +) |
| 32 | + |
| 33 | +const ( |
| 34 | + masterTaint = "node-role.kubernetes.io/master" |
| 35 | + kubeadmConfigNamespace = "kube-system" |
| 36 | + kubeadmConfigName = "kubeadm-config" |
| 37 | + clusterInfoNamespace = "kube-public" |
| 38 | + clusterInfoName = "cluster-info" |
| 39 | + bootstrapSignerRoleNamespace = "kube-system" |
| 40 | + bootstrapSignerRoleName = "system:controller:bootstrap-signer" |
| 41 | +) |
| 42 | + |
| 43 | +var _ = framework.KubeDescribe("Kubeadm [Feature:Kubeadm]", func() { |
| 44 | + f := framework.NewDefaultFramework("kubeadm") |
| 45 | + |
| 46 | + Describe("kubeadm master", func() { |
| 47 | + It("should be labelled and tainted", func() { |
| 48 | + selector := labels.Set{masterTaint: ""}.AsSelector() |
| 49 | + master, err := f.ClientSet.CoreV1().Nodes(). |
| 50 | + List(metav1.ListOptions{LabelSelector: selector.String()}) |
| 51 | + framework.ExpectNoError(err, "couldn't find a master node") |
| 52 | + Expect(master.Items).NotTo(BeEmpty()) |
| 53 | + for _, master := range master.Items { |
| 54 | + Expect(master.Spec.Taints).To( |
| 55 | + ContainElement(taint(masterTaint, corev1.TaintEffectNoSchedule)), |
| 56 | + ) |
| 57 | + } |
| 58 | + }) |
| 59 | + }) |
| 60 | + |
| 61 | + Describe("kubeadm-config config map", func() { |
| 62 | + It("should exist", func() { |
| 63 | + _, err := f.ClientSet.CoreV1(). |
| 64 | + ConfigMaps(kubeadmConfigNamespace). |
| 65 | + Get(kubeadmConfigName, metav1.GetOptions{}) |
| 66 | + framework.ExpectNoError(err) |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + Describe("cluster-info", func() { |
| 71 | + It("should have expected keys", func() { |
| 72 | + clientInfo, err := f.ClientSet.CoreV1(). |
| 73 | + ConfigMaps(clusterInfoNamespace). |
| 74 | + Get(clusterInfoName, metav1.GetOptions{}) |
| 75 | + framework.ExpectNoError(err, "couldn't find config map") |
| 76 | + |
| 77 | + Expect(clientInfo.Data).To(HaveKey(HavePrefix(bootstrapapi.JWSSignatureKeyPrefix))) |
| 78 | + Expect(clientInfo.Data).To(HaveKey(bootstrapapi.KubeConfigKey)) |
| 79 | + }) |
| 80 | + |
| 81 | + It("should be public", func() { |
| 82 | + cfg, err := framework.LoadConfig() |
| 83 | + framework.ExpectNoError(err, "couldn't get config") |
| 84 | + cfg = rest.AnonymousClientConfig(cfg) |
| 85 | + client, err := kubernetes.NewForConfig(cfg) |
| 86 | + framework.ExpectNoError(err, "couldn't create client") |
| 87 | + |
| 88 | + _, err = client.CoreV1().ConfigMaps(clusterInfoNamespace). |
| 89 | + Get(clusterInfoName, metav1.GetOptions{}) |
| 90 | + framework.ExpectNoError(err, "couldn't anonymously access config") |
| 91 | + }) |
| 92 | + }) |
| 93 | + |
| 94 | + Describe("bootstrap signer RBAC role", func() { |
| 95 | + It("should exist", func() { |
| 96 | + _, err := f.ClientSet.RbacV1(). |
| 97 | + Roles(bootstrapSignerRoleNamespace). |
| 98 | + Get(bootstrapSignerRoleName, metav1.GetOptions{}) |
| 99 | + framework.ExpectNoError(err, "doesn't exist") |
| 100 | + }) |
| 101 | + }) |
| 102 | + |
| 103 | + Describe("kubeadm:kubelet-bootstrap cluster role binding", func() { |
| 104 | + It("should exist", func() { |
| 105 | + binding, err := f.ClientSet.RbacV1(). |
| 106 | + ClusterRoleBindings(). |
| 107 | + Get("kubeadm:kubelet-bootstrap", metav1.GetOptions{}) |
| 108 | + framework.ExpectNoError(err, "couldn't get clusterrolebinding") |
| 109 | + Expect(binding.Subjects).To( |
| 110 | + ContainElement(subject( |
| 111 | + "system:bootstrappers:kubeadm:default-node-token", |
| 112 | + rbacv1.GroupKind, |
| 113 | + )), |
| 114 | + ) |
| 115 | + Expect(binding.RoleRef.Name).To(Equal("system:node-bootstrapper")) |
| 116 | + }) |
| 117 | + }) |
| 118 | + |
| 119 | + Describe("autoapproval for new bootstrap token", func() { |
| 120 | + It("should create a clusterrolebinding", func() { |
| 121 | + binding, err := f.ClientSet.RbacV1(). |
| 122 | + ClusterRoleBindings(). |
| 123 | + Get("kubeadm:node-autoapprove-bootstrap", metav1.GetOptions{}) |
| 124 | + framework.ExpectNoError(err, "couldn't get clusterrolebinding") |
| 125 | + Expect(binding.Subjects).To( |
| 126 | + ContainElement(subject( |
| 127 | + "system:bootstrappers:kubeadm:default-node-token", |
| 128 | + rbacv1.GroupKind, |
| 129 | + )), |
| 130 | + ) |
| 131 | + Expect(binding.RoleRef.Name).To( |
| 132 | + Equal("system:certificates.k8s.io:certificatesigningrequests:nodeclient"), |
| 133 | + ) |
| 134 | + }) |
| 135 | + }) |
| 136 | +}) |
0 commit comments