Skip to content

Commit

Permalink
Add v1beta2 version and implement KThreesControlPlaneTemplate (#88)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti authored May 9, 2024
1 parent ae3b216 commit 7d52020
Show file tree
Hide file tree
Showing 85 changed files with 6,006 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version-file: "./go.mod"
go-version-file: go.mod
cache: true

- name: ${{ matrix.target }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:

- uses: actions/setup-go@v4
with:
go-version: "${{ env.GO_VERSION }}"
go-version-file: go.mod
cache: true

- uses: actions/cache@v3
Expand Down
35 changes: 31 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ CONTROLLER_GEN_VER := v0.14.0
CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER)

# Sync
CONVERSION_GEN_VER := v0.29.0
CONVERSION_GEN_BIN := conversion-gen
CONVERSION_GEN := $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN)-$(CONVERSION_GEN_VER)

# Sync to github.com/drone/envsubst/v2 in https://github.com/kubernetes-sigs/cluster-api/blob/v{VERSION}/go.mod
ENVSUBST_VER := v2.0.0-20210730161058-179042472c46
ENVSUBST_BIN := envsubst
Expand Down Expand Up @@ -154,7 +159,7 @@ test-common:
all-bootstrap: manager-bootstrap

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

# Build manager binary
Expand All @@ -180,7 +185,7 @@ deploy-bootstrap: manifests-bootstrap

# Generate manifests e.g. CRD, RBAC etc.
manifests-bootstrap: $(KUSTOMIZE) $(CONTROLLER_GEN)
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=bootstrap/config/crd/bases output:rbac:dir=bootstrap/config/rbac
$(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

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

generate-bootstrap-conversions: $(CONVERSION_GEN)
$(CONVERSION_GEN) \
--input-dirs=./bootstrap/api/v1beta1 \
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \
--build-tag=ignore_autogenerated_conversions \
--output-file-base=zz_generated.conversion \
--output-base=./ \
--go-header-file=./hack/boilerplate.go.txt

# Build the docker image
docker-build-bootstrap: manager-bootstrap ## Build bootstrap
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}
Expand All @@ -201,7 +215,7 @@ docker-push-bootstrap: ## Push bootstrap
all-controlplane: manager-controlplane

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

.PHONY: docker-build-e2e
Expand Down Expand Up @@ -244,7 +258,7 @@ deploy-controlplane: manifests-controlplane

# Generate manifests e.g. CRD, RBAC etc.
manifests-controlplane: $(KUSTOMIZE) $(CONTROLLER_GEN)
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook crd paths="./..." output:crd:artifacts:config=controlplane/config/crd/bases output:rbac:dir=controlplane/config/rbac
$(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

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

generate-controlplane-conversions: $(CONVERSION_GEN)
$(CONVERSION_GEN) \
--input-dirs=./controlplane/api/v1beta1 \
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \
--extra-peer-dirs=github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta1 \
--build-tag=ignore_autogenerated_conversions \
--output-file-base=zz_generated.conversion \
--output-base=./ \
--go-header-file=./hack/boilerplate.go.txt

docker-build-controlplane: manager-controlplane ## Build control-plane
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)

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

$(CONTROLLER_GEN): ## Build controller-gen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/controller-gen $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)

$(CONVERSION_GEN): ## Build conversion-gen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) k8s.io/code-generator/cmd/conversion-gen $(CONVERSION_GEN_BIN) $(CONVERSION_GEN_VER)
6 changes: 6 additions & 0 deletions bootstrap/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ resources:
- group: bootstrap
kind: KThreesConfig
version: v1beta1
- group: bootstrap
kind: KThreesConfig
version: v1beta2
- group: bootstrap
kind: KThreesConfigTemplate
version: v1beta1
- group: bootstrap
kind: KThreesConfigTemplate
version: v1beta2
version: "2"
94 changes: 94 additions & 0 deletions bootstrap/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1beta1

import (
"fmt"

"sigs.k8s.io/controller-runtime/pkg/conversion"

cabp3v1 "github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta2"
)

// ConvertTo converts the v1beta1 KThreesConfig receiver to a v1beta2 KThreesConfig.
func (c *KThreesConfig) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*cabp3v1.KThreesConfig)
if err := autoConvert_v1beta1_KThreesConfig_To_v1beta2_KThreesConfig(c, dst, nil); err != nil {
return fmt.Errorf("converting KThreesConfig v1beta1 to v1beta2: %w", err)
}
return nil
}

// ConvertFrom converts the v1beta1 KThreesConfig receiver from a v1beta2 KThreesConfig.
func (c *KThreesConfig) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*cabp3v1.KThreesConfig)
if err := autoConvert_v1beta2_KThreesConfig_To_v1beta1_KThreesConfig(src, c, nil); err != nil {
return fmt.Errorf("converting KThreesConfig v1beta1 from v1beta2: %w", err)
}
return nil
}

