Refactor making of openapi generated files.

This commit is contained in:
jregan
2020-10-16 18:32:15 -07:00
parent 495f6df973
commit dc8439fbfa
6 changed files with 118 additions and 65 deletions

62
kyaml/openapi/Makefile Normal file
View File

@@ -0,0 +1,62 @@
# Copyright 2020 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
MYGOBIN := $(shell go env GOPATH)/bin
.PHONY: all
all: \
kustomizationapi/swagger.go \
kubernetesapi/swagger.go \
kubernetesapi/openapiinfo.go
.PHONY: clean
clean:
rm kustomizationapi/swagger.go
rm kubernetesapi/swagger.go
rm kubernetesapi/openapiinfo.go
# To get swagger.json, we need a cluster at the correct version,
# so think twice before deleting.
.PHONY: nuke
nuke: clean
rm kubernetesapi/swagger.json
$(MYGOBIN)/go-bindata:
go install github.com/go-bindata/go-bindata/v3/go-bindata
$(MYGOBIN)/kind:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget -O ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(shell uname)-amd64; \
chmod +x ./kind; \
mv ./kind $(MYGOBIN); \
rm -rf $$d; \
)
$(MYGOBIN)/kpt:
../../hack/install_kpt.sh 0.34.0 $(MYGOBIN)
kubernetesapi/swagger.go: $(MYGOBIN)/go-bindata kubernetesapi/swagger.json
$(MYGOBIN)/go-bindata \
--pkg kubernetesapi \
-o kubernetesapi/swagger.go \
kubernetesapi/swagger.json
kustomizationapi/swagger.go: $(MYGOBIN)/go-bindata kustomizationapi/swagger.json
$(MYGOBIN)/go-bindata \
--pkg kustomizationapi \
-o kustomizationapi/swagger.go \
kustomizationapi/swagger.json
kubernetesapi/openapiinfo.go: kubernetesapi/swagger.json
./makeOpenApiInfoDotGo.sh kubernetesapi/swagger.json
API_VERSION="v1.19.1"
kubernetesapi/swagger.json: $(MYGOBIN)/kind $(MYGOBIN)/kpt
cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true
$(MYGOBIN)/kind create cluster --image kindest/node:$(API_VERSION) --name=getopenapidata
$(MYGOBIN)/kpt live fetch-k8s-schema --pretty-print > /tmp/new_swagger.json
$(MYGOBIN)/kind delete cluster --name=getopenapidata
cp /tmp/kubeconfig.txt $(HOME)/.kube/config | true
cp /tmp/new_swagger.json kubernetesapi/swagger.json

View File

@@ -1,36 +1,42 @@
# Sampling New OpenAPI Data
[kyaml]: ../
[OpenAPI schema]: ./kubernetesapi/swagger.json
[home]: ../../
This document describes how to fetch OpenAPI data from
a particular kubernetes version number.
a particular kubernetes version number.
### Fetching the Schema
In this directory, fetch the openapi schema for the kubernetes api:
### Fetching the Schema
In the [kyaml] directory, fetch the schema
```
make schema
make nuke
make kubernetesapi/swagger.json
```
You can specify a specific version with the "API_VERSION"
You can specify a specific version with the "API_VERSION"
parameter. The default version is v1.19.1. Here is an
example for fetching the data for v1.14.1.
```
make schema API_VERSION=v1.14.1
make kubernetesapi/swagger.json API_VERSION=v1.14.1
```
This will update the [OpenAPI schema].
This will update the [OpenAPI schema].
### Generating Swagger.go
In the [kyaml] directory, generate the swagger.go files.
In this directory, generate the swagger.go files.
```
make openapi
make
```
### Run all tests
In the [home] directory, run the tests.
At the top of the repository, run the tests.
```
make prow-presubmit-check >& /tmp/k.txt; echo $?
# The exit code should be zero; if not examine /tmp/k.txt
```
```

View File

@@ -1,8 +1,8 @@
// Copyright 2019 The Kubernetes Authors.
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Code generated by ./makeOpenApiInfoDotGo.sh; DO NOT EDIT.
package kubernetesapi
const Info = "{ title:Kubernetes, version:v1.17.0 }"
const Info = "{title:Kubernetes,version:v1.17.0}"

View File

@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright 2020 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
set -e
if ! command -v jq &> /dev/null ; then
echo Please install jq
echo on ubuntu: sudo apt-get install jq
exit 1
fi
OPEN_API_INFO=$(\
jq -r '.info' $1 | \
sed 's/[\" *]//g' | \
tr -d '\n' )
cat <<EOF >kubernetesapi/openapiinfo.go
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Code generated by $0; DO NOT EDIT.
package kubernetesapi
const Info = "$OPEN_API_INFO"
EOF