Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit cc2b1e4

Browse files
authored
Merge pull request #209 from chuckha/test-cleanup
🏃Document tests with minor clean ups
2 parents 1390a83 + 5f234d2 commit cc2b1e4

File tree

3 files changed

+114
-157
lines changed

3 files changed

+114
-157
lines changed

controllers/kubeadmconfig_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (r *KubeadmConfigReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
9090
ctx := context.Background()
9191
log := r.Log.WithValues("kubeadmconfig", req.NamespacedName)
9292

93+
// Lookup the kubeadm config
9394
config := &bootstrapv1.KubeadmConfig{}
9495
if err := r.Get(ctx, req.NamespacedName, config); err != nil {
9596
if apierrors.IsNotFound(err) {
@@ -105,6 +106,7 @@ func (r *KubeadmConfigReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
105106
return ctrl.Result{}, nil
106107
}
107108

109+
// Look up the Machine that owns this KubeConfig if there is one
108110
machine, err := util.GetOwnerMachine(ctx, r.Client, config.ObjectMeta)
109111
if err != nil {
110112
log.Error(err, "could not get owner machine")
@@ -118,15 +120,18 @@ func (r *KubeadmConfigReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
118120

119121
// Ignore machines that already have bootstrap data
120122
if machine.Spec.Bootstrap.Data != nil {
123+
// TODO: mark the config as ready?
121124
return ctrl.Result{}, nil
122125
}
123126

127+
// Lookup the cluster the machine is associated with
124128
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, machine.ObjectMeta)
125129
if err != nil {
126130
log.Error(err, "could not get cluster by machine metadata")
127131
return ctrl.Result{}, err
128132
}
129133

134+
// Wait patiently for the infrastructure to be ready
130135
if !cluster.Status.InfrastructureReady {
131136
log.Info("Infrastructure is not ready, waiting until ready.")
132137
return ctrl.Result{}, nil

controllers/kubeadmconfig_controller_reconciler_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -58,74 +58,9 @@ var _ = Describe("KubeadmConfigReconciler", func() {
5858
Expect(err).To(Succeed())
5959
Expect(result.Requeue).To(BeFalse())
6060
})
61-
/*
62-
When apimachinery decodes into a typed struct, the decoder strips the TypeMeta from the object;
63-
the theory at the time being that because it was a typed object, you knew its API version, group, and kind.
64-
if fact this leads to errors with k8sClient, because it loses GVK, and this leads r.Status().Patch to fail
65-
with "the server could not find the requested resource (patch kubeadmconfigs.bootstrap.cluster.x-k8s.io control-plane-config)"
66-
67-
There's a WIP PR to k/k to fix this.
68-
After this merge, we can implement more behavioral test
69-
70-
It("should process only control plane machines when infrastructure is ready but control plane is not", func() {
71-
cluster := newCluster("cluster2")
72-
Expect(k8sClient.Create(context.Background(), cluster)).To(Succeed())
73-
cluster.Status.InfrastructureReady = true
74-
Expect(k8sClient.Status().Update(context.Background(), cluster)).To(Succeed())
75-
76-
controlplaneMachine := newMachine(cluster, "control-plane")
77-
controlplaneMachine.ObjectMeta.Labels[clusterv1alpha2.MachineControlPlaneLabelName] = "true"
78-
Expect(k8sClient.Create(context.Background(), controlplaneMachine)).To(Succeed())
79-
80-
controlplaneConfig := newKubeadmConfig(controlplaneMachine, "control-plane-config")
81-
controlplaneConfig.Spec.ClusterConfiguration = &kubeadmv1beta1.ClusterConfiguration{}
82-
controlplaneConfig.Spec.InitConfiguration = &kubeadmv1beta1.InitConfiguration{}
83-
Expect(k8sClient.Create(context.Background(), controlplaneConfig)).To(Succeed())
84-
85-
workerMachine := newMachine(cluster, "worker")
86-
Expect(k8sClient.Create(context.Background(), workerMachine)).To(Succeed())
87-
88-
workerConfig := newKubeadmConfig(workerMachine, "worker-config")
89-
Expect(k8sClient.Create(context.Background(), workerConfig)).To(Succeed())
90-
91-
reconciler := KubeadmConfigReconciler{
92-
Log: log.Log,
93-
Client: k8sClient,
94-
}
95-
96-
By("Calling reconcile on a config corresponding to worker node should requeue")
97-
resultWorker, err := reconciler.Reconcile(ctrl.Request{
98-
NamespacedName: types.NamespacedName{
99-
Namespace: "default",
100-
Name: "worker-config",
101-
},
102-
})
103-
Expect(err).To(Succeed())
104-
Expect(resultWorker.Requeue).To(BeFalse())
105-
Expect(resultWorker.RequeueAfter).To(Equal(30 * time.Second))
106-
107-
By("Calling reconcile on a config corresponding to a control plane node should create BootstrapData")
108-
resultControlPlane, err := reconciler.Reconcile(ctrl.Request{
109-
NamespacedName: types.NamespacedName{
110-
Namespace: "default",
111-
Name: "control-plane-config",
112-
},
113-
})
114-
Expect(err).To(Succeed())
115-
Expect(resultControlPlane.Requeue).To(BeFalse())
116-
Expect(resultControlPlane.RequeueAfter).To(BeZero())
117-
118-
controlplaneConfigAfter, err := getKubeadmConfig(k8sClient, "control-plane-config")
119-
Expect(err).To(Succeed())
120-
Expect(controlplaneConfigAfter.Status.Ready).To(BeTrue())
121-
Expect(controlplaneConfigAfter.Status.BootstrapData).NotTo(BeEmpty())
122-
})
123-
*/
12461
})
12562
})
12663

127-
// test utils
128-
12964
// getKubeadmConfig returns a KubeadmConfig object from the cluster
13065
func getKubeadmConfig(c client.Client, name string) (*bootstrapv1.KubeadmConfig, error) {
13166
ctx := context.Background()

0 commit comments

Comments
 (0)