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

doc: add docstring for parent and delete a duplicate if condition #334

Merged
merged 1 commit into from
May 9, 2023
Merged
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
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
}
Comment on lines -96 to -98
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already claimed in

if err != nil {
return nil, err
}

if !found {
return nil, &meta.NoResourceMatchError{PartialResource: schema.GroupVersionResource{Group: gk.Group, Resource: gk.Kind}}
}
Expand Down