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

Simplify construction of the fake dynamic client #102928

Merged

Conversation

dprotaso
Copy link
Contributor

@dprotaso dprotaso commented Jun 16, 2021

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

With the introduction of GVK to the fake dynamic client it made using
the fake much more cumbersome.

Specifically:

  • requires manual registration of list types
  • mismatch between scheme types and passed in fixtures would result in errors

The PR changes the constructor method NewSimpleDynamicClient to do the following:

  • rewire the schemes to unstructured types
  • typed fixtures are converted to unstructured types
  • automatically register fixture gvks with the scheme

This should make the dynamic client 'flexible' with it's inputs like it was
before

Which issue(s) this PR fixes:

Fixes N/A

Special notes for your reviewer:

Thanks!

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 16, 2021
@dprotaso dprotaso changed the title Simplify use of the fake dynamic client Simplify constructions of the fake dynamic client Jun 16, 2021
@dprotaso dprotaso changed the title Simplify constructions of the fake dynamic client Simplify construction of the fake dynamic client Jun 16, 2021
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 16, 2021
@dprotaso
Copy link
Contributor Author

/kind cleanup

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Jun 16, 2021
@dprotaso
Copy link
Contributor Author

/assign @lavalamp

@dprotaso
Copy link
Contributor Author

I debated whether to move the logic to NewSimpleDynamicClientWithCustomListKinds

I wonder if that method is still necessary and could be marked deprecated

@dims
Copy link
Member

dims commented Jun 16, 2021

/assign @deads2k

related to kubernetes/client-go#914 specifically kubernetes/client-go#949 (comment)

@dims
Copy link
Member

dims commented Jun 16, 2021

cc @n3wscott

@dprotaso
Copy link
Contributor Author

/assign @deads2k

related to kubernetes/client-go#914 specifically kubernetes/client-go#949 (comment)

Interesting this PR won't fix #914 because in that example there's no scheme or resources being supplied during construction.

@fedebongio
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 17, 2021
@dprotaso
Copy link
Contributor Author

Does a priority need to be assigned prior to review?

unstructuredScheme.AddKnownTypeWithName(gvk, &unstructured.Unstructured{})
}

objects, err := convertObjectsToUnstructured(scheme, objects)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea.


// This test ensures list works when the fake dynamic client is seeded with a typed scheme and
// unstructured type fixtures
func TestListWithUnstructuredObjectsAndTypedScheme(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see a test case where the list isn't seeded at all and the response needs to be fully constructed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added TestListWithNoFixturesAndTypedScheme

I'm testing with a typed scheme - otherwise I'd expect consumers to use the other constructor that requires a mapping of gvrs to list kinds

@deads2k
Copy link
Contributor

deads2k commented Jul 7, 2021

/lgtm
/approve
/hold

holding for squash. ping me on slack for a re-lgtm.

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jul 7, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, dprotaso

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 7, 2021
With the introduction of GVK to the fake dynamic client it made using
the fake much more cumbersome.

Specifically:
- requires manual registration of list types
- mismatch between scheme types and passed in fixtures would result in errors

The PR changes the constructor method NewSimpleDynamicClient to do the following:
- rewire the schemes to unstructured types
- typed fixtures are converted to unstructured types
- automatically register fixture gvks with the scheme

This should make the dynamic client 'flexible' with it's inputs like it was
before
@dprotaso dprotaso force-pushed the dynamic-client-backwards-compatible branch from cfbd3ff to 418fa71 Compare July 8, 2021 14:50
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 8, 2021
@dprotaso
Copy link
Contributor Author

dprotaso commented Jul 8, 2021

Ok squashed

@deads2k
Copy link
Contributor

deads2k commented Jul 8, 2021

/lgtm
/hold cancel

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jul 8, 2021
@dprotaso
Copy link
Contributor Author

dprotaso commented Jul 8, 2021

/retest

1 similar comment
@dprotaso
Copy link
Contributor Author

dprotaso commented Jul 8, 2021

/retest

@k8s-ci-robot k8s-ci-robot merged commit fc4e7c1 into kubernetes:master Jul 8, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone Jul 8, 2021
@dprotaso dprotaso deleted the dynamic-client-backwards-compatible branch July 8, 2021 22:39
@dprotaso
Copy link
Contributor Author

dprotaso commented Jul 9, 2021

/cherrypick release-1.21
/cherrypick release-1.20

k8s-ci-robot added a commit that referenced this pull request Jul 29, 2021
…2928-upstream-release-1.20

Automated cherry pick of #102928: Simplify use of the fake dynamic client
k8s-ci-robot added a commit that referenced this pull request Jul 29, 2021
…2928-upstream-release-1.21

Automated cherry pick of #102928: Simplify use of the fake dynamic client
halvards added a commit to halvards/skaffold that referenced this pull request Mar 24, 2022
The new `ko` build option to produce SBOM is disabled until we
have a design for how this should work across Skaffold builders.

Additional transitive dependencies (mainly authentication libraries
for various image registries) means that the Skaffold binary grows
by about 4.8MB.

The change to labels_test.go works around the tests failing due to
this change in `client-go` between `v0.21.3` and `v0.21.4`:
kubernetes/client-go@c6c0ca0
That commit came from this k/k PR:
kubernetes/kubernetes#102928

Related: GoogleContainerTools#7193
Tracking: GoogleContainerTools#7131
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants