Skip to content
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

Enable Namespace as an optional field in TypedReference #541

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions apis/common/v1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ type Reference struct {
Policy *Policy `json:"policy,omitempty"`
}

// A TypedReference refers to an object by Name, Kind, and APIVersion. It is
// commonly used to reference cluster-scoped objects or objects where the
// namespace is already known.
// A TypedReference refers to an object by Name, Namespace, Kind, and
// APIVersion. It is commonly used to reference cluster-scoped objects
// and can also be used for namespace-scoped objects.
type TypedReference struct {
// APIVersion of the referenced object.
APIVersion string `json:"apiVersion"`
Expand All @@ -135,6 +135,10 @@ type TypedReference struct {
// Name of the referenced object.
Name string `json:"name"`

// Namespace of the referenced object.
// +optional
Namespace string `json:"namespace,omitempty"`

// UID of the referenced object.
// +optional
UID types.UID `json:"uid,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TypedReferenceTo(o metav1.Object, of schema.GroupVersionKind) *xpv1.TypedRe
APIVersion: v,
Kind: k,
Name: o.GetName(),
Namespace: o.GetNamespace(),
UID: o.GetUID(),
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestTypedReferenceTo(t *testing.T) {
want: &xpv1.TypedReference{
APIVersion: groupVersion,
Kind: kind,
Namespace: namespace,
Name: name,
UID: uid,
},
Expand Down