Skip to content

Commit

Permalink
doc: add docstring in parent and delete a duplicate if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed May 9, 2023
1 parent c72ef4b commit 6eb7117
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 25 additions & 1 deletion applylib/applyset/parentref.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -26,29 +44,35 @@ 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
restMapping *meta.RESTMapping
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
}
3 changes: 0 additions & 3 deletions pkg/restmapper/controllerrestmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
Expand Down

0 comments on commit 6eb7117

Please sign in to comment.