// ConvertTo converts the v1beta1 KThreesConfigList receiver to a v1beta2 KThreesConfigList.
func (c *KThreesConfigList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*cabp3v1.KThreesConfigList)
if err := autoConvert_v1beta1_KThreesConfigList_To_v1beta2_KThreesConfigList(c, dst, nil); err != nil {
return fmt.Errorf("converting KThreesConfigList v1beta1 to v1beta2: %w", err)
}
return nil
}

// ConvertFrom converts the v1beta1 KThreesConfigList receiver from a v1beta2 KThreesConfigList.
func (c *KThreesConfigList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*cabp3v1.KThreesConfigList)
if err := autoConvert_v1beta2_KThreesConfigList_To_v1beta1_KThreesConfigList(src, c, nil); err != nil {
return fmt.Errorf("converting KThreesConfigList v1beta1 from v1beta2: %w", err)
}
return nil
}

// ConvertTo converts the v1beta1 KThreesConfigTemplate receiver to a v1beta2 KThreesConfigTemplate.
func (r *KThreesConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*cabp3v1.KThreesConfigTemplate)
if err := autoConvert_v1beta1_KThreesConfigTemplate_To_v1beta2_KThreesConfigTemplate(r, dst, nil); err != nil {
return fmt.Errorf("converting KThreesConfigTemplate v1beta1 to v1beta2: %w", err)
}
return nil
}

// ConvertFrom converts the v1beta1 KThreesConfigTemplate receiver from a v1beta2 KThreesConfigTemplate.
func (r *KThreesConfigTemplate) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*cabp3v1.KThreesConfigTemplate)
if err := autoConvert_v1beta2_KThreesConfigTemplate_To_v1beta1_KThreesConfigTemplate(src, r, nil); err != nil {
return fmt.Errorf("converting KThreesConfigTemplate v1beta1 from v1beta2: %w", err)
}
return nil
}

// ConvertTo converts the v1beta1 KThreesConfigTemplateList receiver to a v1beta2 KThreesConfigTemplateList.
func (r *KThreesConfigTemplateList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*cabp3v1.KThreesConfigTemplateList)
if err := autoConvert_v1beta1_KThreesConfigTemplateList_To_v1beta2_KThreesConfigTemplateList(r, dst, nil); err != nil {
return fmt.Errorf("converting KThreesConfigTemplateList v1beta1 to v1beta2: %w", err)
}
return nil
}

// ConvertFrom converts the v1beta1 KThreesConfigTemplateList receiver from a v1beta2 KThreesConfigTemplateList.
func (r *KThreesConfigTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*cabp3v1.KThreesConfigTemplateList)
if err := autoConvert_v1beta2_KThreesConfigTemplateList_To_v1beta1_KThreesConfigTemplateList(src, r, nil); err != nil {
return fmt.Errorf("converting KThreesConfigTemplateList v1beta1 from v1beta2: %w", err)
}
return nil
}
45 changes: 45 additions & 0 deletions bootstrap/api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1beta1

import (
"testing"

. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/runtime"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"

cabp3v1 "github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta2"
)

func TestFuzzyConversion(t *testing.T) {
g := NewWithT(t)
scheme := runtime.NewScheme()
g.Expect(AddToScheme(scheme)).To(Succeed())
g.Expect(cabp3v1.AddToScheme(scheme)).To(Succeed())

t.Run("for KThreesConfig", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &cabp3v1.KThreesConfig{},
Spoke: &KThreesConfig{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
}))
t.Run("for KThreesConfigTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &cabp3v1.KThreesConfigTemplate{},
Spoke: &KThreesConfigTemplate{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
}))
}
22 changes: 22 additions & 0 deletions bootstrap/api/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1beta1 contains API Schema definitions for the bootstrap v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=bootstrap.cluster.x-k8s.io
// +k8s:defaulter-gen=TypeMeta
// +k8s:conversion-gen=github.com/k3s-io/cluster-api-k3s/bootstrap/api/v1beta2
package v1beta1
10 changes: 4 additions & 6 deletions bootstrap/api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,9 +12,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

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

import (
Expand All @@ -33,4 +28,7 @@ var (

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// localSchemeBuilder is used by the conversion-gen tool.
localSchemeBuilder = SchemeBuilder.SchemeBuilder
)
1 change: 0 additions & 1 deletion bootstrap/api/v1beta1/kthreesconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

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

// KThreesConfigSpec defines the desired state of KThreesConfig.
Expand Down
Loading

0 comments on commit 7d52020

Please sign in to comment.