Skip to content

Commit

Permalink
Merge pull request #187 from Danil-Grigorev/v1alpha2-api
Browse files Browse the repository at this point in the history
Introduce v1beta1 api version
  • Loading branch information
Danil-Grigorev committed Jan 10, 2024
2 parents 4ecd686 + 7a4225e commit c692853
Show file tree
Hide file tree
Showing 97 changed files with 6,713 additions and 144 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ run:
go: "1.20"
skip-files:
- "zz_generated.*\\.go$"
- "conversion\\.go"
- "vendored_openapi\\.go$"
- ".*_test\\.go$"
allow-parallel-runners: true
Expand Down
30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ ALL_GENERATE_MODULES = rke2-bootstrap rke2-control-plane

.PHONY: generate
generate: ## Run all generate-manifests-*, generate-go-deepcopy-* targets
$(MAKE) generate-modules generate-manifests generate-go-deepcopy
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions

.PHONY: generate-manifests
generate-manifests: $(addprefix generate-manifests-,$(ALL_GENERATE_MODULES)) ## Run all generate-manifests-* targets
Expand Down Expand Up @@ -197,6 +197,30 @@ generate-go-deepcopy-rke2-control-plane: $(CONTROLLER_GEN) ## Generate deepcopy
object:headerFile=./hack/boilerplate.go.txt \
paths=./controlplane/api/...


.PHONY: generate-go-conversions
generate-go-conversions: ## Run all generate-go-conversions-* targets
$(MAKE) $(addprefix generate-go-conversions-,$(ALL_GENERATE_MODULES))

.PHONY: generate-go-conversions-rke2-bootstrap
generate-go-conversions-rke2-bootstrap: $(CONVERSION_GEN) ## Generate conversions go code for the rke2 bootstrap
$(MAKE) clean-generated-conversions SRC_DIRS="./bootstrap/api/v1alpha1"
$(CONVERSION_GEN) \
--input-dirs=./bootstrap/api/v1alpha1 \
--build-tag=ignore_autogenerated_rke2_bootstrap \
--output-file-base=zz_generated.conversion $(ROOT_DIR) \
--go-header-file=./hack/boilerplate.go.txt

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

.PHONY: generate-modules
generate-modules: ## Run go mod tidy to ensure modules are up to date
go mod tidy
Expand Down Expand Up @@ -556,6 +580,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
15 changes: 15 additions & 0 deletions bootstrap/PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: cluster.x-k8s.io
layout:
- go.kubebuilder.io/v3
Expand Down Expand Up @@ -29,4 +33,15 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: bootstrap
kind: RKE2ConfigTemplate
path: github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1beta1
version: v1beta1
webhooks:
conversion: true
webhookVersion: v1
version: "3"
113 changes: 113 additions & 0 deletions bootstrap/api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Copyright 2024 SUSE LLC.
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 (
"fmt"

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

bootstrapv1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1beta1"
)

func (src *RKE2Config) ConvertTo(dstRaw conversion.Hub) error {
dst, ok := dstRaw.(*bootstrapv1.RKE2Config)
if !ok {
return fmt.Errorf("not a RKE2Config: %v", dst)
}

if err := Convert_v1alpha1_RKE2Config_To_v1beta1_RKE2Config(src, dst, nil); err != nil {
return err
}

return nil
}

func (dst *RKE2Config) ConvertFrom(srcRaw conversion.Hub) error {
src, ok := srcRaw.(*bootstrapv1.RKE2Config)
if !ok {
return fmt.Errorf("not a RKE2Config: %v", src)
}

if err := Convert_v1beta1_RKE2Config_To_v1alpha1_RKE2Config(src, dst, nil); err != nil {
return err
}

return nil
}

func (src *RKE2ConfigList) ConvertTo(dstRaw conversion.Hub) error {
dst, ok := dstRaw.(*bootstrapv1.RKE2ConfigList)
if !ok {
return fmt.Errorf("not a RKE2ConfigList: %v", src)
}

return Convert_v1alpha1_RKE2ConfigList_To_v1beta1_RKE2ConfigList(src, dst, nil)
}

func (dst *RKE2ConfigList) ConvertFrom(srcRaw conversion.Hub) error {
src, ok := srcRaw.(*bootstrapv1.RKE2ConfigList)
if !ok {
return fmt.Errorf("not a RKE2ConfigList: %v", src)
}

return Convert_v1beta1_RKE2ConfigList_To_v1alpha1_RKE2ConfigList(src, dst, nil)
}

func (src *RKE2ConfigTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst, ok := dstRaw.(*bootstrapv1.RKE2ConfigTemplate)
if !ok {
return fmt.Errorf("not a RKE2ConfigTemplate: %v", dst)
}

if err := Convert_v1alpha1_RKE2ConfigTemplate_To_v1beta1_RKE2ConfigTemplate(src, dst, nil); err != nil {
return err
}

return nil
}

func (dst *RKE2ConfigTemplate) ConvertFrom(srcRaw conversion.Hub) error {
src, ok := srcRaw.(*bootstrapv1.RKE2ConfigTemplate)
if !ok {
return fmt.Errorf("not a RKE2ConfigTemplate: %v", dst)
}

if err := Convert_v1beta1_RKE2ConfigTemplate_To_v1alpha1_RKE2ConfigTemplate(src, dst, nil); err != nil {
return err
}

return nil
}

func (src *RKE2ConfigTemplateList) ConvertTo(dstRaw conversion.Hub) error {
dst, ok := dstRaw.(*bootstrapv1.RKE2ConfigTemplateList)
if !ok {
return fmt.Errorf("not a RKE2ConfigTemplateList: %v", dst)
}

return Convert_v1alpha1_RKE2ConfigTemplateList_To_v1beta1_RKE2ConfigTemplateList(src, dst, nil)
}

func (dst *RKE2ConfigTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
src, ok := srcRaw.(*bootstrapv1.RKE2ConfigTemplateList)
if !ok {
return fmt.Errorf("not a RKE2ConfigTemplateList: %v", dst)
}

return Convert_v1beta1_RKE2ConfigTemplateList_To_v1alpha1_RKE2ConfigTemplateList(src, dst, nil)
}
50 changes: 50 additions & 0 deletions bootstrap/api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2024 SUSE LLC.
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"

"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/runtime"

bootstrapv1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1beta1"
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(bootstrapv1.AddToScheme(scheme)).To(Succeed())

t.Run("for RKE2Config", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &bootstrapv1.RKE2Config{},
Spoke: &RKE2Config{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
}))

t.Run("for RKE2ConfigTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &bootstrapv1.RKE2ConfigTemplate{},
Spoke: &RKE2ConfigTemplate{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
}))
}
21 changes: 21 additions & 0 deletions bootstrap/api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2023 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 a v1alpha1 api for bootstrap resources.
//
// +k8s:conversion-gen=github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1beta1
// +k8s:deepcopy-gen=package
package v1alpha1
3 changes: 3 additions & 0 deletions bootstrap/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ var (

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

// localSchemeBuilder is used for type conversions.
localSchemeBuilder = SchemeBuilder.SchemeBuilder
)
4 changes: 2 additions & 2 deletions bootstrap/api/v1alpha1/rke2configtemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type RKE2ConfigTemplateSpec struct {
Template RKE2ConfigTemplateResource `json:"template"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// RKE2ConfigTemplate is the Schema for the RKE2configtemplates API.
type RKE2ConfigTemplate struct {
Expand Down
Loading

0 comments on commit c692853

Please sign in to comment.