Skip to content

⚠️ Add v1beta2 API for ExtensionConfig #12197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ linters:
alias: ipamv1
# CAPI exp runtime
- pkg: sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1
alias: runtimev1alpha1
- pkg: sigs.k8s.io/cluster-api/exp/runtime/api/v1beta2
alias: runtimev1
- pkg: sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1
alias: runtimehooksv1
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ generate-go-conversions-core-runtime: $(CONVERSION_GEN) ## Generate conversions
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt \
./internal/runtime/test/v1alpha1 \
./internal/runtime/test/v1alpha2
$(MAKE) clean-generated-conversions SRC_DIRS="./$(EXP_DIR)/runtime/api/v1alpha1,./$(EXP_DIR)/runtime/api/v1beta2"
$(CONVERSION_GEN) \
--output-file=zz_generated.conversion.go \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt \
./$(EXP_DIR)/runtime/api/v1alpha1 \
./$(EXP_DIR)/runtime/api/v1beta2

.PHONY: generate-go-conversions-kubeadm-bootstrap
generate-go-conversions-kubeadm-bootstrap: $(CONVERSION_GEN) ## Generate conversions go code for kubeadm bootstrap
Expand Down
352 changes: 352 additions & 0 deletions config/crd/bases/runtime.cluster.x-k8s.io_extensionconfigs.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ patches:
- path: patches/webhook_in_clusterresourcesetbindings.yaml
- path: patches/webhook_in_ipaddresses.yaml
- path: patches/webhook_in_ipaddressclaims.yaml
- path: patches/webhook_in_extensionconfigs.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_extensionconfigs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: extensionconfigs.runtime.cluster.x-k8s.io
spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
4 changes: 0 additions & 4 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ replacements:
delimiter: /
select:
kind: CustomResourceDefinition
reject:
- name: extensionconfigs.runtime.cluster.x-k8s.io
- source:
fieldPath: .metadata.name
group: cert-manager.io
Expand Down Expand Up @@ -90,8 +88,6 @@ replacements:
index: 1
select:
kind: CustomResourceDefinition
reject:
- name: extensionconfigs.runtime.cluster.x-k8s.io
- source:
fieldPath: .metadata.name
kind: Service
Expand Down
8 changes: 4 additions & 4 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /mutate-runtime-cluster-x-k8s-io-v1alpha1-extensionconfig
path: /mutate-runtime-cluster-x-k8s-io-v1beta2-extensionconfig
failurePolicy: Fail
matchPolicy: Equivalent
name: default.extensionconfig.runtime.addons.cluster.x-k8s.io
rules:
- apiGroups:
- runtime.cluster.x-k8s.io
apiVersions:
- v1alpha1
- v1beta2
operations:
- CREATE
- UPDATE
Expand Down Expand Up @@ -415,15 +415,15 @@ webhooks:
service:
name: webhook-service
namespace: system
path: /validate-runtime-cluster-x-k8s-io-v1alpha1-extensionconfig
path: /validate-runtime-cluster-x-k8s-io-v1beta2-extensionconfig
failurePolicy: Fail
matchPolicy: Equivalent
name: validation.extensionconfig.runtime.cluster.x-k8s.io
rules:
- apiGroups:
- runtime.cluster.x-k8s.io
apiVersions:
- v1alpha1
- v1beta2
operations:
- CREATE
- UPDATE
Expand Down
102 changes: 102 additions & 0 deletions exp/runtime/api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright 2025 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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1beta2"
)

func (src *ExtensionConfig) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*runtimev1.ExtensionConfig)

return Convert_v1alpha1_ExtensionConfig_To_v1beta2_ExtensionConfig(src, dst, nil)
}

func (dst *ExtensionConfig) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*runtimev1.ExtensionConfig)

return Convert_v1beta2_ExtensionConfig_To_v1alpha1_ExtensionConfig(src, dst, nil)
}

func Convert_v1beta2_ExtensionConfigStatus_To_v1alpha1_ExtensionConfigStatus(in *runtimev1.ExtensionConfigStatus, out *ExtensionConfigStatus, s apimachineryconversion.Scope) error {
if err := autoConvert_v1beta2_ExtensionConfigStatus_To_v1alpha1_ExtensionConfigStatus(in, out, s); err != nil {
return err
}

// Reset conditions from autogenerated conversions
// NOTE: v1beta2 conditions should not be automatically be converted into legacy conditions (v1beta1).
out.Conditions = nil

// Retrieve legacy conditions (v1beta1) from the deprecated field.
if in.Deprecated != nil && in.Deprecated.V1Beta1 != nil {
if in.Deprecated.V1Beta1.Conditions != nil {
clusterv1beta1.Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1beta1_Conditions(&in.Deprecated.V1Beta1.Conditions, &out.Conditions)
}
}

// Move new conditions (v1beta2) to the v1beta2 field.
if in.Conditions == nil {
return nil
}
out.V1Beta2 = &ExtensionConfigV1Beta2Status{}
out.V1Beta2.Conditions = in.Conditions
return nil
}

