Merge pull request #3076 from natasha41575/fetchOpenAPIdata

Fetch openAPI data
This commit is contained in:
Jeff Regan
2020-10-14 08:20:27 -07:00
committed by GitHub
4 changed files with 146 additions and 4 deletions

76
hack/install_kpt.sh Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
# If no arguments are given -> Downloads the most recently released
# kpt binary to your current working directory.
# (e.g. 'install_kpt.sh')
#
# If one argument is given -> Downloads the specified version of the
# kpt binary to your current working directory.
# (e.g. 'install_kpt.sh 0.34.0')
#
# If two arguments are given -> Downloads the specified version of the
# kpt binary to the specified directory.
# (e.g. 'install_kpt.sh 0.34.0 $(go env GOPATH)/bin')
#
# Fails if the file already exists.
if [ -z "$1" ]; then
version=""
else
version=$1
fi
if [ -z "$2" ]; then
where=$PWD
else
where=$2
fi
if [ -f $where/kpt ]; then
echo "A file named kpt already exists (remove it first)."
exit 1
fi
tmpDir=`mktemp -d`
if [[ ! "$tmpDir" || ! -d "$tmpDir" ]]; then
echo "Could not create temp dir."
exit 1
fi
function cleanup {
rm -rf "$tmpDir"
}
trap cleanup EXIT
pushd $tmpDir >& /dev/null
opsys=windows
if [[ "$OSTYPE" == linux* ]]; then
opsys=linux
elif [[ "$OSTYPE" == darwin* ]]; then
opsys=darwin
fi
curl -s https://api.github.com/repos/GoogleContainerTools/kpt/releases |\
grep browser_download |\
grep $opsys |\
cut -d '"' -f 4 |\
grep /kpt/releases/download/v$version |\
sort | tail -n 1 |\
xargs curl -s -O -L
if [ -e ./kpt_${opsys}_amd64-*.tar.gz ]; then
tar xzf ./kpt_${opsys}_amd64-*.tar.gz
else
echo "Error: kpt binary with the version $version does not exist!"
exit 1
fi
cp ./kpt $where
popd >& /dev/null
$where/kpt version
echo kpt installed to specified directory.

View File

@@ -1,10 +1,11 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
.PHONY: generate license fix vet fmt test lint tidy openapi
MYGOBIN := $(shell go env GOPATH)/bin
GOPATH := $(shell go env GOPATH)
export PATH := $(MYGOBIN):$(PATH)
.PHONY: generate license fix vet fmt test lint tidy openapi schema
all: generate license fix vet fmt test lint tidy
fix:
@@ -39,6 +40,30 @@ vet:
# likely related to https://github.com/kubernetes/kubernetes/issues/39188
openapi:
sed -i 's/"x-kubernetes-patch-merge-key": "containerPort"/"x-kubernetes-patch-merge-key": "name"/g' 'openapi/kubernetesapi/swagger.json'
(which $(GOPATH)/bin/go-bindata || go get -v github.com/go-bindata/go-bindata)
(which $(GOPATH)/bin/go-bindata || go get -u github.com/go-bindata/go-bindata/...)
$(GOPATH)/bin/go-bindata --pkg kubernetesapi -o openapi/kubernetesapi/swagger.go openapi/kubernetesapi/swagger.json
$(GOPATH)/bin/go-bindata --pkg kustomizationapi -o openapi/kustomizationapi/swagger.go openapi/kustomizationapi/swagger.json
$(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)
API_VERSION="v1.19.1"
schema: $(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 openapi/kubernetesapi/swagger.json

36
kyaml/openapi/README.md Normal file
View File

@@ -0,0 +1,36 @@
# 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.
### Fetching the Schema
In the [kyaml] directory, fetch the schema
```
make schema
```
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
```
This will update the [OpenAPI schema].
### Generating Swagger.go
In the [kyaml] directory, generate the swagger.go files.
```
make openapi
```
### Run all tests
In the [home] directory, 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

@@ -10,6 +10,7 @@
[semver release]: #semver-review
[`cloudbuild.yaml`]: cloudbuild.yaml
[kustomize repo release page]: https://github.com/kubernetes-sigs/kustomize/releases
[OpenAPI Readme]: ../kyaml/openapi/README.md
This document describes how to perform a [semver release]
of one of the several [Go modules] in this repository.
@@ -28,6 +29,11 @@ The dependencies determine the release order:
Thus, do `kyaml` first, then `cli-utils`, etc.
#### Consider fetching new OpenAPI data
The Kubernetes OpenAPI data changes no more frequently than once per quarter. Instructions
on how to get a new OpenAPI sample can be found in the
[OpenAPI Readme].
#### Establish clean state
```
@@ -142,7 +148,6 @@ this should be automated, and descriptions in PR's should
be standardized to make automation possible.
See kubebuilder project.
## Public Modules
[`sigs.k8s.io/cli-utils`]: #sigsk8siocli-utils