sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/controllers/kubeadmconfig_controller_reconciler_test.go (about) 1 /* 2 Copyright 2019 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 controllers 18 19 import ( 20 "context" 21 22 . "github.com/onsi/ginkgo" 23 . "github.com/onsi/gomega" 24 "k8s.io/apimachinery/pkg/types" 25 ctrl "sigs.k8s.io/controller-runtime" 26 "sigs.k8s.io/controller-runtime/pkg/client" 27 "sigs.k8s.io/controller-runtime/pkg/runtime/log" 28 29 bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha2" 30 ) 31 32 var _ = Describe("KubeadmConfigReconciler", func() { 33 BeforeEach(func() {}) 34 AfterEach(func() {}) 35 36 Context("Reconcile a KubeadmConfig", func() { 37 It("should wait until infrastructure is ready", func() { 38 cluster := newCluster("cluster1") 39 Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed()) 40 41 machine := newMachine(cluster, "my-machine") 42 Expect(k8sClient.Create(context.Background(), machine)).To(Succeed()) 43 44 config := newKubeadmConfig(machine, "my-machine-config") 45 Expect(k8sClient.Create(context.Background(), config)).To(Succeed()) 46 47 reconciler := KubeadmConfigReconciler{ 48 Log: log.Log, 49 Client: k8sClient, 50 } 51 By("Calling reconcile should requeue") 52 result, err := reconciler.Reconcile(ctrl.Request{ 53 NamespacedName: types.NamespacedName{ 54 Namespace: "default", 55 Name: "my-machine-config", 56 }, 57 }) 58 Expect(err).To(Succeed()) 59 Expect(result.Requeue).To(BeFalse()) 60 }) 61 }) 62 }) 63 64 // getKubeadmConfig returns a KubeadmConfig object from the cluster 65 func getKubeadmConfig(c client.Client, name string) (*bootstrapv1.KubeadmConfig, error) { 66 ctx := context.Background() 67 controlplaneConfigKey := client.ObjectKey{ 68 Namespace: "default", 69 Name: name, 70 } 71 config := &bootstrapv1.KubeadmConfig{} 72 err := c.Get(ctx, controlplaneConfigKey, config) 73 return config, err 74 }