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

feat: kustomize rollout: add openapi to doc and examples #1371

Merged
merged 4 commits into from
Sep 3, 2021

Conversation

huikang
Copy link
Member

@huikang huikang commented Jul 26, 2021

  • openAPI schema for kustomize rollout

Signed-off-by: Hui Kang [email protected]

close #1210

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this is a chore.
  • The title of the PR is (a) conventional, (b) states what changed, and (c) suffixes the related issues number. E.g. "fix(controller): Updates such and such. Fixes #1234".
  • I've signed my commits with DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My builds are green. Try syncing with master if they are not.
  • My organization is added to USERS.md.

@sonarcloud
Copy link

sonarcloud bot commented Jul 26, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.9% 0.9% Duplication

@codecov
Copy link

codecov bot commented Jul 26, 2021

Codecov Report

Merging #1371 (9273141) into master (1353526) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1371   +/-   ##
=======================================
  Coverage   81.35%   81.35%           
=======================================
  Files         108      108           
  Lines       14505    14505           
=======================================
  Hits        11801    11801           
  Misses       2089     2089           
  Partials      615      615           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1353526...9273141. Read the comment docs.

@jessesuen
Copy link
Member

@huikang - did you hand code the rollout_cr_schema.json file? Is there not a way to auto-generate it?

@huikang
Copy link
Member Author

huikang commented Jul 26, 2021

Hi, @jessesuen , yeah, I handcoded rollout_cr_schema.json by adapting from this example. It seems to me the openapi data is flexible to customize different use case; I have not found any way to auto-generate the content from the k8s type. Please let me know if you are aware of any approach.

@jessesuen
Copy link
Member

This file:
https://github.com/argoproj/argo-rollouts/blob/master/pkg/apiclient/rollout/rollout.swagger.json

is autogenerated. I thought something similar would need to be done for Rollouts but with the SMP keys

@huikang
Copy link
Member Author

huikang commented Jul 27, 2021

This file:
https://github.com/argoproj/argo-rollouts/blob/master/pkg/apiclient/rollout/rollout.swagger.json

is autogenerated. I thought something similar would need to be done for Rollouts but with the SMP keys

Thanks. Let me look into the options of the open-api tool.

@huikang
Copy link
Member Author

huikang commented Jul 27, 2021

Hi, @jessesuen , just want to make sure I understand the problem correctly: the problem is that the content in https://github.com/argoproj/argo-rollouts/blob/master/pkg/apiclient/rollout/rollout.swagger.json misses some x-kubernetes-patch-merge-key and x-kubernetes-patch-strategy for certain properties. For example, in the definition of

type PodSpec struct {
  Containers []Container `json:"containers" patchStrategy:"merge" patchMergeKey:"name" ...`

the containers has the patchStrategy and patchMergeKey, however, the generated rollout.swagger.json misses x-kubernetes-patch-merge-key and x-kubernetes-patch-strategy.

So we need to figure our how to let

PATH=${DIST_DIR}:$$PATH protoc \
attach these annotations in the generated json file.

Is my understanding correct? Thanks.

@jessesuen
Copy link
Member

Yes, that is correct. The goal is for kustomize 4 to be able to patch rollouts in the same way as deployments. If we can achieve this via automation that would be ideal, but not sure if that is possible.

@huikang
Copy link
Member Author

huikang commented Jul 28, 2021

Yes, that is correct. The goal is for kustomize 4 to be able to patch rollouts in the same way as deployments. If we can achieve this via automation that would be ideal, but not sure if that is possible.

Following is my findings:

  1. This is how k8s api is exposed as a json file:

https://github.com/kubernetes/kubernetes/blob/ea0764452222146c47ec826977f49d7001b0ea8c/hack/update-openapi-spec.sh#L101

  1. In addition, I found that the kustomize openapi fetch returns
    "io.argoproj.v1alpha1.Rollout": {
      "properties": {
        "apiVersion": {
          "type": "string"
        },
        "kind": {
          "type": "string"
        },
        "metadata": {
          "$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta",
          "description": "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata"
        },
        "spec": {
            "template": {
              "properties": {
                "metadata": {
                  "properties": {
                    "annotations": {
                      "additionalProperties": {
                        "type": "string"

If I change the key "template" to

"template": {
              "$ref": "#/definitions/io.k8s.api.core.v1.PodTemplateSpec"
            }

The SMP would work. Not sure why the original one does not use the reference definition.

@alexmt
Copy link
Contributor

alexmt commented Sep 1, 2021

@huikang , I think I found a way to generate schema. There is no out of the box generator unfortunatelly so I had to write more go code in gen-crd-spec/main.go.

We need tests and documentation changes from your PR so I've sent PR to your fork: huikang#1 . Once it is merged this PR should be complete. Can you please take a look?

@huikang
Copy link
Member Author

huikang commented Sep 1, 2021

@huikang , I think I found a way to generate schema. There is no out of the box generator unfortunatelly so I had to write more go code in gen-crd-spec/main.go.

We tests and documentation changes from your PR so I've sent PR to your fork: huikang#1 . Once it is merged this PR should be complete. Can you please take a look?

Sounds good. Thanks, @alexmt !

- openAPI schema for kustomize rollout

Signed-off-by: Hui Kang <[email protected]>
@huikang huikang force-pushed the 1210-genenerate-x-kubernetes-patch branch from ffeb3f5 to c5ac0f9 Compare September 3, 2021 16:53
Signed-off-by: Alexander Matyushentsev <[email protected]>
Signed-off-by: Hui Kang <[email protected]>
@huikang huikang force-pushed the 1210-genenerate-x-kubernetes-patch branch from c5ac0f9 to 1892ff0 Compare September 3, 2021 16:54
@huikang huikang force-pushed the 1210-genenerate-x-kubernetes-patch branch from 00348eb to de9c211 Compare September 3, 2021 17:05
@huikang
Copy link
Member Author

huikang commented Sep 3, 2021

Hi, @alexmt , I have merged your commit and cleaned up the PR a bit. However, when the new command failed due to the following error

go run ./hack/gen-crd-spec/main.go
panic: Version string empty

goroutine 1 [running]:
main.checkErr(...)
	/Users/hui.kang/go/src/github.com/huikang/argo-rollouts-backup2/hack/gen-crd-spec/main.go:287
main.main()
	/Users/hui.kang/go/src/github.com/huikang/argo-rollouts-backup2/hack/gen-crd-spec/main.go:467 +0x5d3
exit status 2

Could you take a look? Thanks.

@sonarcloud
Copy link

sonarcloud bot commented Sep 3, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

genenerate x-kubernetes-patch-merge-key and x-kubernetes-patch-strategy
3 participants