Skip to content

Commit

Permalink
Adding hubClusterArn validation in spec
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Jaswal <[email protected]>
  • Loading branch information
Gaurav Jaswal committed Jan 15, 2025
1 parent bda1321 commit e8f7b7e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ spec:
- awsirsa
type: string
hubClusterArn:
description: This represents the hub cluster ARN
description: |-
This represents the hub cluster ARN
Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1
pattern: ^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$
type: string
type: object
type: array
Expand Down
2 changes: 2 additions & 0 deletions operator/v1/types_clustermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ type RegistrationDriverHub struct {
AuthType string `json:"authType,omitempty"`

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

Expand Down
2 changes: 1 addition & 1 deletion operator/v1/zz_generated.swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions test/integration/api/clustermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,46 @@ var _ = Describe("ClusterManager API test with RegistrationConfiguration", func(
Expect(clusterManager.Spec.RegistrationConfiguration.FeatureGates[0].Mode).Should(Equal(operatorv1.FeatureGateModeTypeDisable))
Expect(clusterManager.Spec.RegistrationConfiguration.FeatureGates[1].Mode).Should(Equal(operatorv1.FeatureGateModeTypeEnable))
})

It("Create a cluster manager with aws registration and invalid hubClusterArn", func() {
clusterManager := &operatorv1.ClusterManager{
ObjectMeta: metav1.ObjectMeta{
Name: clusterManagerName,
},
Spec: operatorv1.ClusterManagerSpec{
RegistrationConfiguration: &operatorv1.RegistrationHubConfiguration{
RegistrationDrivers: []operatorv1.RegistrationDriverHub{
{
AuthType: "awsirsa",
HubClusterArn: "arn:aws:bks:us-west-2:123456789012:cluster/hub-cluster1",
},
},
},
},
}
_, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
Expect(err).ToNot(BeNil())
})

It("Create a cluster manager with aws registration and valid hubClusterArn", func() {
clusterManager := &operatorv1.ClusterManager{
ObjectMeta: metav1.ObjectMeta{
Name: clusterManagerName,
},
Spec: operatorv1.ClusterManagerSpec{
RegistrationConfiguration: &operatorv1.RegistrationHubConfiguration{
RegistrationDrivers: []operatorv1.RegistrationDriverHub{
{
AuthType: "awsirsa",
HubClusterArn: "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster1",
},
},
},
},
}
_, err := operatorClient.OperatorV1().ClusterManagers().Create(context.TODO(), clusterManager, metav1.CreateOptions{})
Expect(err).To(BeNil())
})
})

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

0 comments on commit e8f7b7e

Please sign in to comment.