Skip to content

Commit

Permalink
Restore ObjectMeta on CloudStackMachineTemplateResource
Browse files Browse the repository at this point in the history
This restores the field with the correct type, and converts the field for v1beta1 and 2

Signed-off-by: Hans Rakers <[email protected]>
  • Loading branch information
hrak committed Feb 7, 2024
1 parent 7fd4146 commit 731fb43
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 39 deletions.
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ GH_REPO ?= kubernetes-sigs/cluster-api-provider-cloudstack

# Binaries
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
GINKGO := $(TOOLS_BIN_DIR)/ginkgo
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
Expand Down Expand Up @@ -80,7 +81,7 @@ all: build
## --------------------------------------

.PHONY: binaries
binaries: $(CONTROLLER_GEN) $(GOLANGCI_LINT) $(STATIC_CHECK) $(GINKGO) $(MOCKGEN) $(KUSTOMIZE) managers # Builds and installs all binaries
binaries: $(CONTROLLER_GEN) $(CONVERSION_GEN) $(GOLANGCI_LINT) $(STATIC_CHECK) $(GINKGO) $(MOCKGEN) $(KUSTOMIZE) managers # Builds and installs all binaries

.PHONY: managers
managers:
Expand Down Expand Up @@ -157,13 +158,16 @@ config/.flag.mk: $(CONTROLLER_GEN) $(MANIFEST_GEN_INPUTS)
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="{./api/...,./controllers/...}" output:crd:artifacts:config=config/crd/bases
@touch config/.flag.mk

CONVERSION_GEN_TARGET=$(shell find api -type d -name "v*1" -exec echo {}\/zz_generated.conversion.go \;)
CONVERSION_GEN_INPUTS=$(shell find ./api -name "*test*" -prune -o -name "*zz_generated*" -prune -o -type f -print)
.PHONY: generate-conversion
generate-conversion: $(CONVERSION_GEN_TARGET) ## Generate code to convert api/v1beta1 to api/v1beta2
api/%/zz_generated.conversion.go: bin/conversion-gen $(CONVERSION_GEN_INPUTS)
conversion-gen --go-header-file "./hack/boilerplate.go.txt" --input-dirs "./api/v1beta1" \
--output-base "." --output-file-base="zz_generated.conversion" --skip-unsafe=true
generate-conversion: $(CONVERSION_GEN) ## Generate code to convert api/v1beta1 and api/v1beta2 to api/v1beta3
$(CONVERSION_GEN) \
--input-dirs=./api/v1beta1 \
--go-header-file=./hack/boilerplate.go.txt \
--output-base=. --output-file-base=zz_generated.conversion
$(CONVERSION_GEN) \
--input-dirs=./api/v1beta2 \
--go-header-file=./hack/boilerplate.go.txt \
--output-base=. --output-file-base=zz_generated.conversion

##@ Build
## --------------------------------------
Expand Down
27 changes: 23 additions & 4 deletions api/v1beta1/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

