Skip to content

Commit

Permalink
Write e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsinrahman committed Sep 4, 2019
1 parent a7a3f7b commit ef8510f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions controllers/machinedeployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,61 @@ var _ = Describe("MachineDeployment Reconciler", func() {
return len(machineSets.Items)
}, timeout*3).Should(BeEquivalentTo(1))

//
// Update a MachineDeployment spec.Selector.Matchlabels spec.Template.Labels
// expect Reconcile to be called and a new MachineSet to appear
// expect old MachineSets with old labels to be deleted
//
oldLabels := deployment.Spec.Selector.MatchLabels
newLabels := map[string]string{
"new-key": "new-value",
}

err = updateMachineDeployment(k8sClient, deployment, func(d *clusterv1.MachineDeployment) {
d.Spec.Selector.MatchLabels = newLabels
d.Spec.Template.Labels = newLabels
})
Expect(err).ToNot(HaveOccurred())

// verify new MachineSet with updated labels are created
Eventually(func() int {
listOpts := client.MatchingLabels(newLabels)
if err := k8sClient.List(ctx, machineSets, listOpts); err != nil {
return -1
}
return len(machineSets.Items)
}, timeout).Should(BeEquivalentTo(1))

// verify new MachineSet have desired number of available replicas
Eventually(func() bool {
// Set the all non-deleted machines as ready with a NodeRef, so the MachineSet controller can proceed
// to properly set AvailableReplicas.
machines := &clusterv1.MachineList{}
Expect(k8sClient.List(ctx, machines, client.InNamespace(namespace.Name))).NotTo(HaveOccurred())
for _, m := range machines.Items {
if !m.DeletionTimestamp.IsZero() {
continue
}
fakeInfrastructureRefReady(m.Spec.InfrastructureRef, infraResource)
fakeMachineNodeRef(&m)
}

listOpts := client.MatchingLabels(newLabels)
if err := k8sClient.List(ctx, machineSets, listOpts); err != nil {
return false
}
return machineSets.Items[0].Status.Replicas == *deployment.Spec.Replicas
}, timeout*5).Should(BeTrue())

// verify old MachineSets with old labels are deleted
Eventually(func() int {
listOpts := client.MatchingLabels(oldLabels)
if err := k8sClient.List(ctx, machineSets, listOpts); err != nil {
return -1
}

return len(machineSets.Items)
}, timeout*5).Should(BeEquivalentTo(0))
})
})

Expand Down

0 comments on commit ef8510f

Please sign in to comment.