func Convert_v1alpha1_ExtensionConfigStatus_To_v1beta2_ExtensionConfigStatus(in *ExtensionConfigStatus, out *runtimev1.ExtensionConfigStatus, s apimachineryconversion.Scope) error {
if err := autoConvert_v1alpha1_ExtensionConfigStatus_To_v1beta2_ExtensionConfigStatus(in, out, s); err != nil {
return err
}

// Reset conditions from autogenerated conversions
// NOTE: v1beta1 conditions should not be automatically be converted into v1beta2 conditions.
out.Conditions = nil

// Retrieve new conditions (v1beta2) from the v1beta2 field.
if in.V1Beta2 != nil {
out.Conditions = in.V1Beta2.Conditions
}

// Move legacy conditions (v1beta1) to the deprecated field.
if in.Conditions == nil {
return nil
}

if out.Deprecated == nil {
out.Deprecated = &runtimev1.ExtensionConfigDeprecatedStatus{}
}
if out.Deprecated.V1Beta1 == nil {
out.Deprecated.V1Beta1 = &runtimev1.ExtensionConfigV1Beta1DeprecatedStatus{}
}
if in.Conditions != nil {
clusterv1beta1.Convert_v1beta1_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions(&in.Conditions, &out.Deprecated.V1Beta1.Conditions)
}
return nil
}

func Convert_v1_Condition_To_v1beta1_Condition(in *metav1.Condition, out *clusterv1beta1.Condition, s apimachineryconversion.Scope) error {
return clusterv1beta1.Convert_v1_Condition_To_v1beta1_Condition(in, out, s)
}

func Convert_v1beta1_Condition_To_v1_Condition(in *clusterv1beta1.Condition, out *metav1.Condition, s apimachineryconversion.Scope) error {
return clusterv1beta1.Convert_v1beta1_Condition_To_v1_Condition(in, out, s)
}
68 changes: 68 additions & 0 deletions exp/runtime/api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//go:build !race

