Skip to content

Commit 16871c5

Browse files
zoumoColdsteelRail
andauthored
feat: update operating apis and change generation tools (#13)
* add makefile * add makefile * make file * feat: generate code by kube-codegenerator * generate manifests for api dirs * ci: fix license check * remove defaulter * update pd api --------- Co-authored-by: ColdsteelRail <[email protected]>
1 parent b0e4f15 commit 16871c5

27 files changed

+7385
-135
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
# Output of the go coverage tool, specifically when used with LiteIDE
1515
*.out
16+
bin/
1617

1718
# Dependency directories (remove the comment below to include it)
1819
vendor/
1920

2021
# Go workspace file
2122
go.work
2223
go.work.sum
24+
25+
__output

.idea/workspace.xml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenserc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ header:
6060
- '**/PROJECT'
6161
- '**/Dockerfile'
6262
- '**/.dockerignore'
63-
comment: never
64-
license-location-threshold: 100
63+
comment: on-failure
64+
license-location-threshold: 200

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
LOCALBIN ?= $(shell pwd)/bin
2+
$(LOCALBIN):
3+
mkdir -p $(LOCALBIN)
4+
CONTROLLER_TOOLS_VERSION ?= v0.15.0
5+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
6+
CODEGEN = $(LOCALBIN)/kube-codegen
7+
8+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
9+
$(CONTROLLER_GEN): $(LOCALBIN)
10+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
11+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
12+
13+
manifests: controller-gen
14+
@for dir in apps cluster; do \
15+
mkdir -p "config/crd/$$dir"; \
16+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./$$dir/..." output:crd:artifacts:config="config/crd/$$dir"; \
17+
done
18+
19+
generate: codegen controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
20+
#@scripts/generate_client.sh
21+
# $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
22+
$(CODEGEN) code-gen --go-header-file=./hack/boilerplate.go.txt --code-generator-version=v0.27.16 --apis-path=./ --generators=deepcopy,register
23+
24+
codegen: $(CODEGEN) # Download kube-codegen locally if necessary. If wrong version is installed, it will be overwritten.
25+
$(CODEGEN):
26+
ifeq (, $(shell command -v $(CODEGEN)))
27+
@cd $(shell mktemp -d) && \
28+
git clone https://github.com/zoumo/kube-codegen.git && \
29+
cd kube-codegen && \
30+
GOBIN=$(LOCALBIN) go install ./cmd/kube-codegen
31+
endif

apps/v1alpha1/collaset_types.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ type ByPartition struct {
168168
Partition *int32 `json:"partition,omitempty"`
169169
}
170170

171-
type ByLabel struct {
172-
}
171+
type ByLabel struct{}
173172

174173
// RollingUpdateCollaSetStrategy is used to communicate parameter for rolling update.
175174
type RollingUpdateCollaSetStrategy struct {
@@ -272,12 +271,10 @@ type CollaSetCondition struct {
272271
Message string `json:"message,omitempty"`
273272
}
274273

275-
// +kubebuilder:object:root=true
276-
// +kubebuilder:subresource:status
277-
278-
// CollaSet is the Schema for the collasets API
279274
// +k8s:openapi-gen=true
275+
// +genclient
280276
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
277+
// +kubebuilder:object:root=true
281278
// +kubebuilder:resource:shortName=cls
282279
// +kubebuilder:subresource:status
283280
// +kubebuilder:printcolumn:name="DESIRED",type="integer",JSONPath=".spec.replicas",description="The desired number of pods."
@@ -290,6 +287,8 @@ type CollaSetCondition struct {
290287
// +kubebuilder:printcolumn:name="UPDATED_REVISION",type="string",JSONPath=".status.updatedRevision",description="The updated revision."
291288
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
292289
// +resource:path=collasets
290+
291+
// CollaSet is the Schema for the collasets API
293292
type CollaSet struct {
294293
metav1.TypeMeta `json:",inline"`
295294
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -298,15 +297,12 @@ type CollaSet struct {
298297
Status CollaSetStatus `json:"status,omitempty"`
299298
}
300299

301-
//+kubebuilder:object:root=true
300+
// +kubebuilder:object:root=true
301+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
302302

303303
// CollaSetList contains a list of CollaSet
304304
type CollaSetList struct {
305305
metav1.TypeMeta `json:",inline"`
306306
metav1.ListMeta `json:"metadata,omitempty"`
307307
Items []CollaSet `json:"items"`
308308
}
309-
310-
func init() {
311-
SchemeBuilder.Register(&CollaSet{}, &CollaSetList{})
312-
}
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build !ignore_autogenerated
2-
// +build !ignore_autogenerated
3-
41
/*
52
Copyright The Karbour Authors.
63
@@ -17,17 +14,10 @@ See the License for the specific language governing permissions and
1714
limitations under the License.
1815
*/
1916

20-
// Code generated by defaulter-gen. DO NOT EDIT.
21-
22-
package v1beta1
23-
24-
import (
25-
runtime "k8s.io/apimachinery/pkg/runtime"
26-
)
17+
// +k8s:openapi-gen=true
18+
// +k8s:deepcopy-gen=package
19+
// +k8s:defaulter-gen=TypeMeta
20+
// +groupName=apps.kusionstack.io
2721

28-
// RegisterDefaults adds defaulters functions to the given scheme.
29-
// Public to allow building arbitrary schemes.
30-
// All generated defaulters are covering - they call all nested defaulters.
31-
func RegisterDefaults(scheme *runtime.Scheme) error {
32-
return nil
33-
}
22+
// Package v1alpha1 Package v1alpha1 is the v1alpha1 version of the API.
23+
package v1alpha1

apps/v1alpha1/groupversion_info.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

apps/v1alpha1/operationjob_types.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@ type OpsStatus struct {
135135
Message string `json:"message,omitempty"`
136136
}
137137

138-
// +kubebuilder:object:root=true
139-
// +kubebuilder:subresource:status
140-
141138
// +k8s:openapi-gen=true
139+
// +genclient
142140
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
141+
// +kubebuilder:object:root=true
143142
// +kubebuilder:resource:shortName=oj
144143
// +kubebuilder:subresource:status
145144
// +kubebuilder:printcolumn:name="PROGRESS",type="string",JSONPath=".status.progress"
@@ -154,15 +153,12 @@ type OperationJob struct {
154153
Status OperationJobStatus `json:"status,omitempty"`
155154
}
156155

157-
//+kubebuilder:object:root=true
156+
// +kubebuilder:object:root=true
157+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
158158

159159
// OperationJobList contains a list of OperationJob
160160
type OperationJobList struct {
161161
metav1.TypeMeta `json:",inline"`
162162
metav1.ListMeta `json:"metadata,omitempty"`
163163
Items []OperationJob `json:"items"`
164164
}
165-
166-
func init() {
167-
SchemeBuilder.Register(&OperationJob{}, &OperationJobList{})
168-
}

apps/v1alpha1/poddecoration_types.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ type PodDecorationPodTemplate struct {
8585
}
8686

8787
type PodDecorationPodTemplateMeta struct {
88-
8988
// patch pod metadata policy, Default is "Retain"
9089
PatchPolicy MetadataPatchPolicy `json:"patchPolicy"`
9190

@@ -257,15 +256,12 @@ type PodDecorationCondition struct {
257256
Message string `json:"message,omitempty"`
258257
}
259258

260-
// +genclient
261-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
262-
263-
// PodDecoration is the Schema for the poddecorations API
264259
// +k8s:openapi-gen=true
260+
// +genclient
265261
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
266-
// +kubebuilder:resource:shortName=pd
262+
// +kubebuilder:object:root=true
267263
// +kubebuilder:subresource:status
268-
// +kubebuilder:printcolumn:name="EFFECTIVE",type="boolean",JSONPath=".status.isEffective",description="The number of pods updated."
264+
// +kubebuilder:resource:shortName=pd
269265
// +kubebuilder:printcolumn:name="MATCHED",type="integer",JSONPath=".status.matchedPods",description="The number of selected pods."
270266
// +kubebuilder:printcolumn:name="INJECTED",type="integer",JSONPath=".status.injectedPods",description="The number of injected pods."
271267
// +kubebuilder:printcolumn:name="UPDATED",type="integer",JSONPath=".status.updatedPods",description="The number of updated pods."
@@ -274,6 +270,8 @@ type PodDecorationCondition struct {
274270
// +kubebuilder:printcolumn:name="UPDATED_REVISION",type="string",JSONPath=".status.updatedRevision",description="The updated revision."
275271
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
276272
// +resource:path=poddecorations
273+
274+
// PodDecoration is the Schema for the poddecorations API
277275
type PodDecoration struct {
278276
metav1.TypeMeta `json:",inline"`
279277
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -282,6 +280,7 @@ type PodDecoration struct {
282280
Status PodDecorationStatus `json:"status,omitempty"`
283281
}
284282

283+
// +kubebuilder:object:root=true
285284
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
286285

287286
// PodDecorationList contains a list of PodDecoration
@@ -290,7 +289,3 @@ type PodDecorationList struct {
290289
metav1.ListMeta `json:"metadata,omitempty"`
291290
Items []PodDecoration `json:"items"`
292291
}
293-
294-
func init() {
295-
SchemeBuilder.Register(&PodDecoration{}, &PodDecorationList{})
296-
}

0 commit comments

Comments
 (0)