Skip to content
Merged
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 sdk/apis/kubebind/v1alpha2/helpers/boundschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Comment thread
iakmc marked this conversation as resolved.
Resolved
return boundSchema, nil
}

Expand Down
48 changes: 48 additions & 0 deletions sdk/apis/kubebind/v1alpha2/helpers/boundschema_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}