Skip to content

Commit e14c341

Browse files
committed
Generate MCAD clients using clientgen tools
Fixes #514
1 parent 6fb5e32 commit e14c341

File tree

24 files changed

+1200
-15
lines changed

24 files changed

+1200
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/output*/
2121
/_output*/
2222
/_output
23+
bin
2324

2425
# Emacs save files
2526
*~

Makefile

+70
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ $(LOCALBIN):
1313

1414
## Tool Versions
1515
CONTROLLER_TOOLS_VERSION ?= v0.9.2
16+
CODEGEN_VERSION ?= v0.20.15
1617

1718
## Tool Binaries
1819
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
20+
APPLYCONFIGURATION_GEN ?= $(LOCALBIN)/applyconfiguration-gen
21+
CLIENT_GEN ?= $(LOCALBIN)/client-gen
22+
LISTER_GEN ?= $(LOCALBIN)/lister-gen
23+
INFORMER_GEN ?= $(LOCALBIN)/informer-gen
1924

2025
# Reset branch name if this a Travis CI environment
2126
ifneq ($(strip $(TRAVIS_BRANCH)),)
@@ -70,12 +75,77 @@ init:
7075
verify-tag-name: print-global-variables
7176
# Check for invalid tag name
7277
t=${TAG} && [ $${#t} -le 128 ] || { echo "Target name $$t has 128 or more chars"; false; }
78+
.PHONY: generate-client ## Generate client packages
79+
generate-client: code-generator
80+
rm -rf pkg/client/clientset/versioned pkg/client/informers/externalversions pkg/client/listers/controller/v1beta1
81+
# TODO: add this back when the version of the tool has been updated and supports this executable
82+
# $(APPLYCONFIGURATION_GEN) \
83+
# --input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" \
84+
# --go-header-file="hack/boilerplate/boilerplate.go.txt" \
85+
# --output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/applyconfiguration" \
86+
# --trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
87+
$(CLIENT_GEN) \
88+
--input="pkg/apis/controller/v1beta1" \
89+
--input-base="github.com/project-codeflare/multi-cluster-app-dispatcher" \
90+
--go-header-file="hack/boilerplate/boilerplate.go.txt" \
91+
--clientset-name "versioned" \
92+
--output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/clientset" \
93+
--output-base="."
94+
# TODO: add the following line back once the tool has been upgraded
95+
# --trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
96+
$(LISTER_GEN) \
97+
--input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" \
98+
--go-header-file="hack/boilerplate/boilerplate.go.txt" \
99+
--output-base="." \
100+
--output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/listers"
101+
# TODO: add the following line back once the tool has been upgraded
102+
# --trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
103+
$(INFORMER_GEN) \
104+
--input-dirs="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" \
105+
--versioned-clientset-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/clientset/versioned" \
106+
--listers-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/listers" \
107+
--go-header-file="hack/boilerplate/boilerplate.go.txt" \
108+
--output-base="." \
109+
--output-package="github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/informers"
110+
# TODO: add the following line back once the tool has been upgraded
111+
# --trim-path-prefix "github.com/project-codeflare/multi-cluster-app-dispatcher"
112+
# TODO: remove the following lines once the tool has been upgraded and they are no longer needed.
113+
# The `mv` and `rm` are necessary as the generators write to the gihub.com/... path.
114+
mv -f github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/clientset/versioned pkg/client/clientset/versioned
115+
mv -f github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/informers/externalversions pkg/client/informers/externalversions
116+
mv -f github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/listers/controller/v1beta1 pkg/client/listers/controller/v1beta1
117+
rm -rf github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client
73118

74119
.PHONY: controller-gen
75120
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
76121
$(CONTROLLER_GEN): $(LOCALBIN)
77122
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
78123

124+
.PHONY: code-generator
125+
#TODO: add $(APPLYCONFIGURATION_GEN) as a dependency when the tool is supported
126+
code-generator: $(CLIENT_GEN) $(LISTER_GEN) $(INFORMER_GEN) $(CONTROLLER_GEN)
127+
128+
# TODO: enable this target once the tools is supported
129+
#.PHONY: applyconfiguration-gen
130+
#applyconfiguration-gen: $(APPLYCONFIGURATION_GEN)
131+
#$(APPLYCONFIGURATION_GEN): $(LOCALBIN)
132+
# test -s $(LOCALBIN)/applyconfiguration-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/applyconfiguration-gen@$(CODEGEN_VERSION)
133+
134+
.PHONY: client-gen
135+
client-gen: $(CLIENT_GEN)
136+
$(CLIENT_GEN): $(LOCALBIN)
137+
test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(CODEGEN_VERSION)
138+
139+
.PHONY: lister-gen
140+
lister-gen: $(LISTER_GEN)
141+
$(LISTER_GEN): $(LOCALBIN)
142+
test -s $(LOCALBIN)/lister-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(CODEGEN_VERSION)
143+
144+
.PHONY: informer-gen
145+
informer-gen: $(INFORMER_GEN)
146+
$(INFORMER_GEN): $(LOCALBIN)
147+
test -s $(LOCALBIN)/informer-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(CODEGEN_VERSION)
148+
79149
.PHONY: manifests
80150
manifests: controller-gen ## Generate CustomResourceDefinition objects.
81151
$(CONTROLLER_GEN) crd:allowDangerousTypes=true paths="./pkg/apis/..." output:crd:artifacts:config=config/crd/bases

hack/boilerplate/boilerplate.go.txt

-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
/*
2-
Copyright YEAR The Kubernetes Authors.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
16-
/*
172
Copyright 2019, 2021, 2022, YEAR The Multi-Cluster App Dispatcher Authors.
183

194
Licensed under the Apache License, Version 2.0 (the "License");

pkg/apis/controller/v1beta1/appwrapper.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const AppWrapperPlural string = "appwrappers"
2828
// which AppWrapper it belongs to.
2929
const AppWrapperAnnotationKey = "appwrapper.mcad.ibm.com/appwrapper-name"
3030

31+
// +genclient
3132
// +kubebuilder:object:root=true
3233
// +kubebuilder:subresource:status
3334
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/client/client_factory.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2019, 2021, 2022, 2023 The Multi-Cluster App Dispatcher Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package client
17+
18+
import (
19+
"k8s.io/apimachinery/pkg/runtime"
20+
"k8s.io/apimachinery/pkg/runtime/serializer"
21+
"k8s.io/client-go/rest"
22+
23+
arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
24+
)
25+
26+
func NewClient(cfg *rest.Config) (*rest.RESTClient, *runtime.Scheme, error) {
27+
scheme := runtime.NewScheme()
28+
if err := arbv1.AddToScheme(scheme); err != nil {
29+
return nil, nil, err
30+
}
31+
32+
config := *cfg
33+
config.GroupVersion = &arbv1.SchemeGroupVersion
34+
config.APIPath = "/apis"
35+
config.ContentType = runtime.ContentTypeJSON
36+
config.NegotiatedSerializer = serializer.WithoutConversionCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)}
37+
38+
client, err := rest.RESTClientFor(&config)
39+
if err != nil {
40+
return nil, nil, err
41+
}
42+
43+
return client, scheme, nil
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Package controller_versioned provides a set of Appwrapper clients to be used with interacting with AppWrapper CRDS.
2+
// RC4
3+
// Deprecated: controller_versioned has been replaced by the versioned as that package is generated using the client gen tool.
4+
// controller_versioned interfaces and methods should not be used except for compatibility. It will be removed in future versions.
5+
//
6+
// This package is frozen and no new functionality will be added.
7+
package controller_versioned

pkg/client/clientset/versioned/clientset.go

+97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/doc.go

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/fake/clientset_generated.go

+82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)