Skip to content

Commit 4f15359

Browse files
committed
feat(kubernetes): add a GetObjectMeta accessor to ObjectMeta
Embedding promotes ObjectMeta's fields, but only a method survives type erasure: a consumer walking a tree holds each resource as an any, and Go generics cannot constrain on a field. Without an accessor every consumer has to reach the typed name and namespace with its own per-kind closure or reflection. Mirrors resource.Resource's GetBase, with an Object interface to assert on in the same way as resource.Implementation.
1 parent cd76ef2 commit 4f15359

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

pkg/tree/kubernetes/meta/meta.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,22 @@ type ObjectMeta struct {
4747
// A synthetic namespace must not be used to exclude a candidate when
4848
// matching against a real cluster — it is an assumption, not evidence.
4949
Namespace value.String `tree:"namespace"`
50-
}
50+
}
51+
52+
// GetObjectMeta returns the metadata itself, so that every kind embedding
53+
// ObjectMeta promotes an accessor for it. Embedding promotes fields too, but
54+
// only a method survives type erasure: a consumer walking a tree holds each
55+
// resource as an any, and Go generics cannot constrain on a field. This is the
56+
// same reason resource.Resource carries GetBase.
57+
func (m *ObjectMeta) GetObjectMeta() *ObjectMeta {
58+
return m
59+
}
60+
61+
// Object is satisfied by every Kubernetes kind in the tree, through the
62+
// promoted GetObjectMeta above — at whatever embedding depth it sits (a CronJob
63+
// reaches it through Job through Workload). Consumers that match tree resources
64+
// against real cluster objects assert on this to reach the typed name and
65+
// namespace, as they assert on resource.Implementation to reach the base.
66+
type Object interface {
67+
GetObjectMeta() *ObjectMeta
68+
}

0 commit comments

Comments
 (0)