Skip to content

Commit 83bd331

Browse files
committed
Enabling Soft Affinity and Soft Anti Affinity
1 parent 713632c commit 83bd331

12 files changed

+47
-17
lines changed

api/v1beta1/cloudstackaffinitygroup_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
// CloudStackAffinityGroupSpec defines the desired state of CloudStackAffinityGroup
2828
type CloudStackAffinityGroupSpec struct {
2929
// Mutually exclusive parameter with AffinityGroupIDs.
30-
// Can be "host affinity" or "host anti-affinity". Will create an affinity group per machine set.
30+
// Can be "host affinity", "host anti-affinity", "non-strict host affinity"or "non-strict host anti-affinity". Will create an affinity group per machine set.
3131
Type string `json:"type,omitempty"`
3232

3333
// Name.

api/v1beta1/cloudstackmachine_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const (
2828
MachineFinalizer = "cloudstackmachine.infrastructure.cluster.x-k8s.io"
2929
ProAffinity = "pro"
3030
AntiAffinity = "anti"
31+
SoftProAffinity = "soft-pro"
32+
SoftAntiAffinity = "soft-anti"
3133
NoAffinity = "no"
3234
)
3335

api/v1beta2/cloudstackmachine_types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import (
2727
const MachineFinalizer = "cloudstackmachine.infrastructure.cluster.x-k8s.io"
2828

2929
const (
30-
ProAffinity = "pro"
31-
AntiAffinity = "anti"
32-
NoAffinity = "no"
30+
ProAffinity = "pro"
31+
AntiAffinity = "anti"
32+
SoftProAffinity = "soft-pro"
33+
SoftAntiAffinity = "soft-anti"
34+
NoAffinity = "no"
3335
)
3436

3537
// CloudStackMachineSpec defines the desired state of CloudStackMachine

api/v1beta3/cloudstackaffinitygroup_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const AffinityGroupFinalizer = "affinitygroup.infrastructure.cluster.x-k8s.io"
2525
// CloudStackAffinityGroupSpec defines the desired state of CloudStackAffinityGroup
2626
type CloudStackAffinityGroupSpec struct {
2727
// Mutually exclusive parameter with AffinityGroupIDs.
28-
// Can be "host affinity" or "host anti-affinity". Will create an affinity group per machine set.
28+
// Can be "host affinity", "host anti-affinity", "non-strict host affinity" or "non-strict host anti-affinity". Will create an affinity group per machine set.
2929
Type string `json:"type,omitempty"`
3030

3131
// Name.

api/v1beta3/cloudstackmachine_types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import (
2727
const MachineFinalizer = "cloudstackmachine.infrastructure.cluster.x-k8s.io"
2828

2929
const (
30-
ProAffinity = "pro"
31-
AntiAffinity = "anti"
32-
NoAffinity = "no"
30+
ProAffinity = "pro"
31+
AntiAffinity = "anti"
32+
SoftProAffinity = "soft-pro"
33+
SoftAntiAffinity = "soft-anti"
34+
NoAffinity = "no"
3335
)
3436

3537
// CloudStackMachineSpec defines the desired state of CloudStackMachine

api/v1beta3/cloudstackmachinetemplate_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func (r *CloudStackMachineTemplate) ValidateCreate() error {
6363
spec := r.Spec.Template.Spec
6464

6565
affinity := strings.ToLower(spec.Affinity)
66-
if !(affinity == "" || affinity == "no" || affinity == "pro" || affinity == "anti") {
66+
if !(affinity == "" || affinity == "no" || affinity == "pro" || affinity == "anti" || affinity == "soft-pro" || affinity == "soft-anti") {
6767
errorList = append(errorList, field.Invalid(field.NewPath("spec", "Affinity"), spec.Affinity,
68-
`Affinity must be "no", "pro", "anti", or unspecified.`))
68+
`Affinity must be "no", "pro", "anti", "soft-pro", "soft-anti", or unspecified.`))
6969
}
7070
if affinity != "no" && affinity != "" && len(spec.AffinityGroupIDs) > 0 {
7171
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "AffinityGroupIDs"),

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackaffinitygroups.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ spec:
4545
type: string
4646
type:
4747
description: Mutually exclusive parameter with AffinityGroupIDs. Can
48-
be "host affinity" or "host anti-affinity". Will create an affinity
49-
group per machine set.
48+
be "host affinity", "host anti-affinity", "non-strict host affinity"or
49+
"non-strict host anti-affinity". Will create an affinity group per
50+
machine set.
5051
type: string
5152
type: object
5253
status:
@@ -151,8 +152,9 @@ spec:
151152
type: string
152153
type:
153154
description: Mutually exclusive parameter with AffinityGroupIDs. Can
154-
be "host affinity" or "host anti-affinity". Will create an affinity
155-
group per machine set.
155+
be "host affinity", "host anti-affinity", "non-strict host affinity"
156+
or "non-strict host anti-affinity". Will create an affinity group
157+
per machine set.
156158
type: string
157159
type: object
158160
status:

controllers/utils/affinity_group.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func (r *ReconciliationRunner) GetOrCreateAffinityGroup(
5555
ag.Spec.Type = "host affinity"
5656
} else if affinityType == infrav1.AntiAffinity {
5757
ag.Spec.Type = "host anti-affinity"
58+
} else if affinityType == infrav1.SoftProAffinity {
59+
ag.Spec.Type = "non-strict host affinity"
60+
} else if affinityType == infrav1.SoftAntiAffinity {
61+
ag.Spec.Type = "non-strict host anti-affinity"
5862
} else {
5963
return ctrl.Result{}, errors.Errorf("unrecognized affinity type %s", affinityType)
6064
}

pkg/cloud/affinity_groups.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import (
2222
)
2323

2424
const (
25-
AntiAffinityGroupType = "host anti-affinity"
26-
AffinityGroupType = "host affinity"
25+
AntiAffinityGroupType = "host anti-affinity"
26+
AffinityGroupType = "host affinity"
27+
SoftAntiAffinityGroupType = "non-stric anti-affinity"
28+
SoftAffinityGroupType = "non-stric host affinity"
2729
)
2830

2931
type AffinityGroup struct {

test/e2e/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ E2E Test Run Logs: https://github.com/blueorangutan/capc-prs/releases/download/c
150150
[PASS] When testing with disk offering Should successfully create a cluster with disk offering
151151
[PASS] When testing affinity group Should have host affinity group when affinity is pro
152152
[PASS] When testing affinity group Should have host affinity group when affinity is anti
153+
[PASS] When testing affinity group Should have host affinity group when affinity is soft-pro
154+
[PASS] When testing affinity group Should have host affinity group when affinity is soft-anti
153155
[PASS] When the specified resource does not exist Should fail due to the specified account is not found [TC4a]
154156
[PASS] When the specified resource does not exist Should fail due to the specified domain is not found [TC4b]
155157
[PASS] When the specified resource does not exist Should fail due to the specified control plane offering is not found [TC7]

0 commit comments

Comments
 (0)