Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: new v1beta1 api version for control plane #230

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))
CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen

CONVERSION_GEN_VER := v0.25.0
CONVERSION_GEN_VER := v0.28.0
CONVERSION_GEN_BIN := conversion-gen
# We are intentionally using the binary without version suffix, to avoid the version
# in generated files.
Expand Down Expand Up @@ -179,6 +179,25 @@ generate-manifests-rke2-control-plane: $(CONTROLLER_GEN) ## Generate manifests e
output:webhook:dir=./controlplane/config/webhook \
webhook

.PHONY: generate-go-deepcopy
generate-conversions: ## Run all conversion funcs
$(MAKE) $(addprefix generate-conversions-,$(ALL_GENERATE_MODULES))

.PHONY: generate-conversions-rke2-control-plane
generate-conversions-rke2-control-plane: $(CONVERSION_GEN) ## Generate conversion functions for control plane provider
$(MAKE) clean-generated-conversions SRC_DIRS="./controlplane/api"
$(CONVERSION_GEN) \
--input-dirs=./controlplane/api/v1alpha1 \
--extra-peer-dirs=github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1alpha1 \
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \
--build-tag=ignore_autogenerated_conversions \
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE_CAPRKE2) \
--go-header-file=./hack/boilerplate.go.txt

.PHONY: generate-conversions-rke2-bootstrap
generate-conversions-rke2-bootstrap: $(CONVERSION_GEN) ## Generate conversion functions for bootstrap provider
echo "TODO"

.PHONY: generate-go-deepcopy
generate-go-deepcopy: ## Run all generate-go-deepcopy-* targets
$(MAKE) $(addprefix generate-go-deepcopy-,$(ALL_GENERATE_MODULES))
Expand Down Expand Up @@ -556,6 +575,10 @@ clean-generated-yaml: ## Remove files generated by conversion-gen from the menti
clean-generated-deepcopy: ## Remove files generated by conversion-gen from the mentioned dirs. Example SRC_DIRS="./api/v1alpha4"
(IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.deepcopy*' -exec rm -f {} \;; done)

.PHONY: clean-generated-conversions
clean-generated-conversions: ## Remove files generated by conversion-gen from the mentioned dirs. Example SRC_DIRS="./api/v1alpha4"
(IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done)

## --------------------------------------
## Hack / Tools
## --------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/internal/controllers/rke2config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
bootstrapv1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1alpha1"
"github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/internal/cloudinit"
"github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/internal/ignition"
controlplanev1 "github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1alpha1"
controlplanev1 "github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1beta1"
"github.com/rancher-sandbox/cluster-api-provider-rke2/pkg/consts"
"github.com/rancher-sandbox/cluster-api-provider-rke2/pkg/locking"
"github.com/rancher-sandbox/cluster-api-provider-rke2/pkg/rke2"
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (

bootstrapv1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1alpha1"
"github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/internal/controllers"
controlplanev1 "github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1alpha1"
controlplanev1 "github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1beta1"
"github.com/rancher-sandbox/cluster-api-provider-rke2/pkg/consts"
)

Expand Down
69 changes: 69 additions & 0 deletions controlplane/api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2024 SUSE.

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 v1alpha1

import (
controlplanev1 "github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1beta1"

Check failure on line 20 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s blank -s dot -s default -s prefix(sigs.k8s.io/cluster-api) -s prefix(github.com/rancher-sandbox/cluster-api-provider-rke2) --custom-order (gci)
//utilconversion "sigs.k8s.io/cluster-api/util/conversion"

Check failure on line 21 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)

Check failure on line 21 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
"sigs.k8s.io/controller-runtime/pkg/conversion"

Check failure on line 22 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s blank -s dot -s default -s prefix(sigs.k8s.io/cluster-api) -s prefix(github.com/rancher-sandbox/cluster-api-provider-rke2) --custom-order (gci)
)

// ConvertTo converts the v1alpha1 RKE2ControlPlane receiver to a v1beta1 RKEControlPlane.
func (r *RKE2ControlPlane) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*controlplanev1.RKE2ControlPlane)

Check failure on line 27 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

type assertion must be checked (forcetypeassert)

Check failure on line 27 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

type assertion must be checked (forcetypeassert)

if err := autoConvert_v1alpha1_RKE2ControlPlane_To_v1beta1_RKE2ControlPlane(r, dst, nil); err != nil {
return err
}

// restored := &controlplanev1.RKE2ControlPlane{}
// if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
// return err
// }
//dst.Spec.XXX = restored.Spec.XXXX

Check failure on line 37 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

return nil
}

// ConvertFrom converts the v1beta1 RKE2ControlPlane receiver to a v1alpha1 RKE2ControlPlane.
func (r *RKE2ControlPlane) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*controlplanev1.RKE2ControlPlane)

Check failure on line 44 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

type assertion must be checked (forcetypeassert)

if err := autoConvert_v1beta1_RKE2ControlPlane_To_v1alpha1_RKE2ControlPlane(src, r, nil); err != nil {
return err
}

// if err := utilconversion.MarshalData(src, r); err != nil {
// return nil
// }

return nil
}

// ConvertTo converts the v1alpha1 RKE2ControlPlaneList receiver to a v1beta1 RKEControlPlaneList.
func (r *RKE2ControlPlaneList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*controlplanev1.RKE2ControlPlaneList)

Check failure on line 59 in controlplane/api/v1alpha1/conversion.go

View workflow job for this annotation

GitHub Actions / lint

type assertion must be checked (forcetypeassert)

return autoConvert_v1alpha1_RKE2ControlPlaneList_To_v1beta1_RKE2ControlPlaneList(r, dst, nil)
}

// ConvertFrom converts the v1beta1 RKE2ControlPlaneList receiver to a v1alpha1 RKE2ControlPlaneList.
func (r *RKE2ControlPlaneList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*controlplanev1.RKE2ControlPlaneList)

return autoConvert_v1beta1_RKE2ControlPlaneList_To_v1alpha1_RKE2ControlPlaneList(src, r, nil)
}
42 changes: 42 additions & 0 deletions controlplane/api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2024 SUSE.

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 v1alpha1

import (
"testing"

. "github.com/onsi/gomega"

"github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1beta1"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/runtime"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

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

t.Run("for RKE2ControlPlane", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1beta1.RKE2ControlPlane{},
Spoke: &RKE2ControlPlane{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
}))
}
22 changes: 22 additions & 0 deletions controlplane/api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 SUSE.

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 v1alpha1 contains API Schema definitions for the controlplane v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=controlplane.cluster.x-k8s.io
// +k8s:defaulter-gen=TypeMeta
// +k8s:conversion-gen=github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1beta1
package v1alpha1
5 changes: 2 additions & 3 deletions controlplane/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

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

import (
Expand All @@ -33,4 +30,6 @@ var (

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

localSchemeBuilder = SchemeBuilder.SchemeBuilder
)
Loading
Loading