From 6b438de1430cf581997b9c00505ed9923c321914 Mon Sep 17 00:00:00 2001 From: Iskren Date: Mon, 23 Feb 2026 14:52:58 +0200 Subject: [PATCH] reset ObjectMeta when creating BoundSchema from CRD template On-behalf-of: SAP Signed-off-by: Iskren Petrov reset ObjectMeta when creating BoundSchema from CRD template add boundschema test fix copyright date --- .../kubebind/v1alpha2/helpers/boundschema.go | 2 + .../v1alpha2/helpers/boundschema_test.go | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 sdk/apis/kubebind/v1alpha2/helpers/boundschema_test.go diff --git a/sdk/apis/kubebind/v1alpha2/helpers/boundschema.go b/sdk/apis/kubebind/v1alpha2/helpers/boundschema.go index 15ebaa7c8..2c16778b7 100644 --- a/sdk/apis/kubebind/v1alpha2/helpers/boundschema.go +++ b/sdk/apis/kubebind/v1alpha2/helpers/boundschema.go @@ -115,6 +115,8 @@ func UnstructuredToBoundSchema(u unstructured.Unstructured) (*kubebindv1alpha2.B if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.UnstructuredContent(), boundSchema); err != nil { return nil, err } + + boundSchema.ObjectMeta = metav1.ObjectMeta{Name: boundSchema.Name} return boundSchema, nil } diff --git a/sdk/apis/kubebind/v1alpha2/helpers/boundschema_test.go b/sdk/apis/kubebind/v1alpha2/helpers/boundschema_test.go new file mode 100644 index 000000000..7cc203ecb --- /dev/null +++ b/sdk/apis/kubebind/v1alpha2/helpers/boundschema_test.go @@ -0,0 +1,48 @@ +/* +Copyright 2026 The Kube Bind 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 helpers + +import ( + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" +) + +func TestUnstructuredToBoundSchema_PreservesNameAndStripsMetadata(t *testing.T) { + u := unstructured.Unstructured{} + u.SetName("sheriffs.wildwest.dev") + u.SetManagedFields([]metav1.ManagedFieldsEntry{ + { + Manager: "some-manager", + APIVersion: "apiextensions.k8s.io/v1", + }, + }) + + got, err := UnstructuredToBoundSchema(u) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + if got.Name != "sheriffs.wildwest.dev" { + t.Errorf("expected Name %q, got %q", "sheriffs.wildwest.dev", got.Name) + } + + if len(got.ManagedFields) != 0 { + t.Errorf("expected ManagedFields to be empty, got %v", got.ManagedFields) + } +}