Skip to content

Commit fc6a26f

Browse files
jaswalkiranavtarEricaJ6
authored andcommitted
Adding cluster-arn validation to klusterlet CRD
Signed-off-by: Erica Jin <[email protected]>
1 parent cb7ce98 commit fc6a26f

4 files changed

+23
-0
lines changed

crdsv1beta1/0001_00_operator.open-cluster-management.io_klusterlets.crd.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@ spec:
204204
description: 'The arn of the hub cluster (ie: an EKS cluster). This will be required to pass information to hub, which hub will use to create IAM identities for this klusterlet. Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1.'
205205
type: string
206206
minLength: 1
207+
pattern: ^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$
207208
managedClusterArn:
208209
description: 'The arn of the managed cluster (ie: an EKS cluster). This will be required to generate the md5hash which will be used as a suffix to create IAM role on hub as well as used by kluslerlet-agent, to assume role suffixed with the md5hash, on startup. Example - arn:eks:us-west-2:12345678910:cluster/managed-cluster1.'
209210
type: string
210211
minLength: 1
212+
pattern: ^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$
211213
registrationImagePullSpec:
212214
description: RegistrationImagePullSpec represents the desired image configuration of registration agent. quay.io/open-cluster-management.io/registration:latest will be used if unspecified.
213215
type: string

operator/v1/0000_00_operator.open-cluster-management.io_klusterlets.crd.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,15 @@ spec:
312312
The arn of the hub cluster (ie: an EKS cluster). This will be required to pass information to hub, which hub will use to create IAM identities for this klusterlet.
313313
Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1.
314314
minLength: 1
315+
pattern: ^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$
315316
type: string
316317
managedClusterArn:
317318
description: |-
318319
The arn of the managed cluster (ie: an EKS cluster). This will be required to generate the md5hash which will be used as a suffix to create IAM role on hub
319320
as well as used by kluslerlet-agent, to assume role suffixed with the md5hash, on startup.
320321
Example - arn:eks:us-west-2:12345678910:cluster/managed-cluster1.
321322
minLength: 1
323+
pattern: ^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$
322324
type: string
323325
type: object
324326
type: object

operator/v1/types_klusterlet.go

+2
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,14 @@ type AwsIrsa struct {
195195
// Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1.
196196
// +required
197197
// +kubebuilder:validation:MinLength=1
198+
// +kubebuilder:validation:Pattern=`^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$`
198199
HubClusterArn string `json:"hubClusterArn"`
199200
// The arn of the managed cluster (ie: an EKS cluster). This will be required to generate the md5hash which will be used as a suffix to create IAM role on hub
200201
// as well as used by kluslerlet-agent, to assume role suffixed with the md5hash, on startup.
201202
// Example - arn:eks:us-west-2:12345678910:cluster/managed-cluster1.
202203
// +required
203204
// +kubebuilder:validation:MinLength=1
205+
// +kubebuilder:validation:Pattern=`^arn:aws:eks:([a-zA-Z0-9-]+):(\d{12}):cluster/([a-zA-Z0-9-]+)$`
204206
ManagedClusterArn string `json:"managedClusterArn"`
205207
}
206208

test/integration/api/klusterlet_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ var _ = Describe("Create Klusterlet API", func() {
3737
Expect(err).NotTo(BeNil())
3838
})
3939
})
40+
41+
Context("Create with aws auth and invalid arn", func() {
42+
It("should reject the klusterlet creation", func() {
43+
klusterlet.Spec.RegistrationConfiguration = &operatorv1.RegistrationConfiguration{
44+
RegistrationDriver: operatorv1.RegistrationDriver{
45+
AuthType: "awsirsa",
46+
AwsIrsa: &operatorv1.AwsIrsa{
47+
ManagedClusterArn: "arn:aws:bks:us-west-2:123456789012:cluster/managed-cluster1",
48+
HubClusterArn: "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster1",
49+
},
50+
},
51+
}
52+
_, err := operatorClient.OperatorV1().Klusterlets().Create(context.TODO(), klusterlet, metav1.CreateOptions{})
53+
fmt.Println(err)
54+
Expect(err).NotTo(BeNil())
55+
})
56+
})
4057
})
4158

4259
var _ = Describe("valid HubApiServerHostAlias", func() {

0 commit comments

Comments
 (0)