Skip to content

Commit 87360e2

Browse files
authored
fix: Move preflight skip annotation constants to api module (#1187)
**What problem does this PR solve?**: Makes it possible for CAREN api module consumers to reference these constants. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 92e78ad commit 87360e2

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

api/v1alpha1/constants.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ const (
3939
// DNSVariableName is the DNS external patch variable name.
4040
DNSVariableName = "dns"
4141

42-
ClusterUUIDAnnotationKey = APIGroup + "/cluster-uuid"
42+
ClusterUUIDAnnotationKey = APIGroup + "/cluster-uuid"
43+
4344
SkipAutoEnablingWorkloadClusterRegistry = APIGroup + "/skip-auto-enabling-workload-cluster-registry"
45+
46+
// PreflightChecksSkipAnnotationKey is the key of the annotation on the Cluster used to skip preflight checks.
47+
PreflightChecksSkipAnnotationKey = "preflight.cluster.caren.nutanix.com/skip"
48+
49+
// PreflightChecksSkipAllAnnotationValue is the value used in the cluster's annotations to indicate
50+
// that all checks are skipped.
51+
PreflightChecksSkipAllAnnotationValue = "all"
4452
)

pkg/webhook/preflight/preflight_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sigs.k8s.io/controller-runtime/pkg/client/fake"
2525
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2626

27+
carenv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
2728
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/webhook/preflight/skip"
2829
)
2930

@@ -68,7 +69,7 @@ func topologyCluster(skippedCheckNames ...string) *clusterv1.Cluster {
6869
ObjectMeta: metav1.ObjectMeta{
6970
Name: "test-cluster",
7071
Annotations: map[string]string{
71-
skip.AnnotationKey: strings.Join(skippedCheckNames, ","),
72+
carenv1.PreflightChecksSkipAnnotationKey: strings.Join(skippedCheckNames, ","),
7273
},
7374
},
7475
Spec: clusterv1.ClusterSpec{
@@ -147,7 +148,7 @@ func TestHandle(t *testing.T) {
147148
},
148149
{
149150
name: "if cluster skips all checks, then allowed, with a warning",
150-
cluster: topologyCluster(skip.SkipAllChecksAnnotationValue),
151+
cluster: topologyCluster(carenv1.PreflightChecksSkipAllAnnotationValue),
151152
checkers: []Checker{
152153
&mockChecker{
153154
checks: []Check{},

pkg/webhook/preflight/skip/skip.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@ import (
66
"strings"
77

88
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
9-
)
10-
11-
const (
12-
// AnnotationKey is the key of the annotation on the Cluster used to skip preflight checks.
13-
AnnotationKey = "preflight.cluster.caren.nutanix.com/skip"
149

15-
// SkipAllChecksAnnotationValue is the value used in the cluster's annotations to indicate
16-
// that all checks are skipped.
17-
SkipAllChecksAnnotationValue = "all"
10+
carenv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1811
)
1912

2013
// Evaluator is used to determine which checks should be skipped, based on the cluster's annotations.
@@ -35,7 +28,7 @@ func New(cluster *clusterv1.Cluster) *Evaluator {
3528
return o
3629
}
3730

38-
value, exists := annotations[AnnotationKey]
31+
value, exists := annotations[carenv1.PreflightChecksSkipAnnotationKey]
3932
if !exists {
4033
// If the annotation does not exist, return an Evaluator with no prefixes.
4134
return o
@@ -49,7 +42,8 @@ func New(cluster *clusterv1.Cluster) *Evaluator {
4942
normalizedCheckName := strings.TrimSpace(strings.ToLower(checkName))
5043
o.normalizedCheckNames[normalizedCheckName] = struct{}{}
5144
}
52-
if _, exists := o.normalizedCheckNames[SkipAllChecksAnnotationValue]; exists && len(o.normalizedCheckNames) == 1 {
45+
if _, exists := o.normalizedCheckNames[carenv1.PreflightChecksSkipAllAnnotationValue]; exists &&
46+
len(o.normalizedCheckNames) == 1 {
5347
o.all = true
5448
}
5549
return o

pkg/webhook/preflight/skip/skip_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/stretchr/testify/assert"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
12+
13+
carenv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1214
)
1315

1416
func TestNew(t *testing.T) {
@@ -37,14 +39,14 @@ func TestNew(t *testing.T) {
3739
{
3840
name: "ignores empty skip annotation value",
3941
annotations: map[string]string{
40-
AnnotationKey: "",
42+
carenv1.PreflightChecksSkipAnnotationKey: "",
4143
},
4244
expectCheckNames: map[string]struct{}{},
4345
},
4446
{
4547
name: "ignores empty check names",
4648
annotations: map[string]string{
47-
AnnotationKey: "InfraVMImage,,InfraCredentials,",
49+
carenv1.PreflightChecksSkipAnnotationKey: "InfraVMImage,,InfraCredentials,",
4850
},
4951
expectCheckNames: map[string]struct{}{
5052
"infravmimage": {},
@@ -54,14 +56,14 @@ func TestNew(t *testing.T) {
5456
{
5557
name: "ignores value of only commas",
5658
annotations: map[string]string{
57-
AnnotationKey: ",,,",
59+
carenv1.PreflightChecksSkipAnnotationKey: ",,,",
5860
},
5961
expectCheckNames: map[string]struct{}{},
6062
},
6163
{
6264
name: "accepts single check name",
6365
annotations: map[string]string{
64-
AnnotationKey: "InfraVMImage",
66+
carenv1.PreflightChecksSkipAnnotationKey: "InfraVMImage",
6567
},
6668
expectCheckNames: map[string]struct{}{
6769
"infravmimage": {},
@@ -70,7 +72,7 @@ func TestNew(t *testing.T) {
7072
{
7173
name: "accepts multiple check names",
7274
annotations: map[string]string{
73-
AnnotationKey: "InfraVMImage,InfraCredentials",
75+
carenv1.PreflightChecksSkipAnnotationKey: "InfraVMImage,InfraCredentials",
7476
},
7577
expectCheckNames: map[string]struct{}{
7678
"infravmimage": {},
@@ -80,7 +82,7 @@ func TestNew(t *testing.T) {
8082
{
8183
name: "trims spaces from check names",
8284
annotations: map[string]string{
83-
AnnotationKey: " InfraVMImage , InfraCredentials ",
85+
carenv1.PreflightChecksSkipAnnotationKey: " InfraVMImage , InfraCredentials ",
8486
},
8587
expectCheckNames: map[string]struct{}{
8688
"infravmimage": {},
@@ -125,47 +127,47 @@ func TestEvaluator_For(t *testing.T) {
125127
{
126128
name: "empty annotation value",
127129
annotations: map[string]string{
128-
AnnotationKey: "",
130+
carenv1.PreflightChecksSkipAnnotationKey: "",
129131
},
130132
checkName: "InfraVMImage",
131133
expectMatch: false,
132134
},
133135
{
134136
name: "skip InfraVMImage check",
135137
annotations: map[string]string{
136-
AnnotationKey: "InfraVMImage,InfraCredentials",
138+
carenv1.PreflightChecksSkipAnnotationKey: "InfraVMImage,InfraCredentials",
137139
},
138140
checkName: "InfraVMImage",
139141
expectMatch: true,
140142
},
141143
{
142144
name: "skip credentials, but not image",
143145
annotations: map[string]string{
144-
AnnotationKey: "InfraCredentials",
146+
carenv1.PreflightChecksSkipAnnotationKey: "InfraCredentials",
145147
},
146148
checkName: "InfraVMImage",
147149
expectMatch: false,
148150
},
149151
{
150152
name: "skip with spaces and case mixing",
151153
annotations: map[string]string{
152-
AnnotationKey: " infraVMImage , InfraCredentials ",
154+
carenv1.PreflightChecksSkipAnnotationKey: " infraVMImage , InfraCredentials ",
153155
},
154156
checkName: "InfraVMImage",
155157
expectMatch: true,
156158
},
157159
{
158160
name: "extra commas do not affect matching",
159161
annotations: map[string]string{
160-
AnnotationKey: "InfraVMImage,,InfraCredentials,",
162+
carenv1.PreflightChecksSkipAnnotationKey: "InfraVMImage,,InfraCredentials,",
161163
},
162164
checkName: "InfraVMImage",
163165
expectMatch: true,
164166
},
165167
{
166168
name: "skip all checks",
167169
annotations: map[string]string{
168-
AnnotationKey: "all",
170+
carenv1.PreflightChecksSkipAnnotationKey: "all",
169171
},
170172
checkName: "InfraVMImage",
171173
expectMatch: true,
@@ -206,34 +208,34 @@ func TestEvaluator_ForAll(t *testing.T) {
206208
{
207209
name: "empty annotation value",
208210
annotations: map[string]string{
209-
AnnotationKey: "",
211+
carenv1.PreflightChecksSkipAnnotationKey: "",
210212
},
211213
},
212214
{
213215
name: "skip all checks with spaces and case mixing",
214216
annotations: map[string]string{
215-
AnnotationKey: " aLL ",
217+
carenv1.PreflightChecksSkipAnnotationKey: " aLL ",
216218
},
217219
expectMatch: true,
218220
},
219221
{
220222
name: "skip all checks with extra commas",
221223
annotations: map[string]string{
222-
AnnotationKey: ",all,,",
224+
carenv1.PreflightChecksSkipAnnotationKey: ",all,,",
223225
},
224226
expectMatch: true,
225227
},
226228
{
227229
name: "skip all checks",
228230
annotations: map[string]string{
229-
AnnotationKey: "all",
231+
carenv1.PreflightChecksSkipAnnotationKey: "all",
230232
},
231233
expectMatch: true,
232234
},
233235
{
234236
name: "skip some checks, but not all",
235237
annotations: map[string]string{
236-
AnnotationKey: "OneCheck,AnotherCheck",
238+
carenv1.PreflightChecksSkipAnnotationKey: "OneCheck,AnotherCheck",
237239
},
238240
expectMatch: false,
239241
},

0 commit comments

Comments
 (0)