diff --git a/api/v1beta1/conditions_consts.go b/api/v1beta1/conditions_consts.go index 29392663..ef75b629 100644 --- a/api/v1beta1/conditions_consts.go +++ b/api/v1beta1/conditions_consts.go @@ -102,6 +102,14 @@ const ( // are automatically re-tried by the controller. JoiningPlacementGroupFailedReason = "JoiningPlacementGroupFailed" + // WaitingForPlacementGroupPolicySatisfiedReason (Severity=Warning) documents an ElfMachine + // waiting for placement group policy be satisfied for VM to joining placement group. + WaitingForPlacementGroupPolicySatisfiedReason = "WaitingForPlacementGroupPolicySatisfied" + + // WaitingForELFClusterWithSufficientMemoryReason (Severity=Info) documents an ElfMachine + // waiting for ELF cluster with sufficient memory to create or power on VM. + WaitingForELFClusterWithSufficientMemoryReason = "WaitingForELFClusterWithSufficientMemory" + // WaitingForAvailableHostRequiredByPlacementGroupReason (Severity=Info) documents an ElfMachine // waiting for an available host required by placement group to create VM. WaitingForAvailableHostRequiredByPlacementGroupReason = "WaitingForAvailableHostRequiredByPlacementGroup" diff --git a/controllers/tower_cache.go b/controllers/tower_cache.go index d832256e..5e4f3eaa 100644 --- a/controllers/tower_cache.go +++ b/controllers/tower_cache.go @@ -21,6 +21,10 @@ import ( "sync" "time" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/util/conditions" + + infrav1 "github.com/smartxworks/cluster-api-provider-elf/api/v1beta1" "github.com/smartxworks/cluster-api-provider-elf/pkg/context" towerresources "github.com/smartxworks/cluster-api-provider-elf/pkg/resources" ) @@ -50,6 +54,8 @@ func isELFScheduleVMErrorRecorded(ctx *context.MachineContext) (bool, string, er defer lock.Unlock() if resource := getClusterResource(getKeyForInsufficientMemoryError(ctx.ElfCluster.Spec.Cluster)); resource != nil { + conditions.MarkFalse(ctx.ElfMachine, infrav1.VMProvisionedCondition, infrav1.WaitingForELFClusterWithSufficientMemoryReason, clusterv1.ConditionSeverityInfo, "") + return true, fmt.Sprintf("Insufficient memory detected for the ELF cluster %s", ctx.ElfCluster.Spec.Cluster), nil } @@ -59,6 +65,8 @@ func isELFScheduleVMErrorRecorded(ctx *context.MachineContext) (bool, string, er } if resource := getClusterResource(getKeyForDuplicatePlacementGroupError(placementGroupName)); resource != nil { + conditions.MarkFalse(ctx.ElfMachine, infrav1.VMProvisionedCondition, infrav1.WaitingForPlacementGroupPolicySatisfiedReason, clusterv1.ConditionSeverityInfo, "") + return true, fmt.Sprintf("Not satisfy policy detected for the placement group %s", placementGroupName), nil } diff --git a/controllers/tower_cache_test.go b/controllers/tower_cache_test.go index a5246c99..d6f8f173 100644 --- a/controllers/tower_cache_test.go +++ b/controllers/tower_cache_test.go @@ -21,7 +21,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + infrav1 "github.com/smartxworks/cluster-api-provider-elf/api/v1beta1" "github.com/smartxworks/cluster-api-provider-elf/pkg/context" towerresources "github.com/smartxworks/cluster-api-provider-elf/pkg/resources" "github.com/smartxworks/cluster-api-provider-elf/test/fake" @@ -146,12 +149,14 @@ var _ = Describe("TowerCache", func() { Expect(ok).To(BeFalse()) Expect(msg).To(Equal("")) Expect(err).ShouldNot(HaveOccurred()) + expectConditions(elfMachine, []conditionAssertion{}) recordIsUnmet(machineContext, clusterKey, true) ok, msg, err = isELFScheduleVMErrorRecorded(machineContext) Expect(ok).To(BeTrue()) Expect(msg).To(ContainSubstring("Insufficient memory detected for the ELF cluster")) Expect(err).ShouldNot(HaveOccurred()) + expectConditions(elfMachine, []conditionAssertion{{infrav1.VMProvisionedCondition, corev1.ConditionFalse, clusterv1.ConditionSeverityInfo, infrav1.WaitingForELFClusterWithSufficientMemoryReason}}) resetVMTaskErrorCache() recordIsUnmet(machineContext, placementGroupKey, true) @@ -159,6 +164,7 @@ var _ = Describe("TowerCache", func() { Expect(ok).To(BeTrue()) Expect(msg).To(ContainSubstring("Not satisfy policy detected for the placement group")) Expect(err).ShouldNot(HaveOccurred()) + expectConditions(elfMachine, []conditionAssertion{{infrav1.VMProvisionedCondition, corev1.ConditionFalse, clusterv1.ConditionSeverityInfo, infrav1.WaitingForPlacementGroupPolicySatisfiedReason}}) }) })