knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/kmeta/owner_references.go (about) 1 /* 2 Copyright 2018 The Knative 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 kmeta 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "k8s.io/apimachinery/pkg/runtime/schema" 22 ) 23 24 // OwnerRefable indicates that a particular type has sufficient 25 // information to produce a metav1.OwnerReference to an object. 26 type OwnerRefable interface { 27 metav1.ObjectMetaAccessor 28 29 // GetGroupVersionKind returns a GroupVersionKind. The name is chosen 30 // to avoid collision with TypeMeta's GroupVersionKind() method. 31 // See: https://issues.k8s.io/3030 32 GetGroupVersionKind() schema.GroupVersionKind 33 } 34 35 // NewControllerRef creates an OwnerReference pointing to the given controller. 36 func NewControllerRef(obj OwnerRefable) *metav1.OwnerReference { 37 return metav1.NewControllerRef(obj.GetObjectMeta(), obj.GetGroupVersionKind()) 38 }