func (src *CloudStackMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { // nolint
Expand Down Expand Up @@ -57,13 +60,29 @@ func (dst *CloudStackMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
}

func Convert_v1beta1_CloudStackMachineTemplateSpec_To_v1beta3_CloudStackMachineTemplateSpec(in *CloudStackMachineTemplateSpec, out *v1beta3.CloudStackMachineTemplateSpec, s machineryconversion.Scope) error { // nolint
return autoConvert_v1beta1_CloudStackMachineSpec_To_v1beta3_CloudStackMachineSpec(&in.Spec.Spec, &out.Template.Spec, s)
return Convert_v1beta1_CloudStackMachineTemplateResource_To_v1beta3_CloudStackMachineTemplateResource(&in.Spec, &out.Template, s)
}

func Convert_v1beta3_CloudStackMachineTemplateSpec_To_v1beta1_CloudStackMachineTemplateSpec(in *v1beta3.CloudStackMachineTemplateSpec, out *CloudStackMachineTemplateSpec, s machineryconversion.Scope) error { // nolint
return autoConvert_v1beta3_CloudStackMachineSpec_To_v1beta1_CloudStackMachineSpec(&in.Template.Spec, &out.Spec.Spec, s)
return Convert_v1beta3_CloudStackMachineTemplateResource_To_v1beta1_CloudStackMachineTemplateResource(&in.Template, &out.Spec, s)
}

func Convert_v1beta1_CloudStackMachineTemplateResource_To_v1beta3_CloudStackMachineTemplateResource(in *CloudStackMachineTemplateResource, out *v1beta3.CloudStackMachineTemplateResource, s machineryconversion.Scope) error { //nolint
return autoConvert_v1beta1_CloudStackMachineTemplateResource_To_v1beta3_CloudStackMachineTemplateResource(in, out, s)
func Convert_v1beta1_ObjectMeta_To_v1_ObjectMeta(in *clusterv1.ObjectMeta, out *metav1.ObjectMeta, s machineryconversion.Scope) error { // nolint
if in.Annotations != nil {
out.Annotations = in.Annotations
}
if in.Labels != nil {
out.Labels = in.Labels
}
return nil
}

func Convert_v1_ObjectMeta_To_v1beta1_ObjectMeta(in *metav1.ObjectMeta, out *clusterv1.ObjectMeta, s machineryconversion.Scope) error { // nolint
if in.Annotations != nil {
out.Annotations = in.Annotations
}
if in.Labels != nil {
out.Labels = in.Labels
}
return nil
}
10 changes: 5 additions & 5 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1beta1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ = Describe("Conversion", func() {
Expand All @@ -46,7 +46,7 @@ var _ = Describe("Conversion", func() {
},
},
},
ControlPlaneEndpoint: capiv1.APIEndpoint{
ControlPlaneEndpoint: clusterv1.APIEndpoint{
Host: "endpoint1",
Port: 443,
},
Expand Down Expand Up @@ -99,7 +99,7 @@ var _ = Describe("Conversion", func() {
},
},
},
ControlPlaneEndpoint: capiv1.APIEndpoint{
ControlPlaneEndpoint: clusterv1.APIEndpoint{
Host: "endpoint1",
Port: 443,
},
Expand All @@ -122,7 +122,7 @@ var _ = Describe("Conversion", func() {
},
},
},
ControlPlaneEndpoint: capiv1.APIEndpoint{
ControlPlaneEndpoint: clusterv1.APIEndpoint{
Host: "endpoint1",
Port: 443,
},
Expand All @@ -143,7 +143,7 @@ var _ = Describe("Conversion", func() {
Namespace: "namespace1",
},
Spec: v1beta3.CloudStackClusterSpec{
ControlPlaneEndpoint: capiv1.APIEndpoint{
ControlPlaneEndpoint: clusterv1.APIEndpoint{
Host: "endpoint1",
Port: 443,
},
Expand Down
42 changes: 32 additions & 10 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions api/v1beta2/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ limitations under the License.
package v1beta2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down Expand Up @@ -49,13 +51,29 @@ func (dst *CloudStackMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
}

func Convert_v1beta2_CloudStackMachineTemplateSpec_To_v1beta3_CloudStackMachineTemplateSpec(in *CloudStackMachineTemplateSpec, out *v1beta3.CloudStackMachineTemplateSpec, s machineryconversion.Scope) error { // nolint
return autoConvert_v1beta2_CloudStackMachineSpec_To_v1beta3_CloudStackMachineSpec(&in.Spec.Spec, &out.Template.Spec, s)
return Convert_v1beta2_CloudStackMachineTemplateResource_To_v1beta3_CloudStackMachineTemplateResource(&in.Spec, &out.Template, s)
}

func Convert_v1beta3_CloudStackMachineTemplateSpec_To_v1beta2_CloudStackMachineTemplateSpec(in *v1beta3.CloudStackMachineTemplateSpec, out *CloudStackMachineTemplateSpec, s machineryconversion.Scope) error { // nolint
return autoConvert_v1beta3_CloudStackMachineSpec_To_v1beta2_CloudStackMachineSpec(&in.Template.Spec, &out.Spec.Spec, s)
return Convert_v1beta3_CloudStackMachineTemplateResource_To_v1beta2_CloudStackMachineTemplateResource(&in.Template, &out.Spec, s)
}

func Convert_v1beta2_CloudStackMachineTemplateResource_To_v1beta3_CloudStackMachineTemplateResource(in *CloudStackMachineTemplateResource, out *v1beta3.CloudStackMachineTemplateResource, s machineryconversion.Scope) error { //nolint
return autoConvert_v1beta2_CloudStackMachineTemplateResource_To_v1beta3_CloudStackMachineTemplateResource(in, out, s)
func Convert_v1beta1_ObjectMeta_To_v1_ObjectMeta(in *clusterv1.ObjectMeta, out *metav1.ObjectMeta, s machineryconversion.Scope) error { // nolint
if in.Annotations != nil {
out.Annotations = in.Annotations
}
if in.Labels != nil {
out.Labels = in.Labels
}
return nil
}

func Convert_v1_ObjectMeta_To_v1beta1_ObjectMeta(in *metav1.ObjectMeta, out *clusterv1.ObjectMeta, s machineryconversion.Scope) error { // nolint
if in.Annotations != nil {
out.Annotations = in.Annotations
}
if in.Labels != nil {
out.Labels = in.Labels
}
return nil
}
Loading

0 comments on commit 731fb43

Please sign in to comment.