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

Introduce support for Catalogs that enable specifying KRMFunctions #5507

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

varshaprasad96
Copy link
Member

This PR adds support to Kustomize Function catalogs as mentioned in the KEP: https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2906-kustomize-function-catalog.

This change introduces an option for users to specify path to their catalog configuration file in kustomization.yaml. It introduces logic to fetch the function spec from an individual catalog whose spec contains a GVK matches the resource or from the annotation. This feature is currently supported only in Transformers.

Follow up:

  • Introduce catalog support in generators.
  • Update documentation on this feature.
  • Enable specifying trusted catalogs.

@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 5, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 16, 2024
This commit introduces a Catalog API, and allows the kustomize
command to accept a list of paths that resolve to a catalog file.

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
This commit modifies the logic to read function specs
from catalog in addition to the annotations. This feature
is currently enabled only with transformers.

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 26, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: varshaprasad96

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 Jan 26, 2024
@varshaprasad96
Copy link
Member Author

Apologies for a bunch of lint fixes in this PR to make the linter happy.

The tests which had been failing initially on the PR having been passing locally. The recent push should re-trigger the tests to ensure that it is not a flake.

@stormqueen1990
Copy link
Member

/cc

Comment on lines +98 to +105
apiVersion: example.com/v1
kind: Example
metadata:
name: test
annotations:
config.kubernetes.io/function: |-
container:
image: foo:v1.0.0
Copy link
Member

Choose a reason for hiding this comment

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

I'm having a bit of difficulty understanding this test case. I read the KEP and the wording in the Determining the Function to Execute section suggests that the current use case with the runtime field should take precedence over the new Catalog option, and still require the --enable-alpha-plugins and --enable-exec flags.

Is config.kubernetes.io/function equivalent to the runtime function mentioned by the KEP in this instance?

Comment on lines +152 to +159
if !assert.NoError(t, err) {
t.FailNow()
}
if !assert.Equal(t,
strings.TrimSpace(tt.expectedFn),
strings.TrimSpace(string(b))) {
t.FailNow()
}
Copy link
Member

Choose a reason for hiding this comment

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

This is more code-style-related, so feel free to disregard if you have a preference: could we use require.NoError() and require.Equal() for brevity in these assertions?

@stormqueen1990
Copy link
Member

Apologies for a bunch of lint fixes in this PR to make the linter happy.

The tests which had been failing initially on the PR having been passing locally. The recent push should re-trigger the tests to ensure that it is not a flake.

How do you feel about splitting the formatting changes that happened in files unrelated to this implementation into a new PR?

@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 7, 2024
Comment on lines +270 to +287
content, err := ldr.Load(path)
if err != nil {
return nil, errors.WrapPrefixf(err, "unable to load catalog path")
}

j, err := yaml.YAMLToJSON(content)
if err != nil {
return nil, errors.WrapPrefixf(err, "invalid catalog")
}

dec := json.NewDecoder(bytes.NewReader(j))
dec.DisallowUnknownFields()

var c framework.Catalog
if err := dec.Decode(&c); err != nil {
return nil, errors.WrapPrefixf(err, "unable to find catalog")
}
catalogs = append(catalogs, c)
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to move this logic to a separate function for better readability, keeping the methods short and better testing.

Comment on lines +54 to +60
if krmFunc.Group == resGroup && krmFunc.Names.Kind == resKind {
for _, version := range krmFunc.Versions {
if version.Name == resVersion {
return &version.Runtime, nil
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is deep nesting here. Better to move this section to a different function with a descriptive method name.

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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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

4 participants