Skip to content

Commit

Permalink
Migrate api v1beta1 to v1beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentBaer committed Mar 29, 2023
1 parent be6d01d commit 26f9840
Show file tree
Hide file tree
Showing 111 changed files with 11,437 additions and 2,017 deletions.
35 changes: 31 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ GH_ORG_NAME ?= outscale
GH_REPO_NAME ?= cluster-api-provider-outscale
GIT_USERNAME ?= Outscale Bot
GIT_USEREMAIL ?= [email protected]
K8S_VERSION ?= v1.26.2
LOG_TAIL ?= -1
CAPI_VERSION ?= v1.1.4
CAPI_NAMESPACE ?= capi-kubeadm-bootstrap-system
Expand All @@ -40,11 +39,13 @@ MINIMUM_KUBEBUILDERTOOL_VERSION=1.24.1
MINIMUM_ENVTEST_VERSION=1.23.3
E2E_CONF_FILE_SOURCE ?= ${PWD}/test/e2e/config/outscale-ci.yaml
E2E_CONF_FILE ?= ${PWD}/test/e2e/config/outscale-ci-envsubst.yaml
MINIMUM_CLUSTERCTL_VERSION=1.2.4
MINIMUM_CLUSTERCTL_VERSION=1.3.5
MIN_GO_VERSION=1.18.7
MINIMUM_TILT_VERSION=0.25.3
MINIMUM_PACKER_VERSION=1.8.1
MINIMUM_CONTROLLER_GEN_VERSION=0.8.0
MINIMUM_CONVERSION_GEN_VERSION=release-1.26
MINIMUM_GO_APIDIFF_VERSION=v0.6.0
MINIMUM_GH_VERSION=2.12.1
MINIMUM_KIND_USE_VERSION=v0.14.0
MINIMUM_ENVTEST_VERSION=1.23.3
Expand Down Expand Up @@ -112,18 +113,33 @@ help: ## Display this help.
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

ifneq ($(abspath $(ROOT_DIR)),$(GOPATH)/src/outscale/cluster-api-provider-outscale)
OUTPUT_BASE := --output-base=$(ROOT_DIR)
endif

REPO_ROOT := $(shell git rev-parse --show-toplevel)


.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

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

.PHONY: mock-generate
mock-generate: mockgen ## Generate mock
go generate ./...

.PHONY: generate-image-docs
generate-image-docs:
./.github/scripts/launch.sh -c "${GIT_BRANCH}" -o "${GH_ORG_NAME}" -r "${GH_REPO_NAME}" -n "${GIT_USERNAME}" -e "${GIT_USEREMAIL}" -k "${K8S_VERSION}"

./.github/scripts/launch.sh -c "${GIT_BRANCH}" -o "${GH_ORG_NAME}" -r "${GH_REPO_NAME}" -n "${GIT_USERNAME}" -e "${GIT_USEREMAIL}"

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -426,6 +442,16 @@ CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen
GOPATH=$(GET_GOPATH) MINIMUM_CONTROLLER_GEN_VERSION=${MINIMUM_CONTROLLER_GEN_VERSION} ./hack/ensure-controller-gen.sh

CONVERSION_GEN = $(shell pwd)/bin/conversion-gen
.PHONY: install-conversion-gen
install-conversion-gen:
GOPATH=$(GET_GOPATH) MINIMUM_CONVERSION_GEN_VERSION=${MINIMUM_CONVERSION_GEN_VERSION} ./hack/ensure-conversion-gen.sh

GO_APIDIFF_GEN = $(shell pwd)/bin/go-apidiff
.PHONY: install-go-apidiff
install-go-apidiff:
GOPATH=$(GET_GOPATH) MINIMUM_GO_APIDIFF_VERSION=${MINIMUM_GO_APIDIFF_VERSION} ./hack/ensure-go-apidiff.sh

LOCAL_CLUSTERCTL ?= $(shell pwd)/bin/clusterctl
.PHONY: install-clusterctl
install-clusterctl: ## Download clusterctl
Expand Down Expand Up @@ -510,6 +536,7 @@ ENVTEST = $(shell pwd)/bin/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
GOPATH=${GET_GOPATH} MINIMUM_ENVTEST_VERSION=$(MINIMUM_ENVTEST_VERSION) ./hack/ensure-envtest.sh


MOCKGEN = $(shell pwd)/bin/mockgen
.PHONY: mockgen
mockgen: ## Download mockgen locally if necessary.
Expand Down
56 changes: 56 additions & 0 deletions 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 @@ -52,4 +56,56 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: infrastructure
kind: OscClusterTemplate
path: github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta2
version: v1beta2
webhooks:
conversion: true
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: infrastructure
kind: OscMachineTemplate
path: github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta2
version: v1beta2
webhooks:
conversion: true
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: infrastructure
kind: OscMachine
path: github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta2
version: v1beta2
webhooks:
conversion: true
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: infrastructure
kind: OscCluster
path: github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta2
version: v1beta2
webhooks:
conversion: true
defaulting: true
validation: true
webhookVersion: v1
version: "3"
22 changes: 22 additions & 0 deletions api/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 The Kubernetes Authors.
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.
*/

