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

Check if required setters are set #2670

Merged

Conversation

phanimarupaka
Copy link
Contributor

@phanimarupaka phanimarupaka commented Jun 30, 2020

@mortent @pwittrock

This PR is to make check for all the setters and return error if a package consumer didn't set the setters which are marked as required by package publisher. This is a follow up PR for the PR in kustomize #2635. Description in the kustomize PR and test cases in current PR clearly describe the expected behavior.

The motivation for this PR is to address the feature request kptdev/kpt#261

@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 Jun 30, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: phanimarupaka

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 Jun 30, 2020
requiredVal := required.Document().Value
println(requiredVal)

isSet, err := definitions.Pipe(yaml.Lookup(key, "x-k8s-cli", "setter", "isSet"))
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe just test err != nil by itself?

then check the requiredVal stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR with new implementation.

continue
}
requiredVal := required.Document().Value
println(requiredVal)
Copy link
Contributor

Choose a reason for hiding this comment

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

is println intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seeped in by mistake. Thanks.

@mortent
Copy link
Member

mortent commented Jun 30, 2020

As discussed offline, I think we should try to check this using the openapi api, assuming any krm files have already been read and any definitions merged into the schema.

@phanimarupaka
Copy link
Contributor Author

@mortent Done.

@mortent
Copy link
Member

mortent commented Jun 30, 2020

Looks good to me. I'll give @pwittrock some time to take a look too.


// CheckRequiredSettersSet iterates through all the setter definitions in openAPI
// schema and returns error if any of the setter has required field true and isSet false
func CheckRequiredSettersSet() error {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Could we put this at least in a separate file? It doesn't seem to really have anything to do with listing setters.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mortent Done.

dir, err := ioutil.TempDir("", "")
assert.NoError(t, err)
defer os.RemoveAll(dir)
err = ioutil.WriteFile(filepath.Join(dir, "kustomization"), []byte(test.inputOpenAPIfile), 0600)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Krmfile instead

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

@pwittrock
Copy link
Contributor

Looks good from my end. Address the nits.

@mortent
Copy link
Member

mortent commented Jun 30, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit 7259d3e into kubernetes-sigs:master Jun 30, 2020
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants