diff --git a/applylib/applyset/parentref.go b/applylib/applyset/parentref.go index ddef3938..672e5b64 100644 --- a/applylib/applyset/parentref.go +++ b/applylib/applyset/parentref.go @@ -1,3 +1,19 @@ +/* +Copyright 2023 The Kubernetes 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. +*/ +// This package provides Parent object related methods. package applyset import ( @@ -6,7 +22,8 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) -// This parentref.go guarantees the main k-d-p don't need to import the kubectl. +// Parent is aimed for adaption. We want users to us Parent rather than the third-party/forked ParentRef directly. +// This gives us more flexibility to change the third-party/forked without introducing breaking changes to users. type Parent interface { GroupVersionKind() schema.GroupVersionKind Name() string @@ -15,6 +32,7 @@ type Parent interface { GetSubject() runtime.Object } +// NewParentRef initialize a ParentRef object. func NewParentRef(object runtime.Object, name, namespace string, rest *meta.RESTMapping) *ParentRef { return &ParentRef{ object: object, @@ -26,6 +44,7 @@ func NewParentRef(object runtime.Object, name, namespace string, rest *meta.REST var _ Parent = &ParentRef{} +// ParentRef defines the Parent object information type ParentRef struct { namespace string name string @@ -33,22 +52,27 @@ type ParentRef struct { object runtime.Object } +// GroupVersionKind returns the parent GroupVersionKind func (p *ParentRef) GroupVersionKind() schema.GroupVersionKind { return p.object.GetObjectKind().GroupVersionKind() } +// Name returns the parent Name func (p *ParentRef) Name() string { return p.name } +// Namespace returns the parent Namespace func (p *ParentRef) Namespace() string { return p.namespace } +// RESTMapping returns the parent RESTMapping func (p *ParentRef) RESTMapping() *meta.RESTMapping { return p.restMapping } +// GetSubject returns the parent runtime.Object func (p *ParentRef) GetSubject() runtime.Object { return p.object } diff --git a/pkg/restmapper/controllerrestmapper.go b/pkg/restmapper/controllerrestmapper.go index c57cebc5..207818c7 100644 --- a/pkg/restmapper/controllerrestmapper.go +++ b/pkg/restmapper/controllerrestmapper.go @@ -93,9 +93,6 @@ func (m *ControllerRESTMapper) RESTMappings(gk schema.GroupKind, versions ...str return nil, err } group, found := allGroups[gk.Group] - if err != nil { - return nil, err - } if !found { return nil, &meta.NoResourceMatchError{PartialResource: schema.GroupVersionResource{Group: gk.Group, Resource: gk.Kind}} }