Skip to content

Commit

Permalink
OCPBUGS-7076: Copy Day2 BMH if Agent is installing
Browse files Browse the repository at this point in the history
https://issues.redhat.com/browse/OCPBUGS-7076
Previously the BMAC would copy the BMH and Machine
CRs of a Day2 worker to the spoke cluster before
the Agent began installing. If the Agent doesn't
start installing within the two hours these CRs
were copied over, the CSRs for these nodes will
not be approved by the machine approver pod.

To prevent this from happening, only copy
the BMH and Machine CRs to the spoke cluster
when the Agent has started installing.
  • Loading branch information
CrystalChun committed May 27, 2023
1 parent 43219b9 commit 8ae647f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/controller/controllers/bmh_agent_controller.go
Expand Up @@ -976,6 +976,12 @@ func (r *BMACReconciler) reconcileSpokeBMH(ctx context.Context, log logrus.Field
return reconcileComplete{}
}

if !funk.ContainsString([]string{models.HostStatusInstalling, models.HostStatusInstallingInProgress}, agent.Status.DebugInfo.State) {
// If agent hasn't started installing, do not create the spoke BMH yet
log.Debugf("Agent has not started installing, not creating the spoke BMH for %s on cluster %s", bmh.Name, agent.Spec.ClusterDeploymentName.Name)
return reconcileComplete{stop: false}
}

secret, err := getSecret(ctx, r.Client, r.APIReader, key)
if err != nil {
return reconcileError{err: err}
Expand Down
41 changes: 40 additions & 1 deletion internal/controller/controllers/bmh_agent_controller_test.go
Expand Up @@ -1068,7 +1068,7 @@ var _ = Describe("bmac reconcile", func() {
})

Context("when agent role worker and cluster deployment is set", func() {
It("should set spoke BMH", func() {
It("should set spoke BMH when agent is not installing", func() {
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "root-ca",
Expand All @@ -1085,6 +1085,45 @@ var _ = Describe("bmac reconcile", func() {
Expect(result).To(Equal(ctrl.Result{}))
}

updatedHost := &bmh_v1alpha1.BareMetalHost{}
err := c.Get(ctx, types.NamespacedName{Name: host.Name, Namespace: testNamespace}, updatedHost)
Expect(err).To(BeNil())
Expect(updatedHost.ObjectMeta.Annotations).To(HaveKey(BMH_HARDWARE_DETAILS_ANNOTATION))
Expect(updatedHost.ObjectMeta.Annotations).NotTo(HaveKey(BMH_DETACHED_ANNOTATION))
Expect(updatedHost.ObjectMeta.Annotations).To(HaveKey(BMH_AGENT_IGNITION_CONFIG_OVERRIDES))
Expect(updatedHost.ObjectMeta.Annotations[BMH_AGENT_IGNITION_CONFIG_OVERRIDES]).NotTo(Equal(""))
Expect(updatedHost.ObjectMeta.Annotations[BMH_AGENT_IGNITION_CONFIG_OVERRIDES]).To(ContainSubstring("dGVzdA=="))

machineName := fmt.Sprintf("%s-%s", cluster.Name, host.Name)

spokeBMH := &bmh_v1alpha1.BareMetalHost{}
spokeClient := bmhr.spokeClient
err = spokeClient.Get(ctx, types.NamespacedName{Name: host.Name, Namespace: OPENSHIFT_MACHINE_API_NAMESPACE}, spokeBMH)
Expect(err).NotTo(BeNil())

spokeMachine := &machinev1beta1.Machine{}
err = spokeClient.Get(ctx, types.NamespacedName{Name: machineName, Namespace: OPENSHIFT_MACHINE_API_NAMESPACE}, spokeMachine)
Expect(err).NotTo(BeNil())
})
It("should not set spoke BMH when agent is installing", func() {
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "root-ca",
Namespace: "kube-system",
},
Data: map[string]string{
"ca.crt": BASIC_CERT,
},
}
Expect(bmhr.spokeClient.Create(ctx, configMap)).ShouldNot(HaveOccurred())
agent.Status.DebugInfo.State = models.HostStatusInstallingInProgress
Expect(c.Update(context.Background(), agent)).ShouldNot(HaveOccurred())
for range [3]int{} {
result, err := bmhr.Reconcile(ctx, newBMHRequest(host))
Expect(err).To(BeNil())
Expect(result).To(Equal(ctrl.Result{}))
}

updatedHost := &bmh_v1alpha1.BareMetalHost{}
err := c.Get(ctx, types.NamespacedName{Name: host.Name, Namespace: testNamespace}, updatedHost)
Expect(err).To(BeNil())
Expand Down

0 comments on commit 8ae647f

Please sign in to comment.