// +gencrdrefdocs:force
// +groupName=infrastructure.cluster.x-k8s.io
// +k8s:conversion-gen=github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta2

// Package v1beta1 contains the v1beta1 API implementation.
package v1beta1
3 changes: 3 additions & 0 deletions api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ var (

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

// localSchemeBuilder is used for type conversion
localSchemeBuilder = SchemeBuilder.SchemeBuilder
)
168 changes: 168 additions & 0 deletions api/v1beta1/osccluster_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
Copyright 2022 The Kubernetes Authors.
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 (
infrav1beta2 "github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta2"
apiconversion "k8s.io/apimachinery/pkg/conversion"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

func (src *OscCluster) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1beta2.OscCluster)
if err := Convert_v1beta1_OscCluster_To_v1beta2_OscCluster(src, dst, nil); err != nil {
return err
}
restored := &infrav1beta2.OscCluster{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.Network.Bastion = restored.Spec.Network.Bastion
dst.Spec.Network.Bastion.Enable = restored.Spec.Network.Bastion.Enable
if dst.Spec.Network.Bastion.Enable == true {
dst.Spec.Network.Bastion.ClusterName = restored.Spec.Network.Bastion.ClusterName
dst.Spec.Network.Bastion.DeviceName = restored.Spec.Network.Bastion.DeviceName
dst.Spec.Network.Bastion.ImageId = restored.Spec.Network.Bastion.ImageId
dst.Spec.Network.Bastion.ImageName = restored.Spec.Network.Bastion.ImageName
dst.Spec.Network.Bastion.KeypairName = restored.Spec.Network.Bastion.KeypairName
dst.Spec.Network.Bastion.Name = restored.Spec.Network.Bastion.Name
dst.Spec.Network.Bastion.PrivateIps = restored.Spec.Network.Bastion.PrivateIps
dst.Spec.Network.Bastion.PublicIpName = restored.Spec.Network.Bastion.PublicIpName
dst.Spec.Network.Bastion.ResourceId = restored.Spec.Network.Bastion.ResourceId
dst.Spec.Network.Bastion.RootDisk = restored.Spec.Network.Bastion.RootDisk
dst.Spec.Network.Bastion.SecurityGroupNames = restored.Spec.Network.Bastion.SecurityGroupNames
dst.Spec.Network.Bastion.SubnetName = restored.Spec.Network.Bastion.SubnetName
dst.Spec.Network.Bastion.VmType = restored.Spec.Network.Bastion.VmType
}
if restored.Spec.Network.SubregionName != "" {
dst.Spec.Network.SubregionName = restored.Spec.Network.SubregionName
}
dst.ObjectMeta = src.ObjectMeta
dst.Status.Network.LinkRouteTableRef = restored.Status.Network.LinkRouteTableRef
for _, restoredRouteTable := range restored.Spec.Network.RouteTables {
for _, dstRouteTable := range dst.Spec.Network.RouteTables {
dstRouteTable.Subnets = restoredRouteTable.Subnets
}
}

for i, dstRouteTable := range dst.Spec.Network.RouteTables {
dstRouteTable.Subnets = append(dstRouteTable.Subnets, src.Spec.Network.RouteTables[i].SubnetName)
}
return nil

}

func (dst *OscCluster) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1beta2.OscCluster)
dst.ObjectMeta = src.ObjectMeta
if err := Convert_v1beta2_OscCluster_To_v1beta1_OscCluster(src, dst, nil); err != nil {
return err
}

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

func (dst *OscClusterList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1beta2.OscClusterList)
return Convert_v1beta2_OscClusterList_To_v1beta1_OscClusterList(src, dst, nil)
}

func Convert_v1beta1_OscResourceMapReference_To_v1beta2_OscResourceReference(in *OscResourceMapReference, out *infrav1beta2.OscResourceReference, s apiconversion.Scope) error {
out = (*infrav1beta2.OscResourceReference)(in.DeepCopy())
return nil
}

func Convert_v1beta2_OscResourceReference_To_v1beta1_OscResourceMapReference(in *infrav1beta2.OscResourceReference, out *OscResourceMapReference, s apiconversion.Scope) error {
out = (*OscResourceMapReference)(in.DeepCopy())
return nil
}

