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

✨ Add conversions + CEL transformations for APIResourceSchemas #2105

Merged
merged 3 commits into from
Jan 13, 2023

Conversation

ncdc
Copy link
Member

@ncdc ncdc commented Sep 29, 2022

Summary

Add support for CEL-based conversions for APIResourceSchemas.

Currently implemented:

  • Added a new APIConversion resource
  • Its name must match the name of an APIResourceSchema exactly
  • When an APIBinding is processed, if any of the APIResourceSchemas it's binding to have APIConversions, the controller creates a copy of each APIConversion in system:bound-crds
    • The name of the APIConversion is set to the name of the corresponding CRD (which matches the UID of the APIResourceSchema)
  • Here is an example APIConversion. These are the only supported features in this PR (we can iterate in future PRs):
apiVersion: apis.kcp.dev/v1alpha1
kind: APIConversion
metadata:
  name: rev0002.widgets.example.io
spec:
  conversions:
  - from: v1
    to: v2
    rules:
    - field: .spec.firstName
      destination: .spec.name.first
    - field: .spec.lastName
      destination: .spec.name.last
      transformation: self
    - field: .spec.lastName
      destination: .spec.name.lastUpper
      transformation: self.upperAscii()
  - from: v2
    to: v1
    rules:
    - field: .spec.name.first
      destination: .spec.firstName
    - field: .spec.name.last
      destination: .spec.lastName
    preserve:
    - .spec.someNewField
  • When an APIConversion is created or updated, admission compiles every CEL expression, rejecting upon any errors
    • We need to decide if we want to allow updates; I just realized updates are not carried forward to the copy in system:bound-crds

Possible follow-ups in separate PRs:

  • Figure out how to support indexing in maps and lists in CEL rules
  • Figure out how to support indexing in maps and lists in "to" fields
  • See if we can identify invalid evolutions and reject them
  • What happens if a field's type changes / can we support that?
  • Fully spec out preserve fields annotation-based flows

Related issue(s)

Fixes #

Requires kcp-dev/kubernetes#104

Part of #1671

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 29, 2022
@openshift-ci openshift-ci bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Sep 29, 2022
@ncdc
Copy link
Member Author

ncdc commented Sep 30, 2022

Nice to see that I at least didn't break anything in the e2es, even if the conversion code isn't being exercised yet 😄

@ncdc
Copy link
Member Author

ncdc commented Oct 7, 2022

/test all

@ncdc ncdc changed the title WIP: ✨ Add CEL-based conversions for APIResourceSchemas ✨ Add CEL-based conversions for APIResourceSchemas Oct 7, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 7, 2022
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 12, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 14, 2022
@ncdc
Copy link
Member Author

ncdc commented Oct 14, 2022

Pushed an update based on refactoring in kcp-dev/kubernetes#104

@ncdc ncdc changed the title ✨ Add CEL-based conversions for APIResourceSchemas ✨ Add conversions + CEL transformations for APIResourceSchemas Oct 14, 2022
@ncdc ncdc force-pushed the cel-conversion branch 2 times, most recently from 8c50705 to cbfc29c Compare October 17, 2022 16:39
pkg/server/api_conversion.go Outdated Show resolved Hide resolved
pkg/admission/apiconversion/apiconversion_admission.go Outdated Show resolved Hide resolved
pkg/apis/apis/v1alpha1/types_apiresourceschema.go Outdated Show resolved Hide resolved
pkg/server/api_conversion.go Outdated Show resolved Hide resolved
Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

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

How are conversion compilation errors surfaced to the user?

pkg/admission/apiconversion/apiconversion_admission.go Outdated Show resolved Hide resolved
return nil
}

cluster, err := genericapirequest.ValidClusterFrom(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Totally unrelated question - I have recently hacked cluster name into admission attributes, necessary for webhook plubming. Can we rally around that and not need this "genericapirequest" stuff?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing

Copy link
Member Author

Choose a reason for hiding this comment

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

@stevekuznetsov I see that our generic webhook admission impl sets the cluster in the attrs, but I don't see it happening anywhere else. Do we need to plumb this in to the various handlers e.g. createHandler upstream?

Copy link
Member

Choose a reason for hiding this comment

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

what about the inverse, remove the getters from the attributes? Am not a big fan of changing an upstream interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't have it up there, we have to refactor the entire call-chain to pass it through for generic webhook admission.

Copy link
Member Author

Choose a reason for hiding this comment

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

If needed, will do in a follow-up

Copy link
Member Author

Choose a reason for hiding this comment

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

#2621 to track

pkg/apis/apis/v1alpha1/types_apiresourceschema.go Outdated Show resolved Hide resolved
pkg/conversion/conversion.go Outdated Show resolved Hide resolved
pkg/conversion/conversion.go Outdated Show resolved Hide resolved
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 20, 2022
@stevekuznetsov
Copy link
Contributor

Part of #2014

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 5, 2023
@ncdc
Copy link
Member Author

ncdc commented Jan 5, 2023

@stevekuznetsov

How are conversion compilation errors surfaced to the user?

Directly, as errors, implemented via admission

@ncdc ncdc force-pushed the cel-conversion branch 2 times, most recently from 0b531da to 43614ec Compare January 5, 2023 20:27
@ncdc ncdc changed the title ✨ Add conversions + CEL transformations for APIResourceSchemas ✨ [WIP] Add conversions + CEL transformations for APIResourceSchemas Jan 5, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2023
Copy link
Contributor

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

~ Half way through

pkg/apis/apis/v1alpha1/types_apiresourceschema.go Outdated Show resolved Hide resolved
pkg/conversion/conversion_rules.go Show resolved Hide resolved
pkg/conversion/conversion_rules.go Show resolved Hide resolved
pkg/conversion/conversion_rules.go Outdated Show resolved Hide resolved
pkg/conversion/conversion_rules.go Outdated Show resolved Hide resolved
pkg/conversion/conversion_rules.go Outdated Show resolved Hide resolved
pkg/conversion/conversion_rules.go Outdated Show resolved Hide resolved
pkg/reconciler/apis/apibinding/apibinding_reconcile.go Outdated Show resolved Hide resolved
pkg/conversion/converter.go Outdated Show resolved Hide resolved
pkg/conversion/converter.go Show resolved Hide resolved
pkg/conversion/converter.go Outdated Show resolved Hide resolved
pkg/reconciler/apis/apibinding/apibinding_reconcile.go Outdated Show resolved Hide resolved
pkg/conversion/conversion_rules.go Outdated Show resolved Hide resolved
pkg/conversion/conversion_rules.go Outdated Show resolved Hide resolved
pkg/conversion/conversion_rules.go Outdated Show resolved Hide resolved
Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
Copy link
Contributor

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2023
@ncdc ncdc changed the title ✨ [WIP] Add conversions + CEL transformations for APIResourceSchemas ✨ Add conversions + CEL transformations for APIResourceSchemas Jan 13, 2023
@ncdc
Copy link
Member Author

ncdc commented Jan 13, 2023

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ncdc, vincepri

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 13, 2023
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2023
@vincepri
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2023
Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2023
@vincepri
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 13, 2023
@openshift-merge-robot openshift-merge-robot merged commit 9358474 into kcp-dev:main Jan 13, 2023
@ncdc ncdc deleted the cel-conversion branch January 13, 2023 22:00
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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants