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

test: add unit test for local crds client #46

Merged
merged 4 commits into from
May 30, 2023

Conversation

eddycharly
Copy link
Contributor

@eddycharly eddycharly commented May 25, 2023

This PR adds unit tests for local crds client.

Fixes #44
Fixes #47

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 25, 2023
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 25, 2023
@eddycharly
Copy link
Contributor Author

eddycharly commented May 25, 2023

I think we need to support yaml files with multiple objects too.
Will add once #12 lands in.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 25, 2023
@eddycharly eddycharly changed the title test: add unit test for local crds test: add unit test for local crds client May 25, 2023
@eddycharly
Copy link
Contributor Author

@alexzielenski this should be good !

Copy link
Contributor

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

/approve

withholding lgtm for now for a few nits

nsScoped := namespaced.Has(gvk)
// Check schema extensions to see if the scope was manually added
if scope, ok := def.Extensions.GetString("x-kubectl-validate-scope"); ok {
nsScoped = scope == strings.ToLower(string(apiextensions.NamespaceScoped))
Copy link
Contributor

Choose a reason for hiding this comment

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

probably want some integration tests that this is getting correctly propagated by:

  1. validating yaml for namespace-scoped resource that has no namespace specified
  2. validating yaml for cluster-scoped resource that has namespace specified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i can add some tests later if it's ok

sch.AddExtension("x-kubernetes-group-version-kind", []interface{}{gvkObj})

// Add schema extension to propagate the scope
sch.AddExtension("x-kubectl-validate-scope", strings.ToLower(string(crd.Spec.Scope)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the value of this is an enum, I think it is more correct to leave the CamelCase version as we do in CRDs themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

nsScoped := namespaced.Has(gvk)
// Check schema extensions to see if the scope was manually added
if scope, ok := def.Extensions.GetString("x-kubectl-validate-scope"); ok {
nsScoped = scope == strings.ToLower(string(apiextensions.NamespaceScoped))
Copy link
Contributor

Choose a reason for hiding this comment

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

use lowercase version of both strings for comparison (considering case where users custom schemas use this to communicate the scope, not just internal code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

considering case where users custom schemas use this to communicate the scope, not just internal code

what does that mean ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

considering case where users custom schemas use this to communicate the scope, not just internal code

i switched to lowercase version of both strings for comparison but not sure to understand the sentence above

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 28, 2023
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 28, 2023
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Copy link
Contributor

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

thanks for adding this!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexzielenski, eddycharly

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 merged commit 310a078 into kubernetes-sigs:main May 30, 2023
5 checks passed
eyarz pushed a commit to eyarz/kubectl-validate that referenced this pull request Jul 5, 2023
test: add unit test for local crds client
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

Infer namespace/cluster scope when using schema extension Unit Tests for CRDs Client
3 participants