Skip to content

Commit

Permalink
Add WaitingForPlacementGroupPolicySatisfied and WaitingForELFClusterW…
Browse files Browse the repository at this point in the history
…ithSufficientMemory reasons
  • Loading branch information
haijianyang committed Oct 17, 2023
1 parent f855a41 commit 035a44d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/v1beta1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions controllers/tower_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import (
"sync"
"time"

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"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
)

const (
Expand Down Expand Up @@ -50,6 +53,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
}

Expand All @@ -59,6 +64,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
}

Expand Down
6 changes: 6 additions & 0 deletions controllers/tower_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -146,19 +149,22 @@ 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)
ok, msg, err = isELFScheduleVMErrorRecorded(machineContext)
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}})
})
})

Expand Down

0 comments on commit 035a44d

Please sign in to comment.