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

generate CRD manifests and fix for oc explain #1485

Merged

Conversation

yuqi-zhang
Copy link
Contributor

There are 3 commits in this change that aims to add OpenAPIV3 validation and get oc explain to work for MCO repo CRDS. Note that this does NOT include the actual generator code, this that does not current work with the MCO repo manifests. Will open another PR with the generator and explain what needs to be fixed for that to work, but for now this should get oc explain going.

Commit 1:
Generate crd manifests with OpenAPIV3 schemas

Generate validation for:

containerruntimeconfig
controllerconfig
kubeletconfig
machineconfig
machineconfigpool

Using update-codegen-crds target from
https://github.com/openshift/build-machinery-go, which will be
included in a separate commit as it is not directly usable with the
MCO repo until coreos/ignition#917 is
resolved. The current generation is done via hacking ignition's
config/v2_2/types/schema.go to have dummy json:",inline" for fields
that are causing errors.

Some background on this, there were 2 attempts to add generated
schemas in: #1403
and #955.
This supercedes those with updated generation methods.

Commit 2:
Fix autogenerated crd schemas for oc explain

Now that we have generated schemas, for oc explain to work we need to
turn on validation via preserveUnknownFields: false in the spec.

There is also one error in the autogenerated machineconfigpool spec
due to IntOrString, see: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#intorstring

Also minor formatting in machineconfig.crd.yaml.

Commit 3:
update generated bindata after crd changes

Generate validation for:

containerruntimeconfig
controllerconfig
kubeletconfig
machineconfig
machineconfigpool

Using update-codegen-crds target from
https://github.com/openshift/build-machinery-go, which will be
included in a separate commit as it is not directly usable with the
MCO repo until coreos/ignition#917 is
resolved. The current generation is done via hacking ignition's
config/v2_2/types/schema.go to have dummy `json:",inline"` for fields
that are causing errors.

Some background on this, there were 2 attempts to add generated
schemas in: openshift#1403
and openshift#955.
This supercedes those with updated generation methods.

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
Now that we have generated schemas, for oc explain to work we need to
turn on validation via preserveUnknownFields: false in the spec.

There is also one error in the autogenerated machineconfigpool spec
due to IntOrString, see: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#intorstring

Also minor formatting in machineconfig.crd.yaml.

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Feb 18, 2020
@openshift-ci-robot
Copy link
Contributor

@yuqi-zhang: This pull request references Bugzilla bug 1705750, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Bug 1705750: generate CRD manifests and fix for oc explain

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.

@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 18, 2020
@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 18, 2020
@yuqi-zhang
Copy link
Contributor Author

/retest

items:
type: string
homeDir:
type: string
Copy link
Contributor

Choose a reason for hiding this comment

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

We don’t support all these ignition fields. I think it’s only the ones we had that we allow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, I will look to manually edit for now, unless you know of a better method we can source these MCO-specific use-cases.

@runcom
Copy link
Member

runcom commented Feb 18, 2020

awesome 👍

/approve

will leave to the team to further take a look and address comments, well done!

@yuqi-zhang
Copy link
Contributor Author

/retest

1 similar comment
@yuqi-zhang
Copy link
Contributor Author

/retest

@sinnykumari
Copy link
Contributor

Interesting error from e2e tests failure

 msg="Cluster operator support Disabled is True with NotAuthorized: Reporting was not allowed: your Red Hat account is not enabled for remote support or your token has expired"

@yuqi-zhang
Copy link
Contributor Author

/retest

Will fix up the descriptions. In the meantime let's see if that was a flake

@yuqi-zhang
Copy link
Contributor Author

As per review, added back descriptions and removed unused fields. Note that oc explain doesn't show these fields anyways.

@sinnykumari
Copy link
Contributor

looks good, needs bindata update

Manually modify machineconfig crd fields to have description fields
again. Also remove unused fields.

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
Run ./hack/update-generated-bindata.sh

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
@yuqi-zhang
Copy link
Contributor Author

Re-gen'ed bindata and re-ordered commits a bit. Should be good to go.

@yuqi-zhang yuqi-zhang changed the title Bug 1705750: generate CRD manifests and fix for oc explain generate CRD manifests and fix for oc explain Feb 24, 2020
@openshift-ci-robot openshift-ci-robot removed the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Feb 24, 2020
@openshift-ci-robot
Copy link
Contributor

@yuqi-zhang: No Bugzilla bug is referenced in the title of this pull request.
To reference a bug, add 'Bug XXX:' to the title of this pull request and request another bug refresh with /bugzilla refresh.

In response to this:

generate CRD manifests and fix for oc explain

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.

