-
Notifications
You must be signed in to change notification settings - Fork 1.2k
🐛 Modify multinamespaced cache to support cluster scoped resources #1418
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
Merged
k8s-ci-robot
merged 4 commits into
kubernetes-sigs:master
from
varshaprasad96:multinamespace-cache
Apr 30, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
39ad3e6
:bug: Modify multinamespaced cache to support cluster scoped resources
varshaprasad96 2cde0e7
Add restmapper to multinamespaced cache
varshaprasad96 8c4b815
Use restmapper to identify scope of the object
varshaprasad96 711f8e8
Rename fileter.go to objectutil.go
varshaprasad96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ func (n *namespacedClient) RESTMapper() meta.RESTMapper { | |
|
||
// isNamespaced returns true if the object is namespace scoped. | ||
// For unstructured objects the gvk is found from the object itself. | ||
// TODO: this is repetitive code. Remove this and use ojectutil.IsNamespaced. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this PR references a bug, will do refactoring in follow up. |
||
func isNamespaced(c Client, obj runtime.Object) (bool, error) { | ||
var gvk schema.GroupVersionKind | ||
var err error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,15 @@ limitations under the License. | |
package objectutil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have renamed this file from filter.go to objectutil.go to make it generic |
||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/api/meta" | ||
apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil" | ||
) | ||
|
||
// FilterWithLabels returns a copy of the items in objs matching labelSel | ||
|
@@ -40,3 +46,28 @@ func FilterWithLabels(objs []runtime.Object, labelSel labels.Selector) ([]runtim | |
} | ||
return outItems, nil | ||
} | ||
|
||
// IsAPINamespaced returns true if the object is namespace scoped. | ||
// For unstructured objects the gvk is found from the object itself. | ||
func IsAPINamespaced(obj runtime.Object, scheme *runtime.Scheme, restmapper apimeta.RESTMapper) (bool, error) { | ||
gvk, err := apiutil.GVKForObject(obj, scheme) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
restmapping, err := restmapper.RESTMapping(schema.GroupKind{Group: gvk.Group, Kind: gvk.Kind}) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to get restmapping: %w", err) | ||
} | ||
|
||
scope := restmapping.Scope.Name() | ||
|
||
if scope == "" { | ||
return false, errors.New("Scope cannot be identified. Empty scope returned") | ||
} | ||
|
||
if scope != meta.RESTScopeNameRoot { | ||
return true, nil | ||
} | ||
return false, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.