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

update openapi scripts to fetch protobuffer schemas #4582

Merged
merged 5 commits into from Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/krusty/openapitests/openapicustomschema_test.go
Expand Up @@ -421,7 +421,7 @@ spec:
- image: nginx
name: server
`)
assert.Equal(t, "v1212", openapi.GetSchemaVersion())
assert.Equal(t, "v1.21.2", openapi.GetSchemaVersion())
})
}

Expand Down Expand Up @@ -580,7 +580,7 @@ spec:
containers:
- image: whatever
`)
assert.Equal(t, "v1212", openapi.GetSchemaVersion())
assert.Equal(t, "v1.21.2", openapi.GetSchemaVersion())
})
}

Expand Down
18 changes: 9 additions & 9 deletions kyaml/openapi/Makefile
Expand Up @@ -5,8 +5,8 @@ MYGOBIN = $(shell go env GOBIN)
ifeq ($(MYGOBIN),)
MYGOBIN = $(shell go env GOPATH)/bin
endif
API_VERSION := "v1.21.2"
natasha41575 marked this conversation as resolved.
Show resolved Hide resolved
KIND_VERSION := "v0.11.1"
API_VERSION ?= "v1.21.2"

.PHONY: all
natasha41575 marked this conversation as resolved.
Show resolved Hide resolved
all: \
Expand All @@ -28,7 +28,7 @@ nuke: clean
rm -r kubernetesapi/*

$(MYGOBIN)/go-bindata:
go install github.com/go-bindata/go-bindata/v3/go-bindata
go install github.com/go-bindata/go-bindata/v3/go-bindata@latest

$(MYGOBIN)/kind:
( \
Expand All @@ -40,22 +40,22 @@ $(MYGOBIN)/kind:
rm -rf $$d; \
)

.PHONY: kubernetesapi/openapiinfo.go
kubernetesapi/openapiinfo.go:
./scripts/makeOpenApiInfoDotGo.sh

kustomizationapi/swagger.go: $(MYGOBIN)/go-bindata kustomizationapi/swagger.json
$(MYGOBIN)/go-bindata \
--pkg kustomizationapi \
-o kustomizationapi/swagger.go \
kustomizationapi/swagger.json

.PHONY: kubernetesapi/openapiinfo.go
kubernetesapi/openapiinfo.go:
./scripts/makeOpenApiInfoDotGo.sh

.PHONY: kubernetesapi/swagger.json
kubernetesapi/swagger.json: $(MYGOBIN)/kind $(MYGOBIN)/kustomize
.PHONY: kubernetesapi/swagger.pb
kubernetesapi/swagger.pb: $(MYGOBIN)/kind $(MYGOBIN)/kustomize
./scripts/fetchSchemaFromCluster.sh $(API_VERSION)

.PHONY: kubernetesapi/swagger.go
kubernetesapi/swagger.go: $(MYGOBIN)/go-bindata kubernetesapi/swagger.json
kubernetesapi/swagger.go: $(MYGOBIN)/go-bindata kubernetesapi/swagger.pb
./scripts/generateSwaggerDotGo.sh $(API_VERSION)

$(MYGOBIN)/kustomize:
Expand Down
43 changes: 14 additions & 29 deletions kyaml/openapi/README.md
Expand Up @@ -22,22 +22,26 @@ make nuke

The compiled-in schema version should maximize API availability with respect to all actively supported Kubernetes versions. For example, while 1.20, 1.21 and 1.22 are the actively supported versions, 1.21 is the best choice. This is because 1.21 introduces at least one new API and does not remove any, while 1.22 removes a large set of long-deprecated APIs that are still supported in 1.20/1.21.

### Update the built-in schema to a new version
### Generating additional schema

In the Makefile in this directory, update the `API_VERSION` to your desired version.
If you'd like to change the default schema version, then in the Makefile in this directory, update the `API_VERSION` to your desired version.

You may need to update the version of Kind these scripts use by changing `KIND_VERSION` in the Makefile in this directory. You can find compatibility information in the [kind release notes](https://github.com/kubernetes-sigs/kind/releases).

In this directory, fetch the openapi schema and generate the
corresponding swagger.go for the kubernetes api:
In this directory, fetch the openapi schema, generate the
corresponding swagger.go for the kubernetes api, and update `kubernetesapi/openapiinfo.go`:

```
make all
make kustomizationapi/swagger.go
natasha41575 marked this conversation as resolved.
Show resolved Hide resolved
make kubernetesapi/swagger.go
make kubernetesapi/openapiinfo.go
```

The above command will update the [OpenAPI schema] and the [Kustomization schema]. It will
create a directory kubernetesapi/v1212 and store the resulting
swagger.json and swagger.go files there.
Then, follow the instructions in the next section to make the newly generated schema available for use.

You can optionally delete the old `swagger.pb` and `swagger.go` files if we no longer need to support that kubernetes version of
openapi data. Make sure you rerun `make kubernetesapi/openapiinfo.go` after deleting any old schemas.


#### Precomputations

Expand All @@ -55,25 +59,6 @@ make prow-presubmit-check >& /tmp/k.txt; echo $?

The exit code should be zero; if not, examine `/tmp/k.txt`.

## Generating additional schemas

Instead of replacing the default version, you can specify a desired version as part of the make invocation:

```
rm kubernetesapi/swagger.go
make kubernetesapi/swagger.go API_VERSION=v1.21.2
```

While the above commands generate the swagger.go files, they
do not make them available for use nor do they update the
info field reported by `kustomize openapi info`. To make the
newly fetched schema and swagger.go available:

```
rm kubernetesapi/openapiinfo.go
make kubernetesapi/openapiinfo.go
```

## Partial regeneration

You can also regenerate the kubernetes api schemas specifically with:
Expand All @@ -87,8 +72,8 @@ To fetch the schema without generating the swagger.go, you can
run:

```
rm kubernetesapi/swagger.json
make kubernetesapi/swagger.json
rm kubernetesapi/swagger.pb
make kubernetesapi/swagger.pb
```

Note that generating the swagger.go will re-fetch the schema.
6 changes: 3 additions & 3 deletions kyaml/openapi/kubernetesapi/openapiinfo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

249 changes: 0 additions & 249 deletions kyaml/openapi/kubernetesapi/v1212/swagger.go

This file was deleted.

249 changes: 249 additions & 0 deletions kyaml/openapi/kubernetesapi/v1_21_2/swagger.go

Large diffs are not rendered by default.