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

ExtractItems for unstructured apply configurations #103564

Merged
merged 20 commits into from Aug 5, 2021

Conversation

kevindelgado
Copy link
Contributor

@kevindelgado kevindelgado commented Jul 8, 2021

What type of PR is this?

/kind feature

What this PR does / why we need it:

Enable running fieldmanager "ExtractItems" on unstructured objects. Currently ExtractItems can only be called by typed clients, and extracted into typed apply configurations. This lets you extract any arbitrary object into an unstructured apply configuration (i.e. an `unstructured.Unstructured) which enables extracting CRDs.

In order to call ExtractItems for a given gvk we need the typed.ParseableType for that gvk. For builtins this exists in a large static file. For CRDs we need to dynamically generate the typed.ParseableType

We do this by dynamically downloading the OpenAPISpec, converting it into a GVKParser, and resolving the typed.ParseableType from it for the given gvk.

To prevent having to download the OpenAPISpec and and generate the GVKParser every time we want to extract a CRD, we've implemented a caching mechanism to only download the open api spec and generate the parser at most every minute.

Does this PR introduce a user-facing change?

* Expose a `NewUnstructuredExtractor` from apply configurations `meta/v1` package that enables extracting objects into unstructured apply configurations

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. labels Jul 8, 2021
@kevindelgado kevindelgado marked this pull request as draft July 8, 2021 02:03
@k8s-ci-robot k8s-ci-robot added area/apiserver area/dependency Issues or PRs related to dependency changes area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 8, 2021
@caesarxuchao
Copy link
Member

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 8, 2021
@kevindelgado kevindelgado changed the title WIP: Unstructured Extract Proof-of-concept WIP: Unstructured Extract Jul 15, 2021
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 19, 2021
@kevindelgado kevindelgado changed the title WIP: Unstructured Extract ExtractItems for unstructured apply configurations Jul 19, 2021
@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jul 19, 2021
@kevindelgado
Copy link
Contributor Author

@apelisse or @lavalamp do either of you have thoughts on where to move gvkparser.go to?

Currently it is internal to apiserver/pkg/endpoints/handlers/fieldmanager/internal and I want to use it in the unstructured extractor so I initially tried pulling it out of internal and into the apiserver/pkg/endpoints/handlers/fieldmanager package.

This does not work though, because client-go cannot import apiserver due to an import cycle, so I have to move it somewhere in client-go, or somewhere else entirely that they both can import. I was thinking somewhere int client-go/utils or client-go/applyconfigurations but it doesn't really seem to fit super well in either of those places. Any thoughts?

@kevindelgado
Copy link
Contributor Author

@apelisse or @lavalamp do either of you have thoughts on where to move gvkparser.go to?

Currently it is internal to apiserver/pkg/endpoints/handlers/fieldmanager/internal and I want to use it in the unstructured extractor so I initially tried pulling it out of internal and into the apiserver/pkg/endpoints/handlers/fieldmanager package.

This does not work though, because client-go cannot import apiserver due to an import cycle, so I have to move it somewhere in client-go, or somewhere else entirely that they both can import. I was thinking somewhere int client-go/utils or client-go/applyconfigurations but it doesn't really seem to fit super well in either of those places. Any thoughts?

Actually, I'm thinking apimachinery/pkg/util/managedfields probably makes the most sense (or maybe a new gvkparser package in apimachinery/pkg/util, what do y'all think?

@apelisse
Copy link
Member

Actually, I'm thinking apimachinery/pkg/util/managedfields probably makes the most sense (or maybe a new gvkparser package in apimachinery/pkg/util, what do y'all think?

I think it makes sense in apimachinery, I like apimachinery/pkg/util/managedfields. I don't know the implications of all these dependencies very well though.

@k8s-ci-robot k8s-ci-robot added the sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. label Jul 27, 2021
@kevindelgado
Copy link
Contributor Author

/test pull-kubernetes-integration

@k8s-ci-robot k8s-ci-robot added area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. labels Jul 28, 2021
@@ -5,6 +5,7 @@ rules:
- selectorRegexp: k8s[.]io/kube-openapi/
allowedPrefixes:
- k8s.io/kube-openapi/pkg/util/proto
- k8s.io/kube-openapi/pkg/schemaconv
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why I have to do this.

The only change I made to imports was to make client-go import kube-openapi, but if I don't add this verify import-boss will fail with this error for various packages of kubeadm:

errors in package "k8s.io/kubernetes/cmd/kubeadm/app/util/etcd":
the following imports did not match any allowed prefix:
  k8s.io/kube-openapi/pkg/schemaconv

Copy link
Member

Choose a reason for hiding this comment

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

kubeadm imports client-go, so probably the import-restriction tooling is finding it as an indirect dependency.

but kubeadm does not use k8s.io/kube-openapi directly:
https://github.com/kubernetes/kubernetes/search?q=path%3A%2Fcmd%2Fkubeadm+%22kube-openapi%22

/approve
for kubeadm, but haven't reviewed the other changes.

@kevindelgado
Copy link
Contributor Author

All checks are green, PTAL @apelisse @lavalamp

@kevindelgado
Copy link
Contributor Author

friendly ping @apelisse @lavalamp

@@ -67,6 +67,7 @@
- k8s.io/apimachinery
- k8s.io/client-go
- k8s.io/klog
- k8s.io/kube-openapi
Copy link
Member

Choose a reason for hiding this comment

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

@sttts, can you take a look at this?

Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

/lgtm

Looks good to me, thanks. I think apimachinery is a good place to put this, but I'm not sure about the dependency thing.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 30, 2021
@kevindelgado
Copy link
Contributor Author

Looks good to me, thanks. I think apimachinery is a good place to put this, but I'm not sure about the dependency thing.

Ya, it makes sense to me that we need to add kube-openapi to the import restrictions for client-go because we are now generating the models in the unstructured extractor.

I was more confused about why I had to do it in kubeadm. Since kubeadm is not a staging repo, it's a bit harder to see what it imports directly and transitively, but I can at least see now that it does import client-go in places (even though I can't fully trace it back to why kube-openapi/pkg/schema needs to be imported explicitly)

@lavalamp
Copy link
Member

I'm surprised this is the first use of kube-openapi from within client-go.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kevindelgado, lavalamp, neolit123

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 30, 2021
@dims
Copy link
Member

dims commented Aug 4, 2021

/kind feature

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Aug 4, 2021
@k8s-ci-robot k8s-ci-robot merged commit 0a704f9 into kubernetes:master Aug 5, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Aug 5, 2021
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. area/apiserver area/dependency Issues or PRs related to dependency changes area/kubeadm area/release-eng Issues or PRs related to the Release Engineering subproject area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. 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 Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/release Categorizes an issue or PR as relevant to SIG Release. sig/testing Categorizes an issue or PR as relevant to SIG Testing. 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.

None yet

7 participants