Skip to content

Commit 3a595d6

Browse files
jaswalkiranavtarGaurav Jaswal
and
Gaurav Jaswal
authored
Adding hubClusterArn validation in spec (#356)
Signed-off-by: Gaurav Jaswal <[email protected]> Signed-off-by: Gaurav Jaswal <[email protected]> Co-authored-by: Gaurav Jaswal <[email protected]>
1 parent bda1321 commit 3a595d6

4 files changed

+47
-2
lines changed

operator/v1/0000_01_operator.open-cluster-management.io_clustermanagers.crd.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ spec:
270270
- awsirsa
271271
type: string
272272
hubClusterArn:
273-
description: This represents the hub cluster ARN
273+
description: |-
274+
This represents the hub cluster ARN
275+
Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1
276+
pattern: ^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$
274277
type: string
275278
type: object
276279
type: array

operator/v1/types_clustermanager.go

+2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ type RegistrationDriverHub struct {
126126
AuthType string `json:"authType,omitempty"`
127127

128128
// This represents the hub cluster ARN
129+
// Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1
129130
// +optional
131+
// +kubebuilder:validation:Pattern=`^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$`
130132
HubClusterArn string `json:"hubClusterArn,omitempty"`
131133
}
132134

operator/v1/zz_generated.swagger_doc_generated.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/api/clustermanager_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,46 @@ var _ = Describe("ClusterManager API test with RegistrationConfiguration", func(
261261
Expect(clusterManager.Spec.RegistrationConfiguration.FeatureGates[0].Mode).Should(Equal(operatorv1.FeatureGateModeTypeDisable))
262262
Expect(clusterManager.Spec.RegistrationConfiguration.FeatureGates[1].Mode).Should(Equal(operatorv1.FeatureGateModeTypeEnable))
263263
})
264+
265+
It("Create a cluster manager with aws registration and invalid hubClusterArn", func() {
266+
clusterManager := &operatorv1.ClusterManager{
267+
ObjectMeta: metav1.ObjectMeta{
268+
Name: clusterManagerName,
269+
},
270+
Spec: operatorv1.ClusterManagerSpec{
271+
RegistrationConfiguration: &operatorv1.RegistrationHubConfiguration{
272+
RegistrationDrivers: []operatorv1.RegistrationDriverHub{
273+
{
274+
AuthType: "awsirsa",
275+
HubClusterArn: "arn:aws:bks:us-west-2:123456789012:cluster/hub-cluster1",
276+
},
277+
},
278+
},
279+
},
280+
}
281+
_, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
282+
Expect(err).ToNot(BeNil())
283+
})
284+
285+
It("Create a cluster manager with aws registration and valid hubClusterArn", func() {
286+
clusterManager := &operatorv1.ClusterManager{
287+
ObjectMeta: metav1.ObjectMeta{
288+
Name: clusterManagerName,
289+
},
290+
Spec: operatorv1.ClusterManagerSpec{
291+
RegistrationConfiguration: &operatorv1.RegistrationHubConfiguration{
292+
RegistrationDrivers: []operatorv1.RegistrationDriverHub{
293+
{
294+
AuthType: "awsirsa",
295+
HubClusterArn: "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster1",
296+
},
297+
},
298+
},
299+
},
300+
}
301+
_, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
302+
Expect(err).To(BeNil())
303+
})
264304
})
265305

266306
var _ = Describe("ClusterManager API test with WorkConfiguration", func() {

0 commit comments

Comments
 (0)