diff --git a/Makefile b/Makefile index 23ec0bd82..de609d798 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,10 @@ verify: verify-gocilint update-scripts: hack/update-deepcopy.sh + # Using controller-gen as a workaround for cluster:v1alpha1 because gengo + # isn't respecting deepcopy-gen:false nor does it support generics + # Issue: https://github.com/kubernetes/gengo/issues/225 + $(CONTROLLER_GEN) object:headerFile="hack/empty.txt" paths="./cluster/v1alpha1" hack/update-swagger-docs.sh hack/update-codegen.sh hack/update-v1beta1-crds.sh diff --git a/cluster/v1alpha1/doc.go b/cluster/v1alpha1/doc.go index b435a9cf7..28765f356 100644 --- a/cluster/v1alpha1/doc.go +++ b/cluster/v1alpha1/doc.go @@ -1,4 +1,5 @@ // Package v1alpha1 contains API Schema definitions for the cluster v1alpha1 API group +// +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=open-cluster-management.io/api/cluster // +k8s:defaulter-gen=TypeMeta // +k8s:openapi-gen=true diff --git a/cluster/v1alpha1/helpers.go b/cluster/v1alpha1/helpers.go index 03c2abd5b..7af8bd1b7 100644 --- a/cluster/v1alpha1/helpers.go +++ b/cluster/v1alpha1/helpers.go @@ -38,7 +38,6 @@ const ( ) // ClusterRolloutStatus holds the rollout status information for a cluster. -// +k8s:deepcopy-gen=true type ClusterRolloutStatus struct { // cluster name ClusterName string @@ -54,7 +53,6 @@ type ClusterRolloutStatus struct { } // RolloutResult contains list of clusters that are timeOut, removed and required to rollOut -// +k8s:deepcopy-gen=true type RolloutResult struct { // ClustersToRollout is a slice of ClusterRolloutStatus that will be rolled out. ClustersToRollout []ClusterRolloutStatus @@ -65,6 +63,7 @@ type RolloutResult struct { } // ClusterRolloutStatusFunc defines a function that return the rollout status for a given workload. +// +k8s:deepcopy-gen=false type ClusterRolloutStatusFunc[T any] func(clusterName string, workload T) (ClusterRolloutStatus, error) // The RolloutHandler required workload type (interface/struct) to be assigned to the generic type. diff --git a/cluster/v1alpha1/types.go b/cluster/v1alpha1/types.go index ab3d5c010..6cb57bc3b 100644 --- a/cluster/v1alpha1/types.go +++ b/cluster/v1alpha1/types.go @@ -7,7 +7,6 @@ import ( // +genclient // +genclient:nonNamespaced // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:deepcopy-gen=true // +kubebuilder:resource:scope="Cluster" // ClusterClaim represents cluster information that a managed cluster claims @@ -26,7 +25,6 @@ type ClusterClaim struct { Spec ClusterClaimSpec `json:"spec,omitempty"` } -// +k8s:deepcopy-gen=true type ClusterClaimSpec struct { // Value is a claim-dependent string // +kubebuilder:validation:MaxLength=1024 @@ -35,7 +33,6 @@ type ClusterClaimSpec struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:deepcopy-gen=true // ClusterClaimList is a collection of ClusterClaim. type ClusterClaimList struct { diff --git a/cluster/v1alpha1/types_addonplacementscore.go b/cluster/v1alpha1/types_addonplacementscore.go index 8dc98bf25..1ce73580b 100644 --- a/cluster/v1alpha1/types_addonplacementscore.go +++ b/cluster/v1alpha1/types_addonplacementscore.go @@ -6,7 +6,6 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:deepcopy-gen=true // +kubebuilder:resource:scope="Namespaced" // +kubebuilder:subresource:status @@ -22,7 +21,6 @@ type AddOnPlacementScore struct { } // AddOnPlacementScoreStatus represents the current status of AddOnPlacementScore. -// +k8s:deepcopy-gen=true type AddOnPlacementScoreStatus struct { // Conditions contain the different condition statuses for this AddOnPlacementScore. // +patchMergeKey=type @@ -48,7 +46,6 @@ type AddOnPlacementScoreStatus struct { } // AddOnPlacementScoreItem represents the score name and value. -// +k8s:deepcopy-gen=true type AddOnPlacementScoreItem struct { // Name is the name of the score // +kubebuilder:validation:Required @@ -64,7 +61,6 @@ type AddOnPlacementScoreItem struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +k8s:deepcopy-gen=true // AddOnPlacementScoreList is a collection of AddOnPlacementScore. type AddOnPlacementScoreList struct { diff --git a/cluster/v1alpha1/types_rolloutstrategy.go b/cluster/v1alpha1/types_rolloutstrategy.go index 0e3da1aaa..c9fa38155 100644 --- a/cluster/v1alpha1/types_rolloutstrategy.go +++ b/cluster/v1alpha1/types_rolloutstrategy.go @@ -18,7 +18,6 @@ const ( ) // Rollout strategy to apply workload to the selected clusters by Placement and DecisionStrategy. -// +k8s:deepcopy-gen=true type RolloutStrategy struct { // Rollout strategy Types are All, Progressive and ProgressivePerGroup // 1) All means apply the workload to all clusters in the decision groups at once. @@ -43,7 +42,6 @@ type RolloutStrategy struct { } // Timeout to consider while applying the workload. -// +k8s:deepcopy-gen=true type Timeout struct { // Timeout define how long workload applier controller will wait till workload reach successful state in the cluster. // Timeout default value is None meaning the workload applier will not proceed apply workload to other clusters if did not reach the successful state. @@ -56,7 +54,6 @@ type Timeout struct { // MandatoryDecisionGroup set the decision group name or group index. // GroupName is considered first to select the decisionGroups then GroupIndex. -// +k8s:deepcopy-gen=true type MandatoryDecisionGroup struct { // GroupName of the decision group should match the placementDecisions label value with label key cluster.open-cluster-management.io/decision-group-name // +optional @@ -68,7 +65,6 @@ type MandatoryDecisionGroup struct { } // MandatoryDecisionGroups -// +k8s:deepcopy-gen=true type MandatoryDecisionGroups struct { // List of the decision groups names or indexes to apply the workload first and fail if workload did not reach successful state. // GroupName or GroupIndex must match with the decisionGroups defined in the placement's decisionStrategy @@ -77,14 +73,12 @@ type MandatoryDecisionGroups struct { } // RolloutAll is a RolloutStrategy Type -// +k8s:deepcopy-gen=true type RolloutAll struct { // +optional Timeout `json:",inline"` } // RolloutProgressivePerGroup is a RolloutStrategy Type -// +k8s:deepcopy-gen=true type RolloutProgressivePerGroup struct { // +optional MandatoryDecisionGroups `json:",inline"` @@ -94,7 +88,6 @@ type RolloutProgressivePerGroup struct { } // RolloutProgressive is a RolloutStrategy Type -// +k8s:deepcopy-gen=true type RolloutProgressive struct { // +optional MandatoryDecisionGroups `json:",inline"` diff --git a/cluster/v1alpha1/zz_generated.deepcopy.go b/cluster/v1alpha1/zz_generated.deepcopy.go index fcdd36c0c..2be1d2833 100644 --- a/cluster/v1alpha1/zz_generated.deepcopy.go +++ b/cluster/v1alpha1/zz_generated.deepcopy.go @@ -1,13 +1,13 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1alpha1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -16,7 +16,6 @@ func (in *AddOnPlacementScore) DeepCopyInto(out *AddOnPlacementScore) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Status.DeepCopyInto(&out.Status) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddOnPlacementScore. @@ -40,7 +39,6 @@ func (in *AddOnPlacementScore) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AddOnPlacementScoreItem) DeepCopyInto(out *AddOnPlacementScoreItem) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddOnPlacementScoreItem. @@ -65,7 +63,6 @@ func (in *AddOnPlacementScoreList) DeepCopyInto(out *AddOnPlacementScoreList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddOnPlacementScoreList. @@ -105,7 +102,6 @@ func (in *AddOnPlacementScoreStatus) DeepCopyInto(out *AddOnPlacementScoreStatus in, out := &in.ValidUntil, &out.ValidUntil *out = (*in).DeepCopy() } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AddOnPlacementScoreStatus. @@ -124,7 +120,6 @@ func (in *ClusterClaim) DeepCopyInto(out *ClusterClaim) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Spec = in.Spec - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterClaim. @@ -157,7 +152,6 @@ func (in *ClusterClaimList) DeepCopyInto(out *ClusterClaimList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterClaimList. @@ -181,7 +175,6 @@ func (in *ClusterClaimList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterClaimSpec) DeepCopyInto(out *ClusterClaimSpec) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterClaimSpec. @@ -206,7 +199,6 @@ func (in *ClusterRolloutStatus) DeepCopyInto(out *ClusterRolloutStatus) { in, out := &in.TimeOutTime, &out.TimeOutTime *out = (*in).DeepCopy() } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterRolloutStatus. @@ -222,7 +214,6 @@ func (in *ClusterRolloutStatus) DeepCopy() *ClusterRolloutStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MandatoryDecisionGroup) DeepCopyInto(out *MandatoryDecisionGroup) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MandatoryDecisionGroup. @@ -243,7 +234,6 @@ func (in *MandatoryDecisionGroups) DeepCopyInto(out *MandatoryDecisionGroups) { *out = make([]MandatoryDecisionGroup, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MandatoryDecisionGroups. @@ -260,7 +250,6 @@ func (in *MandatoryDecisionGroups) DeepCopy() *MandatoryDecisionGroups { func (in *RolloutAll) DeepCopyInto(out *RolloutAll) { *out = *in out.Timeout = in.Timeout - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutAll. @@ -279,7 +268,6 @@ func (in *RolloutProgressive) DeepCopyInto(out *RolloutProgressive) { in.MandatoryDecisionGroups.DeepCopyInto(&out.MandatoryDecisionGroups) out.MaxConcurrency = in.MaxConcurrency out.Timeout = in.Timeout - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutProgressive. @@ -297,7 +285,6 @@ func (in *RolloutProgressivePerGroup) DeepCopyInto(out *RolloutProgressivePerGro *out = *in in.MandatoryDecisionGroups.DeepCopyInto(&out.MandatoryDecisionGroups) out.Timeout = in.Timeout - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutProgressivePerGroup. @@ -334,7 +321,6 @@ func (in *RolloutResult) DeepCopyInto(out *RolloutResult) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutResult. @@ -365,7 +351,6 @@ func (in *RolloutStrategy) DeepCopyInto(out *RolloutStrategy) { *out = new(RolloutProgressivePerGroup) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RolloutStrategy. @@ -381,7 +366,6 @@ func (in *RolloutStrategy) DeepCopy() *RolloutStrategy { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Timeout) DeepCopyInto(out *Timeout) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Timeout. diff --git a/hack/update-deepcopy.sh b/hack/update-deepcopy.sh index 0d7d06e62..a91d7cf25 100755 --- a/hack/update-deepcopy.sh +++ b/hack/update-deepcopy.sh @@ -7,9 +7,12 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-ge verify="${VERIFY:-}" +# cluster:v1alpha1 is generated in the Makefile target 'update-scripts' using controller-gen +# because gengo isn't respecting deepcopy-gen:false nor does it support generics +# Issue: https://github.com/kubernetes/gengo/issues/225 GOFLAGS="" bash ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \ open-cluster-management.io/api/generated \ open-cluster-management.io/api \ - "cluster:v1 cluster:v1alpha1 cluster:v1beta1 cluster:v1beta2 work:v1alpha1 work:v1 operator:v1 addon:v1alpha1" \ + "cluster:v1 cluster:v1beta1 cluster:v1beta2 work:v1alpha1 work:v1 operator:v1 addon:v1alpha1" \ --go-header-file ${SCRIPT_ROOT}/hack/empty.txt \ ${verify}