Skip to content

Commit 1b224ed

Browse files
committed
Add validation for apis
1 parent 06f2aec commit 1b224ed

17 files changed

+85
-4
lines changed

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

+2
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

+1
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

+5
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

+4
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

+2
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

+4
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

+4
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

+4
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

+12-2
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

+6
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.

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

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ spec:
1919
registration and work distribution for attached Klusterlets. ClusterManager
2020
will only be deployed in open-cluster-management-hub namespace.
2121
type: object
22+
required:
23+
- spec
2224
properties:
2325
apiVersion:
2426
description: 'APIVersion defines the versioned schema of this representation

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

+6
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
on hub. The Klusterlet agent generates a random name if it is not
4446
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 urls
4852
and ca bundles that is accessible externally If it is set empty, managed
@@ -68,6 +72,8 @@ spec:
6872
set, the namespace of "open-cluster-management-agent" is used to deploy
6973
agent.
7074
type: string
75+
maxLength: 63
76+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
7177
registrationImagePullSpec:
7278
description: RegistrationImagePullSpec represents the desired image
7379
configuration of registration agent.

operator/v1/types.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type ClusterManager struct {
1717
metav1.ObjectMeta `json:"metadata,omitempty"`
1818

1919
// Spec represents a desired deployment configuration of controllers that govern registration and work distribution for attached Klusterlets.
20+
// +kubebuilder:validation:Required
21+
// +required
2022
Spec ClusterManagerSpec `json:"spec"`
2123

2224
// Status represents the current status of controllers that govern the lifecycle of managed clusters.
@@ -138,7 +140,9 @@ type Klusterlet struct {
138140
metav1.ObjectMeta `json:"metadata,omitempty"`
139141

140142
// Spec represents the desired deployment configuration of Klusterlet agent.
141-
Spec KlusterletSpec `json:"spec,omitempty"`
143+
// +kubebuilder:validation:Required
144+
// +required
145+
Spec KlusterletSpec `json:"spec"`
142146

143147
// Status represents the current status of Klusterlet agent.
144148
Status KlusterletStatus `json:"status,omitempty"`
@@ -150,6 +154,8 @@ type KlusterletSpec struct {
150154
// The namespace must have a prefix of "open-cluster-management-", and if it is not set,
151155
// the namespace of "open-cluster-management-agent" is used to deploy agent.
152156
// +optional
157+
// +kubebuilder:validation:MaxLength=63
158+
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
153159
Namespace string `json:"namespace,omitempty"`
154160

155161
// RegistrationImagePullSpec represents the desired image configuration of registration agent.
@@ -163,6 +169,8 @@ type KlusterletSpec struct {
163169
// ClusterName is the name of the managed cluster to be created on hub.
164170
// The Klusterlet agent generates a random name if it is not set, or discovers the appropriate cluster name on OpenShift.
165171
// +optional
172+
// +kubebuilder:validation:MaxLength=63
173+
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
166174
ClusterName string `json:"clusterName,omitempty"`
167175

168176
// ExternalServerURLs represents the a list of apiserver urls and ca bundles that is accessible externally

work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ spec:
2121
on the hub, so that agent on the corresponding managed cluster can access
2222
this resource and deploy on the managed cluster.
2323
type: object
24+
required:
25+
- spec
2426
properties:
2527
apiVersion:
2628
description: 'APIVersion defines the versioned schema of this representation
@@ -155,6 +157,9 @@ spec:
155157
description: ManifestCondition represents the conditions of
156158
the resources deployed on a managed cluster.
157159
type: object
160+
required:
161+
- conditions
162+
- resourceMeta
158163
properties:
159164
conditions:
160165
description: Conditions represents the conditions of this

work/v1/0000_01_work.open-cluster-management.io_appliedmanifestworks.crd.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ spec:
2323
agent. The name of the appliedmanifestwork must be in the format of {hash
2424
of hub's first kube-apiserver url}-{manifestwork name}
2525
type: object
26+
required:
27+
- spec
2628
properties:
2729
apiVersion:
2830
description: 'APIVersion defines the versioned schema of this representation
@@ -39,6 +41,9 @@ spec:
3941
spec:
4042
description: Spec represents the desired configuration of AppliedManifestWork.
4143
type: object
44+
required:
45+
- hubHash
46+
- manifestWorkName
4247
properties:
4348
hubHash:
4449
description: HubHash represents the hash of the first hub kube apiserver

work/v1/0001_01_work.open-cluster-management.io_appliedmanifestworks.crd.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ spec:
2424
The name of the appliedmanifestwork must be in the format of {hash of hub's
2525
first kube-apiserver url}-{manifestwork name}
2626
type: object
27+
required:
28+
- spec
2729
properties:
2830
apiVersion:
2931
description: 'APIVersion defines the versioned schema of this representation
@@ -40,6 +42,9 @@ spec:
4042
spec:
4143
description: Spec represents the desired configuration of AppliedManifestWork.
4244
type: object
45+
required:
46+
- hubHash
47+
- manifestWorkName
4348
properties:
4449
hubHash:
4550
description: HubHash represents the hash of the first hub kube apiserver

work/v1/types.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ type ManifestWork struct {
1919
metav1.ObjectMeta `json:"metadata,omitempty"`
2020

2121
// Spec represents a desired configuration of work to be deployed on the managed cluster.
22+
// +kubebuilder:validation:Required
23+
// +required
2224
Spec ManifestWorkSpec `json:"spec"`
2325

2426
// Status represents the current status of work.
@@ -157,10 +159,12 @@ const (
157159
// managed cluster.
158160
type ManifestCondition struct {
159161
// ResourceMeta represents the group, version, kind, name and namespace of a resoure.
162+
// +kubebuilder:validation:Required
160163
// +required
161164
ResourceMeta ManifestResourceMeta `json:"resourceMeta"`
162165

163166
// Conditions represents the conditions of this resource on a managed cluster.
167+
// +kubebuilder:validation:Required
164168
// +required
165169
Conditions []metav1.Condition `json:"conditions"`
166170
}
@@ -214,7 +218,9 @@ type AppliedManifestWork struct {
214218
metav1.ObjectMeta `json:"metadata,omitempty"`
215219

216220
// Spec represents the desired configuration of AppliedManifestWork.
217-
Spec AppliedManifestWorkSpec `json:"spec,omitempty"`
221+
// +kubebuilder:validation:Required
222+
// +required
223+
Spec AppliedManifestWorkSpec `json:"spec"`
218224

219225
// Status represents the current status of AppliedManifestWork.
220226
// +optional
@@ -225,10 +231,12 @@ type AppliedManifestWork struct {
225231
type AppliedManifestWorkSpec struct {
226232
// HubHash represents the hash of the first hub kube apiserver to identify which hub
227233
// this AppliedManifestWork links to.
234+
// +kubebuilder:validation:Required
228235
// +required
229236
HubHash string `json:"hubHash"`
230237

231238
// ManifestWorkName represents the name of the related manifestwork on the hub.
239+
// +kubebuilder:validation:Required
232240
// +required
233241
ManifestWorkName string `json:"manifestWorkName"`
234242
}

0 commit comments

Comments
 (0)