/*
Copyright 2025 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 (
"reflect"
"testing"

fuzz "github.com/google/gofuzz"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"

runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1beta2"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out.

func TestFuzzyConversion(t *testing.T) {
t.Run("for ExtensionConfig", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Hub: &runtimev1.ExtensionConfig{},
Spoke: &ExtensionConfig{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{ExtensionConfigFuzzFuncs},
}))
}

func ExtensionConfigFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
hubExtensionConfigStatus,
spokeExtensionConfigStatus,
}
}

func hubExtensionConfigStatus(in *runtimev1.ExtensionConfigStatus, c fuzz.Continue) {
c.FuzzNoCustom(in)
// Drop empty structs with only omit empty fields.
if in.Deprecated != nil {
if in.Deprecated.V1Beta1 == nil || reflect.DeepEqual(in.Deprecated.V1Beta1, &runtimev1.ExtensionConfigV1Beta1DeprecatedStatus{}) {
in.Deprecated = nil
}
}
}

func spokeExtensionConfigStatus(in *ExtensionConfigStatus, c fuzz.Continue) {
c.FuzzNoCustom(in)
// Drop empty structs with only omit empty fields.
if in.V1Beta2 != nil {
if reflect.DeepEqual(in.V1Beta2, &ExtensionConfigV1Beta2Status{}) {
in.V1Beta2 = nil
}
}
}
1 change: 1 addition & 0 deletions exp/runtime/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 the v1alpha1 implementation of ExtensionConfig.
// +k8s:conversion-gen=sigs.k8s.io/cluster-api/exp/runtime/api/v1beta2
package v1alpha1
42 changes: 21 additions & 21 deletions exp/runtime/api/v1alpha1/extensionconfig_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/v1beta2"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// ANCHOR: ExtensionConfigSpec
Expand Down Expand Up @@ -125,7 +125,7 @@ type ExtensionConfigStatus struct {

// conditions define the current service state of the ExtensionConfig.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
Conditions clusterv1beta1.Conditions `json:"conditions,omitempty"`

// v1beta2 groups all the fields that will be added or modified in ExtensionConfig's status with the V1Beta2 version.
// +optional
Expand Down Expand Up @@ -203,7 +203,7 @@ const (
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=extensionconfigs,shortName=ext,scope=Cluster,categories=cluster-api
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:deprecatedversion
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ExtensionConfig"

// ExtensionConfig is the Schema for the ExtensionConfig API.
Expand All @@ -223,26 +223,26 @@ type ExtensionConfig struct {
Status ExtensionConfigStatus `json:"status,omitempty"`
}

// GetV1Beta1Conditions returns the set of conditions for this object.
func (e *ExtensionConfig) GetV1Beta1Conditions() clusterv1.Conditions {
// GetConditions returns the set of conditions for this object.
func (e *ExtensionConfig) GetConditions() clusterv1beta1.Conditions {
return e.Status.Conditions
}

// SetV1Beta1Conditions sets the conditions on this object.
func (e *ExtensionConfig) SetV1Beta1Conditions(conditions clusterv1.Conditions) {
// SetConditions sets the conditions on this object.
func (e *ExtensionConfig) SetConditions(conditions clusterv1beta1.Conditions) {
e.Status.Conditions = conditions
}

// GetConditions returns the set of conditions for this object.
func (e *ExtensionConfig) GetConditions() []metav1.Condition {
// GetV1Beta2Conditions returns the set of conditions for this object.
func (e *ExtensionConfig) GetV1Beta2Conditions() []metav1.Condition {
if e.Status.V1Beta2 == nil {
return nil
}
return e.Status.V1Beta2.Conditions
}

// SetConditions sets conditions for an API object.
func (e *ExtensionConfig) SetConditions(conditions []metav1.Condition) {
// SetV1Beta2Conditions sets conditions for an API object.
func (e *ExtensionConfig) SetV1Beta2Conditions(conditions []metav1.Condition) {
if e.Status.V1Beta2 == nil {
e.Status.V1Beta2 = &ExtensionConfigV1Beta2Status{}
}
Expand All @@ -268,22 +268,22 @@ func init() {

// ExtensionConfig's Discovered conditions and corresponding reasons that will be used in v1Beta2 API version.
const (
// ExtensionConfigDiscoveredCondition is true if the runtime extension has been successfully discovered.
ExtensionConfigDiscoveredCondition = "Discovered"
// ExtensionConfigDiscoveredV1Beta2Condition is true if the runtime extension has been successfully discovered.
ExtensionConfigDiscoveredV1Beta2Condition = "Discovered"

// ExtensionConfigDiscoveredReason surfaces that the runtime extension has been successfully discovered.
ExtensionConfigDiscoveredReason = "Discovered"
// ExtensionConfigDiscoveredV1Beta2Reason surfaces that the runtime extension has been successfully discovered.
ExtensionConfigDiscoveredV1Beta2Reason = "Discovered"

// ExtensionConfigNotDiscoveredReason surfaces that the runtime extension has not been successfully discovered.
ExtensionConfigNotDiscoveredReason = "NotDiscovered"
// ExtensionConfigNotDiscoveredV1Beta2Reason surfaces that the runtime extension has not been successfully discovered.
ExtensionConfigNotDiscoveredV1Beta2Reason = "NotDiscovered"
)

const (
// RuntimeExtensionDiscoveredV1Beta1Condition is a condition set on an ExtensionConfig object once it has been discovered by the Runtime SDK client.
RuntimeExtensionDiscoveredV1Beta1Condition clusterv1.ConditionType = "Discovered"
// RuntimeExtensionDiscoveredCondition is a condition set on an ExtensionConfig object once it has been discovered by the Runtime SDK client.
RuntimeExtensionDiscoveredCondition clusterv1beta1.ConditionType = "Discovered"

// DiscoveryFailedV1Beta1Reason documents failure of a Discovery call.
DiscoveryFailedV1Beta1Reason string = "DiscoveryFailed"
// DiscoveryFailedReason documents failure of a Discovery call.
DiscoveryFailedReason string = "DiscoveryFailed"

// InjectCAFromSecretAnnotation is the annotation that specifies that an ExtensionConfig
// object wants injection of CAs. The value is a reference to a Secret
Expand Down
3 changes: 3 additions & 0 deletions exp/runtime/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ var (
// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = schemeBuilder.AddToScheme

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

objectTypes = []runtime.Object{}
)

Expand Down
Loading
Loading