Skip to content
Open
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
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ linters-settings:
- pkg: sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1
alias: runtimev1
- pkg: sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1
alias: runtimehooksv1alpha1
- pkg: sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha2
alias: runtimehooksv1
- pkg: sigs.k8s.io/cluster-api/exp/runtime/controllers
alias: runtimecontrollers
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,20 @@ generate-go-conversions-core-exp: $(CONVERSION_GEN) ## Generate conversions go c

.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"
$(MAKE) clean-generated-conversions SRC_DIRS="./exp/runtime/hooks/api/v1alpha1"
$(CONVERSION_GEN) \
--input-dirs=./internal/runtime/test/v1alpha1 \
--input-dirs=./internal/runtime/test/v1alpha2 \
--input-dirs=./exp/runtime/hooks/api/v1alpha1 \
--input-dirs=./exp/runtime/hooks/api/v1alpha2 \
--build-tag=ignore_autogenerated_runtime \
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt
# $(MAKE) clean-generated-conversions SRC_DIRS="./internal/runtime/test/v1alpha1,./internal/runtime/test/v1alpha2"
# $(CONVERSION_GEN) \
# --input-dirs=./internal/runtime/test/v1alpha1 \
# --input-dirs=./internal/runtime/test/v1alpha2 \
# --build-tag=ignore_autogenerated_runtime \
# --output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
# --go-header-file=./hack/boilerplate/boilerplate.generatego.txt

.PHONY: generate-go-conversions-kubeadm-bootstrap
generate-go-conversions-kubeadm-bootstrap: $(CONVERSION_GEN) ## Generate conversions go code for kubeadm bootstrap
Expand Down
32 changes: 32 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
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 (
"k8s.io/apimachinery/pkg/conversion"

clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

func Convert_v1alpha4_Cluster_To_v1beta1_Cluster(in *clusterv1alpha4.Cluster, out *clusterv1.Cluster, s conversion.Scope) error {
return clusterv1alpha4.Convert_v1alpha4_Cluster_To_v1beta1_Cluster(in, out, s)
}

func Convert_v1beta1_Cluster_To_v1alpha4_Cluster(in *clusterv1.Cluster, out *clusterv1alpha4.Cluster, s conversion.Scope) error {
return clusterv1alpha4.Convert_v1beta1_Cluster_To_v1alpha4_Cluster(in, out, s)
}
42 changes: 42 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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 v1alpha1

import (
"context"
"testing"

runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha2"
runtimecatalog "sigs.k8s.io/cluster-api/internal/runtime/catalog"
)

func TestConversion(t *testing.T) {
// NOTE: this is only a very simple conversion test
// We need something more once we merge multiple versions of a type
// and actually use conversion.

var c = runtimecatalog.New()
_ = AddToCatalog(c)
_ = runtimehooksv1.AddToCatalog(c)

c1 := &runtimehooksv1.BeforeClusterCreateRequest{}
c2 := &BeforeClusterCreateRequest{}

if err := c.Convert(c1, c2, context.Background()); err != nil {
t.Fatal(err)
}
}
1 change: 1 addition & 0 deletions exp/runtime/hooks/api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

// Package v1alpha1 contains the v1alpha1 RuntimeHooks.
// +k8s:conversion-gen=sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha2
// +kubebuilder:object:generate=true
// +k8s:openapi-gen=true
package v1alpha1
6 changes: 6 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ var (
// AddToCatalog adds RuntimeHooks defined in this package and their request and
// response types to a catalog.
AddToCatalog = catalogBuilder.AddToCatalog

// localSchemeBuilder provide access to the SchemeBuilder used for managing rpc
// method's request and response types defined in this package.
// NOTE: this object is required to allow registration of automatically generated
// conversions func.
localSchemeBuilder = catalogBuilder
)

func init() {
Expand Down
14 changes: 7 additions & 7 deletions exp/runtime/hooks/api/v1alpha1/lifecyclehooks_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
runtimecatalog "sigs.k8s.io/cluster-api/internal/runtime/catalog"
)

Expand All @@ -29,7 +29,7 @@ type BeforeClusterCreateRequest struct {
metav1.TypeMeta `json:",inline"`

// The cluster object the lifecycle hook corresponds to.
Cluster clusterv1.Cluster `json:"cluster"`
Cluster clusterv1alpha4.Cluster `json:"cluster"`
}

var _ RetryResponseObject = &BeforeClusterCreateResponse{}
Expand All @@ -52,7 +52,7 @@ type AfterControlPlaneInitializedRequest struct {
metav1.TypeMeta `json:",inline"`

// The cluster object the lifecycle hook corresponds to.
Cluster clusterv1.Cluster `json:"cluster"`
Cluster clusterv1alpha4.Cluster `json:"cluster"`
}

var _ ResponseObject = &AfterControlPlaneInitializedResponse{}
Expand All @@ -76,7 +76,7 @@ type BeforeClusterUpgradeRequest struct {
metav1.TypeMeta `json:",inline"`

// The cluster object the lifecycle hook corresponds to.
Cluster clusterv1.Cluster `json:"cluster"`
Cluster clusterv1alpha4.Cluster `json:"cluster"`

// The current Kubernetes version of the cluster.
FromKubernetesVersion string `json:"fromKubernetesVersion"`
Expand Down Expand Up @@ -106,7 +106,7 @@ type AfterControlPlaneUpgradeRequest struct {
metav1.TypeMeta `json:",inline"`

// The cluster object the lifecycle hook corresponds to.
Cluster clusterv1.Cluster `json:"cluster"`
Cluster clusterv1alpha4.Cluster `json:"cluster"`

// The Kubernetes version after upgrade.
KubernetesVersion string `json:"kubernetesVersion"`
Expand All @@ -133,7 +133,7 @@ type AfterClusterUpgradeRequest struct {
metav1.TypeMeta `json:",inline"`

// The cluster object the lifecycle hook corresponds to.
Cluster clusterv1.Cluster `json:"cluster"`
Cluster clusterv1alpha4.Cluster `json:"cluster"`

// The Kubernetes version after upgrade.
KubernetesVersion string `json:"kubernetesVersion"`
Expand All @@ -160,7 +160,7 @@ type BeforeClusterDeleteRequest struct {
metav1.TypeMeta `json:",inline"`

// The cluster object the lifecycle hook corresponds to.
Cluster clusterv1.Cluster `json:"cluster"`
Cluster clusterv1alpha4.Cluster `json:"cluster"`
}

var _ RetryResponseObject = &BeforeClusterDeleteResponse{}
Expand Down
Loading