-
Notifications
You must be signed in to change notification settings - Fork 1.4k
⚠️ 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
base: main
Are you sure you want to change the base?
Changes from all commits
f6485ca
ff246a3
f90a0e5
943695e
ab29912
ed71966
b214359
4c5aa21
ceae2bb
95f2916
b88fd90
d266169
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
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" | ||
|
||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2" | ||
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 { | ||
out.Conditions = in.Deprecated.V1Beta1.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 { | ||
out.Deprecated.V1Beta1.Conditions = in.Conditions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also require conversion, e.g.: clusterv1beta1.Convert_v1beta1_Conditions_To_v1beta2_Deprecated_V1Beta1_Conditions(&in.Conditions, &out.Deprecated.V1Beta1.Conditions) |
||
} | ||
return nil | ||
} | ||
|
||
func Convert_v1_Condition_To_v1beta2_Condition(_ *metav1.Condition, _ *clusterv1.Condition, _ apimachineryconversion.Scope) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I follow. Why is this different to other CRDs? e.g. 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)
} |
||
// NOTE: v1beta2 conditions should not be automatically converted into legacy (v1beta2) conditions. | ||
return nil | ||
} | ||
|
||
func Convert_v1beta2_Condition_To_v1_Condition(_ *clusterv1.Condition, _ *metav1.Condition, _ apimachineryconversion.Scope) error { | ||
// NOTE: legacy (v1beta2) conditions should not be automatically converted into v1beta2 conditions. | ||
return nil | ||
} |
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 | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be possible without conversion. v1alpha1 should not be using v1beta2.Conditions. Looks like this was changed on main (on release-1.10 v1alpha1 is using v1beta1.Conditions)
(e.g. CRS is using
clusterv1beta1.Convert_v1beta2_Deprecated_V1Beta1_Conditions_To_v1beta1_Conditions(&in.Deprecated.V1Beta1.Conditions, &out.Conditions)
)