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

Refactor Inventory client #586

Closed

Conversation

rquitales
Copy link
Contributor

@rquitales rquitales commented Jun 3, 2022

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.

  • Rebased Karl's code onto cli-utils tip
  • Updated deepcopy-gen to also create DeepCopyObject for actuation.Inventory
  • Remove stuttering on certain Inventory objects and methods after rebase

TODO: Rebase PR when blocking PRs are merged

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 3, 2022
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 3, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 3, 2022
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 3, 2022
@janetkuo
Copy link
Member

janetkuo commented Jun 3, 2022

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 3, 2022
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@@ -8,6 +8,8 @@ import (
"k8s.io/apimachinery/pkg/types"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jun 3, 2022
@rquitales rquitales force-pushed the rquitales-inventory-client branch 3 times, most recently from 08b3615 to 3ad0f74 Compare June 7, 2022 22:05
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 8, 2022
@rquitales rquitales force-pushed the rquitales-inventory-client branch 2 times, most recently from 80e460d to 7c5fef1 Compare June 9, 2022 17:58
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 9, 2022
@rquitales rquitales force-pushed the rquitales-inventory-client branch 4 times, most recently from f44bea1 to f5e7d89 Compare June 9, 2022 22:13
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2022
@k8s-triage-robot
Copy link

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 26, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2022
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.
Copy link
Contributor

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?

Copy link
Contributor Author

@rquitales rquitales Nov 3, 2022

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.

cmd/status/cmdstatus.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rquitales
Once this PR has been reviewed and has the lgtm label, please assign karlkfi for approval by writing /assign @karlkfi in a comment. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rquitales rquitales force-pushed the rquitales-inventory-client branch 2 times, most recently from 9cf3cde to 5c8df4f Compare November 3, 2022 21:47
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.
@rquitales rquitales changed the title [WIP] Refactor Inventory client Refactor Inventory client Nov 9, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 9, 2022
@k8s-triage-robot
Copy link

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 9, 2022
@@ -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{})
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

why commented out?

Copy link
Contributor

@karlkfi karlkfi left a 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)
Copy link
Contributor

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}
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

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.
Copy link
Contributor

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 {
Copy link
Contributor

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.

@k8s-triage-robot
Copy link

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants