Skip to content

Commit

Permalink
🐛 Use controller-runtime for deepcopy generation for cluster:v1alpha1 (
Browse files Browse the repository at this point in the history
…open-cluster-management-io#291)

* Revert "Fix: run `make update` fail because deepcopy doesn't support generic type. (open-cluster-management-io#288)"

This reverts commit ae208c8.

Signed-off-by: Dale Haiducek <[email protected]>

* Use `controller-gen` for deepcopy cluster:v1alpha1

GenGo isn't respecting the `+k8s:deepcopy-gen=false` tag to skip
generation for the generic type

Signed-off-by: Dale Haiducek <[email protected]>

---------

Signed-off-by: Dale Haiducek <[email protected]>
  • Loading branch information
dhaiducek authored and haoqing0110 committed Nov 24, 2023
1 parent b244f2a commit 0c16273
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 36 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cluster/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions cluster/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions cluster/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions cluster/v1alpha1/types_addonplacementscore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions cluster/v1alpha1/types_rolloutstrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"`
Expand All @@ -94,7 +88,6 @@ type RolloutProgressivePerGroup struct {
}

// RolloutProgressive is a RolloutStrategy Type
// +k8s:deepcopy-gen=true
type RolloutProgressive struct {
// +optional
MandatoryDecisionGroups `json:",inline"`
Expand Down
22 changes: 3 additions & 19 deletions cluster/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion hack/update-deepcopy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 0c16273

Please sign in to comment.