-
Notifications
You must be signed in to change notification settings - Fork 75
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
Refactor Inventory client #586
Refactor Inventory client #586
Conversation
Hi @rquitales. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
49e276f
to
6f36891
Compare
/ok-to-test |
@@ -8,6 +8,8 @@ import ( | |||
"k8s.io/apimachinery/pkg/types" | |||
) | |||
|
|||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed for this PR? It can probably be pulled out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactor now requires Inventory
to satisfy runtime.Object
which was previously not needed, hence why deepcopy-gen tags are added in this PR. We could spin it out into another PR that is merged first, but this tag addition is related to the refactor. LMKYT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's required for this PR, but it doesn't need to be IN this PR. The dependency only goes one way. So I think it can go in a separate PR just to reduce the size of this PR.
6f36891
to
f995c77
Compare
08b3615
to
3ad0f74
Compare
80e460d
to
7c5fef1
Compare
f44bea1
to
f5e7d89
Compare
a60cabe
to
b10923d
Compare
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
983f54d
to
c1ef322
Compare
cmd/main.go
Outdated
@@ -62,7 +62,8 @@ func main() { | |||
} | |||
|
|||
loader := manifestreader.NewManifestLoader(f) | |||
invFactory := inventory.ClusterClientFactory{StatusPolicy: inventory.StatusPolicyNone} | |||
// TODO: Add StatusPolicy back to factory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does ConfigMapClientFactory need configurable StatusPolicy? Or is it configured elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfigMapClientFactory does need configurable StatusPolicy. We have historically hardcoded StatusPolicyNone
for kapply
as the statusPolicy field is not exposed as a flag. Perhaps we should also add a flag to kapply
to have users set this in a follow-up PR?
Regardless, ConfigMap now has a configurable StatusPolicy field for handling status conversion to the data fields.
1c02add
to
69dc8af
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rquitales The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
9cf3cde
to
5c8df4f
Compare
This commit uses Karl's inventory client changes and is a direct c&p from his PR. This is a WIP commit and further commits need to be created for kapply status to work as intended.
5c8df4f
to
819cb6e
Compare
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
@@ -164,18 +166,25 @@ func TestInvSetTask(t *testing.T) { | |||
|
|||
for name, tc := range tests { | |||
t.Run(name, func(t *testing.T) { | |||
client := inventory.NewFakeClient(object.ObjMetadataSet{}) | |||
// client := inventory.NewFakeInventoryClient(object.ObjMetadataSet{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented line
@@ -29,7 +29,7 @@ const ( | |||
|
|||
var inventoryConfigs = map[string]invconfig.InventoryConfig{} | |||
var inventoryConfigTypes = []string{ | |||
ConfigMapTypeInvConfig, | |||
// ConfigMapTypeInvConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've identified a bunch of code that looks independent to the core of this PR (to rewrite the inventory client). They don't ALL need to be pulled out, and they don't ALL need to be individual PRs. Feel free to group them at your own discretion. Then link them from this PR and assign them to me. After they're merged, you can rebase this PR.
@@ -129,7 +129,7 @@ func (r *Runner) RunE(cmd *cobra.Command, args []string) error { | |||
if err != nil { | |||
return err | |||
} | |||
inv := inventory.WrapInventoryInfoObj(invObj) | |||
inv := inventory.InfoFromObject(invObj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this WrapInventoryInfoObj -> InfoFromObject rename out to its own PR to reduce noise.
Feel free to include other renames that aren't critical to the rewrite, like inv -> invInfo.
@@ -62,7 +62,7 @@ func main() { | |||
} | |||
|
|||
loader := manifestreader.NewManifestLoader(f) | |||
invFactory := inventory.ClusterClientFactory{StatusPolicy: inventory.StatusPolicyNone} | |||
invFactory := inventory.ConfigMapClientFactory{StatusPolicy: inventory.StatusPolicyNone} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ClusterClientFactory -> ConfigMapClientFactory rename can be moved out to the refactor/rename PR to reduce noise.
@@ -152,7 +152,7 @@ func (r *Runner) preRunE(*cobra.Command, []string) error { | |||
// and get info from the cluster based on the local info | |||
// wrap it to be a map mapping from string to objectMetadataSet | |||
func (r *Runner) loadInvFromDisk(cmd *cobra.Command, args []string) (*printer.PrintData, error) { | |||
inv, err := r.loader.GetInvInfo(cmd, args) | |||
invInfo, err := r.loader.GetInvInfo(cmd, args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This inv -> invInfo refactor variable can be moved out to a smaller PR to reduce noise here.
@@ -8,6 +8,8 @@ import ( | |||
"k8s.io/apimachinery/pkg/types" | |||
) | |||
|
|||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's required for this PR, but it doesn't need to be IN this PR. The dependency only goes one way. So I think it can go in a separate PR just to reduce the size of this PR.
for _, localObj := range localObjs { | ||
inventory.AddInventoryIDAnnotation(localObj, localInv) | ||
for _, applyObj := range applyObjs { | ||
inventory.SetOwningInventoryAnnotation(applyObj, invInfo.ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rename can be pulled out to the smaller refactor PR: AddInventoryIDAnnotation -> SetOwningInventoryAnnotation
"sigs.k8s.io/cli-utils/pkg/object" | ||
) | ||
|
||
type FakeClientFactory object.ObjMetadataSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public types need comments. Not sure why the linter didn't catch this.
type NoInventoryObjError struct{} | ||
|
||
func (e *NoInventoryObjError) Error() string { | ||
func (g NoInventoryObjError) Error() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, error types should use a pointer receiver, to allow them to be nil, even if there's no state that actually needs a pointer. Making the Error method require a pointer is a good way to force users to follow this best practice when using it.
} | ||
} | ||
actual := Label(object.InfoToUnstructured(test.inventoryInfo)) | ||
assert.Equal(t, test.inventoryLabel, actual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's another assert.Equal test cleanup that could be pulled out.
@@ -0,0 +1,19 @@ | |||
// Copyright 2022 The Kubernetes Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test file could be pulled out. It's not a big deal if there's only one, but it's completely independent. It just allows the package to be run with logging verbosity.
) | ||
|
||
// ObjMetadataEqualObjectReference compares an ObjMetadata with a ObjectReference | ||
func ObjMetadataEqualObjectReference(id object.ObjMetadata, ref actuation.ObjectReference) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper function looks pretty independent. It could be in a separate PR.
In fact, this whole file seems like helper funcs that could be factored into a separate PR.
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This is a WIP PR pending rebase when K8s resources are updated to use v1.25.
This PR uses Karl's initial PR as the basis for the Inventory client refactor.
DeepCopyObject
for actuation.InventoryTODO: Rebase PR when blocking PRs are merged