Skip to content

Commit

Permalink
Add validation for apis
Browse files Browse the repository at this point in the history
  • Loading branch information
qiujian16 committed Apr 16, 2021
1 parent 06f2aec commit 1b224ed
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ spec:
ManagedClusterAddOn resource. ClusterManagementAddOn is a cluster-scoped
resource.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down
1 change: 1 addition & 0 deletions addon/v1alpha1/types_clustermanagementaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ClusterManagementAddOn struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ spec:
on the ManagedCluster pushes the credential to the hub to use against the
kube-apiserver of the ManagedCluster."
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -60,6 +62,8 @@ spec:
description: Spec represents a desired configuration for the agent on
the managed cluster.
type: object
required:
- hubAcceptsClient
properties:
hubAcceptsClient:
description: hubAcceptsClient represents that hub accepts the joining
Expand All @@ -80,6 +84,7 @@ spec:
60 seconds by default
type: integer
format: int32
default: 60
managedClusterClientConfigs:
description: ManagedClusterClientConfigs represents a list of the
apiserver address of the managed cluster. If it is empty, the managed
Expand Down
4 changes: 4 additions & 0 deletions cluster/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type ManagedCluster struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

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

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

// LeaseDurationSeconds is used to coordinate the lease update time of Klusterlet agents on the managed cluster.
// If its value is zero, the Klusterlet agent will update its lease every 60 seconds by default
// +kubebuilder:default:=60
// +optional
LeaseDurationSeconds int32 `json:"leaseDurationSeconds,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ spec:
to update this label, user must have the permission on both the old and
new ManagedClusterSet."
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spec:
created in the same namespace can only be distributed to ManagedClusters
in ManagedClusterSets bound in this namespace by higher level controllers.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -38,6 +40,8 @@ spec:
spec:
description: Spec defines the attributes of ManagedClusterSetBinding.
type: object
required:
- clusterSet
properties:
clusterSet:
description: ClusterSet is the name of the ManagedClusterSet to bind.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ spec:
an identifier that relates the cluster to the ClusterSet in which it
belongs.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -37,6 +39,8 @@ spec:
spec:
description: Spec defines the attributes of the ClusterClaim.
type: object
required:
- value
properties:
value:
description: Value is a claim-dependent string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ spec:
a unique identifier for the cluster. 2. clusterset.k8s.io, it contains an
identifier that relates the cluster to the ClusterSet in which it belongs.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -34,6 +36,8 @@ spec:
spec:
description: Spec defines the attributes of the ClusterClaim.
type: object
required:
- value
properties:
value:
description: Value is a claim-dependent string
Expand Down
14 changes: 12 additions & 2 deletions cluster/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type ManagedClusterSet struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the attributes of the ManagedClusterSet
// +kubebuilder:validation:Required
// +required
Spec ManagedClusterSetSpec `json:"spec"`

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

// Spec defines the attributes of ManagedClusterSetBinding.
// +kubebuilder:validation:Required
// +required
Spec ManagedClusterSetBindingSpec `json:"spec"`
}

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

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

// Spec defines the attributes of the ClusterClaim.
Spec ClusterClaimSpec `json:"spec,omitempty"`
// +kubebuilder:validation:Required
// +required
Spec ClusterClaimSpec `json:"spec"`
}

type ClusterClaimSpec struct {
// Value is a claim-dependent string
// +kubebuilder:validation:MaxLength=1024
// +kubebuilder:validation:MinLength=1
Value string `json:"value,omitempty"`
// +kubebuilder:validation:Required
// +required
Value string `json:"value"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
in the same namespace to allow API requests to the hub for the registration
protocol.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -43,6 +45,8 @@ spec:
created on hub. The Klusterlet agent generates a random name if
it is not set, or discovers the appropriate cluster name on OpenShift.
type: string
maxLength: 63
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
externalServerURLs:
description: ExternalServerURLs represents the a list of apiserver
urls and ca bundles that is accessible externally If it is set empty,
Expand Down Expand Up @@ -70,6 +74,8 @@ spec:
set, the namespace of "open-cluster-management-agent" is used to
deploy agent.
type: string
maxLength: 63
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
registrationImagePullSpec:
description: RegistrationImagePullSpec represents the desired image
configuration of registration agent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ spec:
registration and work distribution for attached Klusterlets. ClusterManager
will only be deployed in open-cluster-management-hub namespace.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
in the same namespace to allow API requests to the hub for the registration
protocol.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -43,6 +45,8 @@ spec:
on hub. The Klusterlet agent generates a random name if it is not
set, or discovers the appropriate cluster name on OpenShift.
type: string
maxLength: 63
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
externalServerURLs:
description: ExternalServerURLs represents the a list of apiserver urls
and ca bundles that is accessible externally If it is set empty, managed
Expand All @@ -68,6 +72,8 @@ spec:
set, the namespace of "open-cluster-management-agent" is used to deploy
agent.
type: string
maxLength: 63
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
registrationImagePullSpec:
description: RegistrationImagePullSpec represents the desired image
configuration of registration agent.
Expand Down
10 changes: 9 additions & 1 deletion operator/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type ClusterManager struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

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

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

// Spec represents the desired deployment configuration of Klusterlet agent.
Spec KlusterletSpec `json:"spec,omitempty"`
// +kubebuilder:validation:Required
// +required
Spec KlusterletSpec `json:"spec"`

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

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

// ExternalServerURLs represents the a list of apiserver urls and ca bundles that is accessible externally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ spec:
on the hub, so that agent on the corresponding managed cluster can access
this resource and deploy on the managed cluster.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down Expand Up @@ -155,6 +157,9 @@ spec:
description: ManifestCondition represents the conditions of
the resources deployed on a managed cluster.
type: object
required:
- conditions
- resourceMeta
properties:
conditions:
description: Conditions represents the conditions of this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ spec:
agent. The name of the appliedmanifestwork must be in the format of {hash
of hub's first kube-apiserver url}-{manifestwork name}
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -39,6 +41,9 @@ spec:
spec:
description: Spec represents the desired configuration of AppliedManifestWork.
type: object
required:
- hubHash
- manifestWorkName
properties:
hubHash:
description: HubHash represents the hash of the first hub kube apiserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ spec:
The name of the appliedmanifestwork must be in the format of {hash of hub's
first kube-apiserver url}-{manifestwork name}
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -40,6 +42,9 @@ spec:
spec:
description: Spec represents the desired configuration of AppliedManifestWork.
type: object
required:
- hubHash
- manifestWorkName
properties:
hubHash:
description: HubHash represents the hash of the first hub kube apiserver
Expand Down
10 changes: 9 additions & 1 deletion work/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ManifestWork struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

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

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

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

// Spec represents the desired configuration of AppliedManifestWork.
Spec AppliedManifestWorkSpec `json:"spec,omitempty"`
// +kubebuilder:validation:Required
// +required
Spec AppliedManifestWorkSpec `json:"spec"`

// Status represents the current status of AppliedManifestWork.
// +optional
Expand All @@ -225,10 +231,12 @@ type AppliedManifestWork struct {
type AppliedManifestWorkSpec struct {
// HubHash represents the hash of the first hub kube apiserver to identify which hub
// this AppliedManifestWork links to.
// +kubebuilder:validation:Required
// +required
HubHash string `json:"hubHash"`

// ManifestWorkName represents the name of the related manifestwork on the hub.
// +kubebuilder:validation:Required
// +required
ManifestWorkName string `json:"manifestWorkName"`
}
Expand Down

0 comments on commit 1b224ed

Please sign in to comment.