Skip to content

Commit 7d52020

Browse files
authored
Add v1beta2 version and implement KThreesControlPlaneTemplate (#88)
Signed-off-by: Andrea Mazzotti <[email protected]>
1 parent ae3b216 commit 7d52020

File tree

85 files changed

+6006
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+6006
-351
lines changed

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- uses: actions/setup-go@v4
2626
with:
27-
go-version-file: "./go.mod"
27+
go-version-file: go.mod
2828
cache: true
2929

3030
- name: ${{ matrix.target }}

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101

102102
- uses: actions/setup-go@v4
103103
with:
104-
go-version: "${{ env.GO_VERSION }}"
104+
go-version-file: go.mod
105105
cache: true
106106

107107
- uses: actions/cache@v3

Makefile

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ CONTROLLER_GEN_VER := v0.14.0
5858
CONTROLLER_GEN_BIN := controller-gen
5959
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)
6060

61+
# Sync
62+
CONVERSION_GEN_VER := v0.29.0
63+
CONVERSION_GEN_BIN := conversion-gen
64+
CONVERSION_GEN := $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN)-$(CONVERSION_GEN_VER)
65+
6166
# Sync to github.com/drone/envsubst/v2 in https://github.com/kubernetes-sigs/cluster-api/blob/v{VERSION}/go.mod
6267
ENVSUBST_VER := v2.0.0-20210730161058-179042472c46
6368
ENVSUBST_BIN := envsubst
@@ -154,7 +159,7 @@ test-common:
154159
all-bootstrap: manager-bootstrap
155160

156161
# Run tests
157-
test-bootstrap: envtest generate-bootstrap lint manifests-bootstrap
162+
test-bootstrap: envtest generate-bootstrap generate-bootstrap-conversions lint manifests-bootstrap
158163
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(TOOLS_BIN_DIR) -p path)" go test $(shell pwd)/bootstrap/... -coverprofile cover.out
159164

160165
# Build manager binary
@@ -180,7 +185,7 @@ deploy-bootstrap: manifests-bootstrap
180185

181186
# Generate manifests e.g. CRD, RBAC etc.
182187
manifests-bootstrap: $(KUSTOMIZE) $(CONTROLLER_GEN)
183-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=bootstrap/config/crd/bases output:rbac:dir=bootstrap/config/rbac
188+
$(CONTROLLER_GEN) paths=./bootstrap/... rbac:roleName=manager-role crd webhook output:crd:artifacts:config=bootstrap/config/crd/bases output:rbac:dir=bootstrap/config/rbac output:webhook:dir=bootstrap/config/webhook
184189

185190
release-bootstrap:$(RELEASE_DIR) manifests-bootstrap ## Release bootstrap
186191
cd bootstrap/config/manager && $(KUSTOMIZE) edit set image controller=${BOOTSTRAP_IMG}:${BOOTSTRAP_IMG_TAG}
@@ -190,6 +195,15 @@ release-bootstrap:$(RELEASE_DIR) manifests-bootstrap ## Release bootstrap
190195
generate-bootstrap: $(CONTROLLER_GEN)
191196
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="$(shell pwd)/bootstrap/..."
192197

198+
generate-bootstrap-conversions: $(CONVERSION_GEN)
199+
$(CONVERSION_GEN) \
200+
--input-dirs=./bootstrap/api/v1beta1 \
201+
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \
202+
--build-tag=ignore_autogenerated_conversions \
203+
--output-file-base=zz_generated.conversion \
204+
--output-base=./ \
205+
--go-header-file=./hack/boilerplate.go.txt
206+
193207
# Build the docker image
194208
docker-build-bootstrap: manager-bootstrap ## Build bootstrap
195209
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg TARGETARCH=$(ARCH) --build-arg package=./bootstrap/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${BOOTSTRAP_IMG}:${BOOTSTRAP_IMG_TAG}
@@ -201,7 +215,7 @@ docker-push-bootstrap: ## Push bootstrap
201215
all-controlplane: manager-controlplane
202216

203217
# Run tests
204-
test-controlplane: envtest generate-controlplane lint manifests-controlplane
218+
test-controlplane: envtest generate-controlplane generate-controlplane-conversions lint manifests-controlplane
205219
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(TOOLS_BIN_DIR) -p path)" go test $(shell pwd)/controlplane/... -coverprofile cover.out
206220

207221
.PHONY: docker-build-e2e
@@ -244,7 +258,7 @@ deploy-controlplane: manifests-controlplane
244258

245259
# Generate manifests e.g. CRD, RBAC etc.
246260
manifests-controlplane: $(KUSTOMIZE) $(CONTROLLER_GEN)
247-
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook crd paths="./..." output:crd:artifacts:config=controlplane/config/crd/bases output:rbac:dir=controlplane/config/rbac
261+
$(CONTROLLER_GEN) paths=./controlplane/... rbac:roleName=manager-role webhook crd output:crd:artifacts:config=controlplane/config/crd/bases output:rbac:dir=controlplane/config/rbac output:webhook:dir=controlplane/config/webhook
248262

