Skip to content

Commit 8e4325e

Browse files
authored
reset ObjectMeta when creating BoundSchema from CRD template (#476)
On-behalf-of: SAP <iskren.pertov@sap.com> Signed-off-by: Iskren Petrov <iskren@kubermatic.com> reset ObjectMeta when creating BoundSchema from CRD template add boundschema test fix copyright date
1 parent 3978350 commit 8e4325e

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

sdk/apis/kubebind/v1alpha2/helpers/boundschema.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func UnstructuredToBoundSchema(u unstructured.Unstructured) (*kubebindv1alpha2.B
115115
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.UnstructuredContent(), boundSchema); err != nil {
116116
return nil, err
117117
}
118+
119+
boundSchema.ObjectMeta = metav1.ObjectMeta{Name: boundSchema.Name}
118120
return boundSchema, nil
119121
}
120122

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2026 The Kube Bind Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package helpers
18+
19+
import (
20+
"testing"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24+
)
25+
26+
func TestUnstructuredToBoundSchema_PreservesNameAndStripsMetadata(t *testing.T) {
27+
u := unstructured.Unstructured{}
28+
u.SetName("sheriffs.wildwest.dev")
29+
u.SetManagedFields([]metav1.ManagedFieldsEntry{
30+
{
31+
Manager: "some-manager",
32+
APIVersion: "apiextensions.k8s.io/v1",
33+
},
34+
})
35+
36+
got, err := UnstructuredToBoundSchema(u)
37+
if err != nil {
38+
t.Fatalf("unexpected error: %v", err)
39+
}
40+
41+
if got.Name != "sheriffs.wildwest.dev" {
42+
t.Errorf("expected Name %q, got %q", "sheriffs.wildwest.dev", got.Name)
43+
}
44+
45+
if len(got.ManagedFields) != 0 {
46+
t.Errorf("expected ManagedFields to be empty, got %v", got.ManagedFields)
47+
}
48+
}

0 commit comments

Comments
 (0)