Skip to content

Commit

Permalink
promote IPAM types to v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanderp3 committed Oct 5, 2023
1 parent 646933b commit 51dba3d
Show file tree
Hide file tree
Showing 23 changed files with 1,067 additions and 8 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ generate-go-conversions: ## Run all generate-go-conversions-* targets
generate-go-conversions-core: ## Run all generate-go-conversions-core-* targets
$(MAKE) generate-go-conversions-core-api
$(MAKE) generate-go-conversions-core-exp
$(MAKE) generate-go-conversions-core-exp-ipam
$(MAKE) generate-go-conversions-core-runtime

.PHONY: generate-go-conversions-core-api
Expand All @@ -443,6 +444,14 @@ generate-go-conversions-core-exp: $(CONVERSION_GEN) ## Generate conversions go c
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

.PHONY: generate-go-conversions-core-exp-ipam
generate-go-conversions-core-exp-ipam: $(CONVERSION_GEN) ## Generate conversions go code for core exp IPAM
$(MAKE) clean-generated-conversions SRC_DIRS="./$(EXP_DIR)/ipam/api/v1alpha1"
$(CONVERSION_GEN) \
--input-dirs=./$(EXP_DIR)/ipam/api/v1alpha1 \
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

.PHONY: generate-go-conversions-core-runtime
generate-go-conversions-core-runtime: $(CONVERSION_GEN) ## Generate conversions go code for core runtime
$(MAKE) clean-generated-conversions SRC_DIRS="./internal/runtime/test/v1alpha1,./internal/runtime/test/v1alpha2"
Expand Down
117 changes: 117 additions & 0 deletions config/crd/bases/ipam.cluster.x-k8s.io_ipaddressclaims.yaml

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

84 changes: 84 additions & 0 deletions config/crd/bases/ipam.cluster.x-k8s.io_ipaddresses.yaml

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

92 changes: 92 additions & 0 deletions exp/ipam/api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright 2021 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 v1alpha1

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

ipamv1beta1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

func (src *IPAddress) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*ipamv1beta1.IPAddress)

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

delete(src.Annotations, utilconversion.DataAnnotation)

return nil
}

func (dst *IPAddress) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*ipamv1beta1.IPAddress)

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

return utilconversion.MarshalData(src, dst)
}

func (src *IPAddressList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*ipamv1beta1.IPAddressList)

return Convert_v1alpha1_IPAddressList_To_v1beta1_IPAddressList(src, dst, nil)
}

func (dst *IPAddressList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*ipamv1beta1.IPAddressList)

return Convert_v1beta1_IPAddressList_To_v1alpha1_IPAddressList(src, dst, nil)
}

func (src *IPAddressClaim) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*ipamv1beta1.IPAddressClaim)

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

delete(src.Annotations, utilconversion.DataAnnotation)

return nil
}

func (dst *IPAddressClaim) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*ipamv1beta1.IPAddressClaim)

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

return utilconversion.MarshalData(src, dst)
}

func (src *IPAddressClaimList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*ipamv1beta1.IPAddressClaimList)

return Convert_v1alpha1_IPAddressClaimList_To_v1beta1_IPAddressClaimList(src, dst, nil)
}

func (dst *IPAddressClaimList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*ipamv1beta1.IPAddressClaimList)

return Convert_v1beta1_IPAddressClaimList_To_v1alpha1_IPAddressClaimList(src, dst, nil)
}
39 changes: 39 additions & 0 deletions exp/ipam/api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2021 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 v1alpha1

import (
"testing"

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

ipamv1beta1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

func TestFuzzyConversion(t *testing.T) {
t.Run("for IPAddress", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Hub: &ipamv1beta1.IPAddress{},
Spoke: &IPAddress{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
}))
t.Run("for IPAddressClaim", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Hub: &ipamv1beta1.IPAddressClaim{},
Spoke: &IPAddressClaim{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
}))
}
1 change: 1 addition & 0 deletions exp/ipam/api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the exp v1alpha1 IPAM API.
// +k8s:conversion-gen=sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1
package v1alpha1
3 changes: 3 additions & 0 deletions exp/ipam/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var (
AddToScheme = schemeBuilder.AddToScheme

objectTypes = []runtime.Object{}

// localSchemeBuilder is used for type conversions.
localSchemeBuilder = schemeBuilder
)

func addKnownTypes(scheme *runtime.Scheme) error {
Expand Down
1 change: 0 additions & 1 deletion exp/ipam/api/v1alpha1/ipaddress_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type IPAddressSpec struct {

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=ipaddresses,scope=Namespaced,categories=cluster-api
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Address",type="string",JSONPath=".spec.address",description="Address"
// +kubebuilder:printcolumn:name="Pool Name",type="string",JSONPath=".spec.poolRef.name",description="Name of the pool the address is from"
// +kubebuilder:printcolumn:name="Pool Kind",type="string",JSONPath=".spec.poolRef.kind",description="Kind of the pool the address is from"
Expand Down
Loading

0 comments on commit 51dba3d

Please sign in to comment.