249263
release-controlplane: $(RELEASE_DIR) manifests-controlplane ## Release control-plane
250264
cd controlplane/config/manager && $(KUSTOMIZE) edit set image controller=${CONTROLPLANE_IMG}:$(CONTROLPLANE_IMG_TAG)
@@ -253,6 +267,16 @@ release-controlplane: $(RELEASE_DIR) manifests-controlplane ## Release control-p
253267
generate-controlplane: $(CONTROLLER_GEN)
254268
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="$(shell pwd)/controlplane/..."
255269

270+
generate-controlplane-conversions: $(CONVERSION_GEN)
271+
$(CONVERSION_GEN) \
272+
--input-dirs=./controlplane/api/v1beta1 \
273+
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \
274+
--extra-peer-dirs=github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta1 \
275+
--build-tag=ignore_autogenerated_conversions \
276+
--output-file-base=zz_generated.conversion \
277+
--output-base=./ \
278+
--go-header-file=./hack/boilerplate.go.txt
279+
256280
docker-build-controlplane: manager-controlplane ## Build control-plane
257281
DOCKER_BUILDKIT=1 docker build --build-arg builder_image=$(GO_CONTAINER_IMAGE) --build-arg goproxy=$(GOPROXY) --build-arg TARGETARCH=$(ARCH) --build-arg package=./controlplane/main.go --build-arg ldflags="$(LDFLAGS)" . -t ${CONTROLPLANE_IMG}:$(CONTROLPLANE_IMG_TAG)
258282

@@ -317,3 +341,6 @@ $(KUSTOMIZE): ## Put kustomize into tools folder.
317341

318342
$(CONTROLLER_GEN): ## Build controller-gen from tools folder.
319343
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/controller-gen $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
344+
345+
$(CONVERSION_GEN): ## Build conversion-gen from tools folder.
346+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) k8s.io/code-generator/cmd/conversion-gen $(CONVERSION_GEN_BIN) $(CONVERSION_GEN_VER)