@yuqi-zhang
Copy link
Contributor Author

Removing BZ as well since this is now targeting master

@yuqi-zhang
Copy link
Contributor Author

/retest

one throttling one api

@yuqi-zhang yuqi-zhang linked an issue Feb 25, 2020 that may be closed by this pull request
Add nullable to additionalTrustBundle, cloudProviderCAData, proxy,
and kernelArguments, as they will otherwise be generated as null
during CI runs, and the validation will cause it to fail.

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
@yuqi-zhang
Copy link
Contributor Author

Ok, I changed it to nullable instead of omitempty and it passed CI.

Also note that there are potentially other fields that need to be nullable. Basically any field that can be null (and is not omitempty-able) will fail validation. Are there a lot of potential issues outside what CI can cover?

@yuqi-zhang
Copy link
Contributor Author

Ah, so one more thing, since in TestReconcileAfterBadMC we try to give it a bad MC with networkd section and wait for it to degrade, that now fails since the validation straight up rejects the MC. I think we should change that test, and then add a test case for e.g. #1443 (once we fix that that is).

@ashcrow
Copy link
Member

ashcrow commented Feb 26, 2020

/test e2e-gcp-op

@yuqi-zhang
Copy link
Contributor Author

I think its not a flake but a change in behaviour, fixing now

This allows MCC/MCD to validate the ignition section instead, much
like we've always done. Otherwise, any non-valid ignition section
will instead get pruned by the validation.

A bit more background: for oc explain to work, we need to have

preserveUnknownFields: false

which means all fields not defined by the crd schema will be pruned
upon generation of the CR. Since we only define ignition sections
that are allowed, an invalid ignition spec field will simply get
removed when the machineconfig is created. Adding the flag tells
validation that anything under Config is allowed, and we will let
MCC/MCD do the validation instead, like we do today.

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
@yuqi-zhang
Copy link
Contributor Author

Ok I added x-kubernetes-preserve-unknown-fields: true to the whole Config section, which should fix the test failure.

A bit more background: for oc explain to work, we need to have

preserveUnknownFields: false

which means all fields not defined by the crd schema will be pruned upon generation of the CR. Since we only define ignition sections that are allowed to be machineconfig sections, an invalid ignition spec field will simply get removed when the machineconfig is created. Adding the flag tells validation that anything under Config is allowed, and we will let MCC/MCD do the validation instead, like we do today.

Now it may technically be more inline with the API to just let the fields be pruned, but I feel that disrupts existing user experience. And since we will be switching to RawExtention anyways, that will not be validate-able via the CRD validation, so we will eventually have to do this.

@sinnykumari
Copy link
Contributor

/retest

@runcom
Copy link
Member

runcom commented Feb 27, 2020

/approve

amazing :)

@sinnykumari
Copy link
Contributor

Nice work Jerry!
Will wait for the team for any final comments.
/approve

@yuqi-zhang
Copy link
Contributor Author

As a final clarification, this adds schema and schema validation for the manifests that live within our repo. This will enable oc explain to work properly, as well as validate new CRs that are applied before they hit the cluster, with the exception of Ignition section items, which we skip and let MCD make the call on whether its valid or not.

@kikisdeliveryservice
Copy link
Contributor

As a final clarification, this adds schema and schema validation for the manifests that live within our repo. This will enable oc explain to work properly, as well as validate new CRs that are applied before they hit the cluster, with the exception of Ignition section items, which we skip and let MCD make the call on whether its valid or not.

As per our conversation this sounds correct :)
FYI : @rphillips @umohnani8 since this affects kubelet and cr configs

/LGTM

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 27, 2020
@ericavonb
Copy link
Contributor

/lgtm

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ericavonb, kikisdeliveryservice, runcom, sinnykumari, yuqi-zhang

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:
  • OWNERS [ericavonb,kikisdeliveryservice,runcom,sinnykumari,yuqi-zhang]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yuqi-zhang
Copy link
Contributor Author

/cherry-pick release-4.4

@openshift-cherrypick-robot

@yuqi-zhang: once the present PR merges, I will cherry-pick it on top of release-4.4 in a new PR and assign it to you.

In response to this:

/cherry-pick release-4.4

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.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-cherrypick-robot

@yuqi-zhang: new pull request created: #1520

In response to this:

/cherry-pick release-4.4

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.

yuqi-zhang added a commit to yuqi-zhang/origin that referenced this pull request Feb 28, 2020
Now with openshift/machine-config-operator#1485
oc explain is working for *.machineconfiguration CRDs. Also remove
"mcoconfigs" as it does not seem to exist anywhere.

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
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. lgtm 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.

Add CRD openapi
10 participants