Skip to content

Commit f2786b6

Browse files
committed
Add validation for apis
Signed-off-by: Jian Qiu <[email protected]>
1 parent 06f2aec commit f2786b6

17 files changed

+85
-4
lines changed

addon/v1alpha1/0000_00_addon.open-cluster-management.io_clustermanagementaddons.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ spec:
3030
ManagedClusterAddOn resource. ClusterManagementAddOn is a cluster-scoped
3131
resource.
3232
type: object
33+
required:
34+
- spec
3335
properties:
3436
apiVersion:
3537
description: 'APIVersion defines the versioned schema of this representation

addon/v1alpha1/types_clustermanagementaddon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ClusterManagementAddOn struct {
2323
metav1.ObjectMeta `json:"metadata,omitempty"`
2424

2525
// spec represents a desired configuration for the agent on the cluster management add-on.
26+
// +kubebuilder:validation:Required
2627
// +required
2728
Spec ClusterManagementAddOnSpec `json:"spec"`
2829

cluster/v1/0000_00_clusters.open-cluster-management.io_managedclusters.crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ spec:
4343
on the ManagedCluster pushes the credential to the hub to use against the
4444
kube-apiserver of the ManagedCluster."
4545
type: object
46+
required:
47+
- spec
4648
properties:
4749
apiVersion:
4850
description: 'APIVersion defines the versioned schema of this representation
@@ -60,6 +62,8 @@ spec:
6062
description: Spec represents a desired configuration for the agent on
6163
the managed cluster.
6264
type: object
65+
required:
66+
- hubAcceptsClient
6367
properties:
6468
hubAcceptsClient:
6569
description: hubAcceptsClient represents that hub accepts the joining
@@ -80,6 +84,7 @@ spec:
8084
60 seconds by default
8185
type: integer
8286
format: int32
87+
default: 60
8388
managedClusterClientConfigs:
8489
description: ManagedClusterClientConfigs represents a list of the
8590
apiserver address of the managed cluster. If it is empty, the managed

cluster/v1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type ManagedCluster struct {
3535
metav1.ObjectMeta `json:"metadata,omitempty"`
3636

3737
// Spec represents a desired configuration for the agent on the managed cluster.
38+
// +kubebuilder:validation:Required
39+
// +required
3840
Spec ManagedClusterSpec `json:"spec"`
3941

4042
// Status represents the current status of joined managed cluster
@@ -59,11 +61,13 @@ type ManagedClusterSpec struct {
5961
// the namespace to grant the permision of access from the agent on the managed cluster.
6062
// When the value is set to false, the namespace representing the managed cluster is
6163
// deleted.
64+
// +kubebuilder:validation:Required
6265
// +required
6366
HubAcceptsClient bool `json:"hubAcceptsClient"`
6467

6568
// LeaseDurationSeconds is used to coordinate the lease update time of Klusterlet agents on the managed cluster.
6669
// If its value is zero, the Klusterlet agent will update its lease every 60 seconds by default
70+
// +kubebuilder:default:=60
6771
// +optional
6872
LeaseDurationSeconds int32 `json:"leaseDurationSeconds,omitempty"`
6973
}

cluster/v1alpha1/0000_00_clusters.open-cluster-management.io_managedclustersets.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
to update this label, user must have the permission on both the old and
2929
new ManagedClusterSet."
3030
type: object
31+
required:
32+
- spec
3133
properties:
3234
apiVersion:
3335
description: 'APIVersion defines the versioned schema of this representation

cluster/v1alpha1/0000_01_clusters.open-cluster-management.io_managedclustersetbindings.crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ spec:
2222
created in the same namespace can only be distributed to ManagedClusters
2323
in ManagedClusterSets bound in this namespace by higher level controllers.
2424
type: object
25+
required:
26+
- spec
2527
properties:
2628
apiVersion:
2729
description: 'APIVersion defines the versioned schema of this representation
@@ -38,6 +40,8 @@ spec:
3840
spec:
3941
description: Spec defines the attributes of ManagedClusterSetBinding.
4042
type: object
43+
required:
44+
- clusterSet
4145
properties:
4246
clusterSet:
4347
description: ClusterSet is the name of the ManagedClusterSet to bind.

cluster/v1alpha1/0000_02_clusters.open-cluster-management.io_clusterclaims.crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ spec:
2121
an identifier that relates the cluster to the ClusterSet in which it
2222
belongs.
2323
type: object
24+
required:
25+
- spec
2426
properties:
2527
apiVersion:
2628
description: 'APIVersion defines the versioned schema of this representation
@@ -37,6 +39,8 @@ spec:
3739
spec:
3840
description: Spec defines the attributes of the ClusterClaim.
3941
type: object
42+
required:
43+
- value
4044
properties:
4145
value:
4246
description: Value is a claim-dependent string

cluster/v1alpha1/0001_02_clusters.open-cluster-management.io_clusterclaims.crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ spec:
1818
a unique identifier for the cluster. 2. clusterset.k8s.io, it contains an
1919
identifier that relates the cluster to the ClusterSet in which it belongs.
2020
type: object
21+
required:
22+
- spec
2123
properties:
2224
apiVersion:
2325
description: 'APIVersion defines the versioned schema of this representation
@@ -34,6 +36,8 @@ spec:
3436
spec:
3537
description: Spec defines the attributes of the ClusterClaim.
3638
type: object
39+
required:
40+
- value
3741
properties:
3842
value:
3943
description: Value is a claim-dependent string

cluster/v1alpha1/types.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type ManagedClusterSet struct {
2626
metav1.ObjectMeta `json:"metadata,omitempty"`
2727

2828
// Spec defines the attributes of the ManagedClusterSet
29+
// +kubebuilder:validation:Required
30+
// +required
2931
Spec ManagedClusterSetSpec `json:"spec"`
3032

3133
// Status represents the current status of the ManagedClusterSet
@@ -78,6 +80,8 @@ type ManagedClusterSetBinding struct {
7880
metav1.ObjectMeta `json:"metadata,omitempty"`
7981

8082
// Spec defines the attributes of ManagedClusterSetBinding.
83+
// +kubebuilder:validation:Required
84+
// +required
8185
Spec ManagedClusterSetBindingSpec `json:"spec"`
8286
}
8387

@@ -88,6 +92,8 @@ type ManagedClusterSetBindingSpec struct {
8892
// User is allowed to set this field if they have an RBAC rule to CREATE on the
8993
// virtual subresource of managedclustersets/bind.
9094
// +kubebuilder:validation:MinLength=1
95+
// +kubebuilder:validation:Required
96+
// +required
9197
ClusterSet string `json:"clusterSet"`
9298
}
9399

@@ -120,14 +126,18 @@ type ClusterClaim struct {
120126
metav1.ObjectMeta `json:"metadata,omitempty"`
121127

122128
// Spec defines the attributes of the ClusterClaim.
123-
Spec ClusterClaimSpec `json:"spec,omitempty"`
129+
// +kubebuilder:validation:Required
130+
// +required
131+
Spec ClusterClaimSpec `json:"spec"`
124132
}
125133

126134
type ClusterClaimSpec struct {
127135
// Value is a claim-dependent string
128136
// +kubebuilder:validation:MaxLength=1024
129137
// +kubebuilder:validation:MinLength=1
130-
Value string `json:"value,omitempty"`
138+
// +kubebuilder:validation:Required
139+
// +required
140+
Value string `json:"value"`
131141
}
132142

133143
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ spec:
2020
in the same namespace to allow API requests to the hub for the registration
2121
protocol.
2222
type: object
23+
required:
24+
- spec
2325
properties:
2426
apiVersion:
2527
description: 'APIVersion defines the versioned schema of this representation
@@ -43,6 +45,8 @@ spec:
4345
created on hub. The Klusterlet agent generates a random name if
4446
it is not set, or discovers the appropriate cluster name on OpenShift.
4547
type: string
48+
maxLength: 63
49+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
4650
externalServerURLs:
4751
description: ExternalServerURLs represents the a list of apiserver
4852
urls and ca bundles that is accessible externally If it is set empty,
@@ -70,6 +74,8 @@ spec:
7074
set, the namespace of "open-cluster-management-agent" is used to
7175
deploy agent.
7276
type: string
77+
maxLength: 63
78+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
7379
registrationImagePullSpec:
7480
description: RegistrationImagePullSpec represents the desired image
7581
configuration of registration agent.

0 commit comments

Comments
 (0)