bootstrap/PROJECT

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ resources:
44
- group: bootstrap
55
kind: KThreesConfig
66
version: v1beta1
7+
- group: bootstrap
8+
kind: KThreesConfig
9+
version: v1beta2
710
- group: bootstrap
811
kind: KThreesConfigTemplate
912
version: v1beta1
13+
- group: bootstrap
14+
kind: KThreesConfigTemplate
15+
version: v1beta2
1016
version: "2"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
package v1beta1
15+
16+
import (
17+
"fmt"
18+
19+
"sigs.k8s.io/controller-runtime/pkg/conversion"
20+
21+
cabp3v1 "github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta2"
22+
)
23+
24+
// ConvertTo converts the v1beta1 KThreesConfig receiver to a v1beta2 KThreesConfig.
25+
func (c *KThreesConfig) ConvertTo(dstRaw conversion.Hub) error {
26+
dst := dstRaw.(*cabp3v1.KThreesConfig)
27+
if err := autoConvert_v1beta1_KThreesConfig_To_v1beta2_KThreesConfig(c, dst, nil); err != nil {
28+
return fmt.Errorf("converting KThreesConfig v1beta1 to v1beta2: %w", err)
29+
}
30+
return nil
31+
}
32+
33+
// ConvertFrom converts the v1beta1 KThreesConfig receiver from a v1beta2 KThreesConfig.
34+
func (c *KThreesConfig) ConvertFrom(srcRaw conversion.Hub) error {
35+
src := srcRaw.(*cabp3v1.KThreesConfig)
36+
if err := autoConvert_v1beta2_KThreesConfig_To_v1beta1_KThreesConfig(src, c, nil); err != nil {
37+
return fmt.Errorf("converting KThreesConfig v1beta1 from v1beta2: %w", err)
38+
}
39+
return nil
40+
}
41+
42+
// ConvertTo converts the v1beta1 KThreesConfigList receiver to a v1beta2 KThreesConfigList.
43+
func (c *KThreesConfigList) ConvertTo(dstRaw conversion.Hub) error {
44+
dst := dstRaw.(*cabp3v1.KThreesConfigList)
45+
if err := autoConvert_v1beta1_KThreesConfigList_To_v1beta2_KThreesConfigList(c, dst, nil); err != nil {
46+
return fmt.Errorf("converting KThreesConfigList v1beta1 to v1beta2: %w", err)
47+
}
48+
return nil
49+
}
50+
51+
// ConvertFrom converts the v1beta1 KThreesConfigList receiver from a v1beta2 KThreesConfigList.
52+
func (c *KThreesConfigList) ConvertFrom(srcRaw conversion.Hub) error {
53+
src := srcRaw.(*cabp3v1.KThreesConfigList)
54+
if err := autoConvert_v1beta2_KThreesConfigList_To_v1beta1_KThreesConfigList(src, c, nil); err != nil {
55+
return fmt.Errorf("converting KThreesConfigList v1beta1 from v1beta2: %w", err)
56+
}
57+
return nil
58+
}
59+
60+
// ConvertTo converts the v1beta1 KThreesConfigTemplate receiver to a v1beta2 KThreesConfigTemplate.
61+
func (r *KThreesConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
62+
dst := dstRaw.(*cabp3v1.KThreesConfigTemplate)
63+
if err := autoConvert_v1beta1_KThreesConfigTemplate_To_v1beta2_KThreesConfigTemplate(r, dst, nil); err != nil {
64+
return fmt.Errorf("converting KThreesConfigTemplate v1beta1 to v1beta2: %w", err)
65+
}
66+
return nil
67+
}
68+
69+
// ConvertFrom converts the v1beta1 KThreesConfigTemplate receiver from a v1beta2 KThreesConfigTemplate.
70+
func (r *KThreesConfigTemplate) ConvertFrom(srcRaw conversion.Hub) error {
71+
src := srcRaw.(*cabp3v1.KThreesConfigTemplate)
72+
if err := autoConvert_v1beta2_KThreesConfigTemplate_To_v1beta1_KThreesConfigTemplate(src, r, nil); err != nil {
73+
return fmt.Errorf("converting KThreesConfigTemplate v1beta1 from v1beta2: %w", err)
74+
}
75+
return nil
76+
}
77+
78+
// ConvertTo converts the v1beta1 KThreesConfigTemplateList receiver to a v1beta2 KThreesConfigTemplateList.
79+
func (r *KThreesConfigTemplateList) ConvertTo(dstRaw conversion.Hub) error {
80+
dst := dstRaw.(*cabp3v1.KThreesConfigTemplateList)
81+
if err := autoConvert_v1beta1_KThreesConfigTemplateList_To_v1beta2_KThreesConfigTemplateList(r, dst, nil); err != nil {
82+
return fmt.Errorf("converting KThreesConfigTemplateList v1beta1 to v1beta2: %w", err)
83+
}
84+
return nil
85+
}
86+
87+
// ConvertFrom converts the v1beta1 KThreesConfigTemplateList receiver from a v1beta2 KThreesConfigTemplateList.
88+
func (r *KThreesConfigTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
89+
src := srcRaw.(*cabp3v1.KThreesConfigTemplateList)
90+
if err := autoConvert_v1beta2_KThreesConfigTemplateList_To_v1beta1_KThreesConfigTemplateList(src, r, nil); err != nil {
91+
return fmt.Errorf("converting KThreesConfigTemplateList v1beta1 from v1beta2: %w", err)
92+
}
93+
return nil
94+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
package v1beta1
15+
16+
import (
17+
"testing"
18+
19+
. "github.com/onsi/gomega"
20+
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
23+
24+
cabp3v1 "github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta2"
25+
)
26+
27+
func TestFuzzyConversion(t *testing.T) {
28+
g := NewWithT(t)
29+
scheme := runtime.NewScheme()
30+
g.Expect(AddToScheme(scheme)).To(Succeed())
31+
g.Expect(cabp3v1.AddToScheme(scheme)).To(Succeed())
32+
33+
t.Run("for KThreesConfig", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
34+
Scheme: scheme,
35+
Hub: &cabp3v1.KThreesConfig{},
36+
Spoke: &KThreesConfig{},
37+
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
38+
}))
39+
t.Run("for KThreesConfigTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
40+
Scheme: scheme,
41+
Hub: &cabp3v1.KThreesConfigTemplate{},
42+
Spoke: &KThreesConfigTemplate{},
43+
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
44+
}))
45+
}

bootstrap/api/v1beta1/doc.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
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+
17+
// Package v1beta1 contains API Schema definitions for the bootstrap v1beta1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=bootstrap.cluster.x-k8s.io
20+
// +k8s:defaulter-gen=TypeMeta
21+
// +k8s:conversion-gen=github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta2
22+
package v1beta1

bootstrap/api/v1beta1/groupversion_info.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/*
2-
3-
42
Licensed under the Apache License, Version 2.0 (the "License");
53
you may not use this file except in compliance with the License.
64
You may obtain a copy of the License at
75
8-
http://www.apache.org/licenses/LICENSE-2.0
6+
http://www.apache.org/licenses/LICENSE-2.0
97
108
Unless required by applicable law or agreed to in writing, software
119
distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,9 +12,6 @@ See the License for the specific language governing permissions and
1412
limitations under the License.
1513
*/
1614

17-
// Package v1beta1 contains API Schema definitions for the bootstrap v1beta1 API group
18-
// +kubebuilder:object:generate=true
19-
// +groupName=bootstrap.cluster.x-k8s.io
2015
package v1beta1
2116

2217
import (
@@ -33,4 +28,7 @@ var (
3328

3429
// AddToScheme adds the types in this group-version to the given scheme.
3530
AddToScheme = SchemeBuilder.AddToScheme
31+
32+
// localSchemeBuilder is used by the conversion-gen tool.
33+
localSchemeBuilder = SchemeBuilder.SchemeBuilder
3634
)

bootstrap/api/v1beta1/kthreesconfig_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2222
)
2323

24-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2524
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2625

2726
// KThreesConfigSpec defines the desired state of KThreesConfig.

0 commit comments

Comments
 (0)