Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
Signed-off-by: Aniruddha Basak <aniruddha.basak@syself.com>
  • Loading branch information
aniruddha2000 committed Oct 13, 2023
1 parent eb36373 commit 1da6ca7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
18 changes: 2 additions & 16 deletions controllers/hcloudremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,6 @@ var _ = Describe("HCloudRemediationReconciler", func() {
}, timeout).Should(BeNil())
})

It("checks if hcloudRemediation objects has the HCloudTokenAvailableCondition condition", func() {
Expect(testEnv.Create(ctx, hcloudRemediation)).To(Succeed())

Eventually(func() bool {
if err := testEnv.Get(ctx, hcloudRemediationkey, hcloudRemediation); err != nil {
return false
}

testEnv.GetLogger().Info("Status condition of the hcloud remediation", "condition", hcloudRemediation.Status.Conditions)
return isPresentAndTrue(hcloudRemediationkey, hcloudRemediation, infrav1.HCloudTokenAvailableCondition)
}, timeout).Should(BeTrue())
})

It("checks that no remediation is tried if HCloud server does not exist anymore", func() {
By("ensuring if hcloudMachine is provisioned")
Eventually(func() bool {
Expand Down Expand Up @@ -263,7 +250,7 @@ var _ = Describe("HCloudRemediationReconciler", func() {
}, timeout).Should(BeTrue())
})

It("should delete machine if remediation is unhealthy", func() {
It("should delete machine if retry limit reached and reboot timed out", func() {
By("creating hcloudRemediation")
Expect(testEnv.Create(ctx, hcloudRemediation)).To(Succeed())

Expand All @@ -274,8 +261,7 @@ var _ = Describe("HCloudRemediationReconciler", func() {
hcloudRemediation.Status.Phase = infrav1.PhaseWaiting
hcloudRemediation.Status.LastRemediated = &metav1.Time{Time: time.Now().Add(-2 * time.Second)}

err = hcloudRemediationPatchHelper.Patch(ctx, hcloudRemediation)
Expect(err).NotTo(HaveOccurred())
Expect(hcloudRemediationPatchHelper.Patch(ctx, hcloudRemediation)).NotTo(HaveOccurred())

By("checking if hcloudRemediation is in deleting phase and capiMachine has MachineOwnerRemediatedCondition")
Eventually(func() bool {
Expand Down
26 changes: 13 additions & 13 deletions controllers/hetznerbaremetalremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package controllers

import (
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -271,7 +272,7 @@ var _ = Describe("HetznerBareMetalRemediationReconciler", func() {
}, timeout).Should(BeTrue())
})

It("should not remediate if no HetznerBareMetalHost is present", func() {
It("should not remediate if HetznerBareMetalHost does not exist anymore", func() {
hetznerBaremetalMachine.Annotations = map[string]string{
infrav1.HostAnnotation: fmt.Sprintf("%s/%s", testNs.Name, hostName),
}
Expand Down Expand Up @@ -344,22 +345,22 @@ var _ = Describe("HetznerBareMetalRemediationReconciler", func() {
return false
}

testEnv.GetLogger().Info("host annotations", "hostAnnotation", host.Annotations)
return hetznerBareMetalRemediation.Status.LastRemediated != nil && hetznerBareMetalRemediation.Status.RetryCount == 1 && host.Annotations != nil
}, timeout).Should(BeTrue())
})
rebootAnnotationArguments := infrav1.RebootAnnotationArguments{Type: infrav1.RebootTypeHardware}

It("should delete machine if remediation is unhealthy", func() {
By("ensuring host is provisioned")
Eventually(func() bool {
if err := testEnv.Get(ctx, hostKey, host); err != nil {
b, err := json.Marshal(rebootAnnotationArguments)
Expect(err).NotTo(HaveOccurred())

val, ok := host.Annotations[infrav1.RebootAnnotation]
if !ok {
return false
}

testEnv.GetLogger().Info("Provisioning state of host", "state", host.Spec.Status.ProvisioningState, "conditions", host.Spec.Status.Conditions)
return host.Spec.Status.ProvisioningState == infrav1.StateProvisioned
testEnv.GetLogger().Info("host annotations", "hostAnnotation", host.Annotations)
return hetznerBareMetalRemediation.Status.LastRemediated != nil && hetznerBareMetalRemediation.Status.RetryCount == 1 && val == string(b)
}, timeout).Should(BeTrue())
})

It("should delete machine if retry limit reached and reboot timed out", func() {
By("creating hetznerBareMetalRemediation object")
Expect(testEnv.Create(ctx, hetznerBareMetalRemediation)).To(Succeed())

Expand All @@ -370,8 +371,7 @@ var _ = Describe("HetznerBareMetalRemediationReconciler", func() {
hetznerBareMetalRemediation.Status.Phase = infrav1.PhaseWaiting
hetznerBareMetalRemediation.Status.LastRemediated = &metav1.Time{Time: time.Now().Add(-2 * time.Second)}

err = hetznerBaremetalRemediationPatchHelper.Patch(ctx, hetznerBareMetalRemediation)
Expect(err).NotTo(HaveOccurred())
Expect(hetznerBaremetalRemediationPatchHelper.Patch(ctx, hetznerBareMetalRemediation)).NotTo(HaveOccurred())

By("checking if hcloudRemediation is in deleting phase and capiMachine has MachineOwnerRemediatedCondition")
Eventually(func() bool {
Expand Down

0 comments on commit 1da6ca7

Please sign in to comment.