func Convert_v1beta2_OscNetworkResource_To_v1beta1_OscNetworkResource(in *infrav1beta2.OscNetworkResource, out *OscNetworkResource, s apiconversion.Scope) error {
if err := autoConvert_v1beta2_OscNetworkResource_To_v1beta1_OscNetworkResource(in, out, s); err != nil {
return err
}
for key, value := range in.LinkRouteTableRef {
if out.LinkRouteTableRef.ResourceMap == nil {
out.LinkRouteTableRef.ResourceMap = make(map[string]string)
}
out.LinkRouteTableRef.ResourceMap[key] = value[0]
}

return nil
}

func Convert_v1beta1_OscNetworkResource_To_v1beta2_OscNetworkResource(in *OscNetworkResource, out *infrav1beta2.OscNetworkResource, s apiconversion.Scope) error {
if err := autoConvert_v1beta1_OscNetworkResource_To_v1beta2_OscNetworkResource(in, out, s); err != nil {
return err
}
for key, value := range in.LinkRouteTableRef.ResourceMap {
if len(out.LinkRouteTableRef) == 0 {
out.LinkRouteTableRef = make(map[string][]string)
}
out.LinkRouteTableRef[key] = []string{value}
}

out.InternetServiceRef = infrav1beta2.OscResourceReference(in.InternetServiceRef)
out.NatServiceRef = infrav1beta2.OscResourceReference(in.NatServiceRef)
out.NetRef = infrav1beta2.OscResourceReference(in.NetRef)
out.SubnetRef = infrav1beta2.OscResourceReference(in.SubnetRef)
out.SecurityGroupsRef = infrav1beta2.OscResourceReference(in.SecurityGroupsRef)
out.RouteTablesRef = infrav1beta2.OscResourceReference(in.RouteTablesRef)
out.SecurityGroupRuleRef = infrav1beta2.OscResourceReference(in.SecurityGroupRuleRef)
out.RouteRef = infrav1beta2.OscResourceReference(in.RouteRef)
return nil
}

func Convert_v1beta2_OscNetwork_To_v1beta1_OscNetwork(in *infrav1beta2.OscNetwork, out *OscNetwork, s apiconversion.Scope) error {
if err := autoConvert_v1beta2_OscNetwork_To_v1beta1_OscNetwork(in, out, s); err != nil {
return err
}
for _, outRouteTable := range out.RouteTables {
for _, inRouteTable := range in.RouteTables {
outRouteTable.SubnetName = inRouteTable.Subnets[0]
}
}
return nil
}
func Convert_v1beta2_OscClusterStatus_To_v1beta1_OscClusterStatus(in *infrav1beta2.OscClusterStatus, out *OscClusterStatus, s apiconversion.Scope) error {
if err := autoConvert_v1beta2_OscClusterStatus_To_v1beta1_OscClusterStatus(in, out, s); err != nil {
return err
}

return nil
}

func Convert_v1beta2_OscRouteTable_To_v1beta1_OscRouteTable(in *infrav1beta2.OscRouteTable, out *OscRouteTable, s apiconversion.Scope) error {
if err := autoConvert_v1beta2_OscRouteTable_To_v1beta1_OscRouteTable(in, out, s); err != nil {
return err
}
out.SubnetName = in.Subnets[0]
return nil
}

func Convert_v1beta1_OscRouteTable_To_v1beta2_OscRouteTable(in *OscRouteTable, out *infrav1beta2.OscRouteTable, s apiconversion.Scope) error {
if err := autoConvert_v1beta1_OscRouteTable_To_v1beta2_OscRouteTable(in, out, s); err != nil {
return err
}
out.Subnets[0] = in.SubnetName
return nil
}
4 changes: 1 addition & 3 deletions api/v1beta1/osccluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ 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,
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 (
Expand All @@ -39,7 +38,6 @@ type OscClusterStatus struct {
Ready bool `json:"ready,omitempty"`
Network OscNetworkResource `json:"network,omitempty"`
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
VmState *VmState `json:"vmState,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/osccluster_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ func ValidateOscClusterSpec(spec OscClusterSpec) field.ErrorList {
var allErrs field.ErrorList

if spec.Network.LoadBalancer.LoadBalancerName != "" {
if errs := ValidateAndReturnErrorList(spec.Network.LoadBalancer.LoadBalancerName, field.NewPath("loadBalancerName"), ValidateLoadBalancerName); len(errs) > 0 {
allErrs = append(allErrs, errs...)
}
/* if errs := ValidateAndReturnErrorList(spec.Network.LoadBalancer.LoadBalancerName, field.NewPath("loadBalancerName"), ValidateLoadBalancerName); len(errs) > 0 {
allErrs = append(allErrs, errs...)
}
*/
}

return allErrs
Expand Down
Loading

0 comments on commit 26f9840

Please sign in to comment.