From a422c935d8c70a701ba6a68d506314f8169edf2d Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Thu, 8 Oct 2020 22:18:41 +0000 Subject: [PATCH 01/11] added make target to fetch new openapi schema --- kyaml/Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kyaml/Makefile b/kyaml/Makefile index 8ef332976..614848f5e 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -42,3 +42,15 @@ openapi: (which $(GOPATH)/bin/go-bindata || go get -v 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 + +VERSION="v1.19.1" +schema: + which $(GOPATH)/bin/kind || GO111MODULE=on go get sigs.k8s.io/kind@v0.9.0 + which $(GOPATH)/bin/kpt || GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt + cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true + $(GOPATH)/bin/kind create cluster --image kindest/node:$(VERSION) --name=getopenapidata + $(GOPATH)/bin/kpt live fetch-k8s-schema --pretty-print > openapi/kubernetesapi/swagger.json + kind delete cluster --name=getopenapidata + cp /tmp/kubeconfig.txt $(HOME)/.kube/config | true + + From 1cf876927de29f7430a720f4bdd136b90088d29f Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Thu, 8 Oct 2020 15:39:12 -0700 Subject: [PATCH 02/11] minor makefile fix --- kyaml/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyaml/Makefile b/kyaml/Makefile index 614848f5e..864521cf9 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -50,7 +50,7 @@ schema: cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true $(GOPATH)/bin/kind create cluster --image kindest/node:$(VERSION) --name=getopenapidata $(GOPATH)/bin/kpt live fetch-k8s-schema --pretty-print > openapi/kubernetesapi/swagger.json - kind delete cluster --name=getopenapidata + $(GOPATH)/bin/kind delete cluster --name=getopenapidata cp /tmp/kubeconfig.txt $(HOME)/.kube/config | true From 1f595da9ad7c9465438d963da92a8e73949cd303 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Thu, 8 Oct 2020 15:57:34 -0700 Subject: [PATCH 03/11] updated way to fetch go-bindata --- kyaml/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyaml/Makefile b/kyaml/Makefile index 864521cf9..c921aa354 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -39,7 +39,7 @@ 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 From b1e01b238b5362e079130fddf41ae9423d11467e Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Thu, 8 Oct 2020 16:44:45 -0700 Subject: [PATCH 04/11] updated documentation --- kyaml/openapi/README.md | 36 ++++++++++++++++++++++++++++++++++++ releasing/README.md | 5 +++++ 2 files changed, 41 insertions(+) create mode 100644 kyaml/openapi/README.md diff --git a/kyaml/openapi/README.md b/kyaml/openapi/README.md new file mode 100644 index 000000000..90f91c8cf --- /dev/null +++ b/kyaml/openapi/README.md @@ -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 "VERSION" +parameter. The default version is v1.19.1. Here is an +example for fetching the data for v1.14.1. +``` +make schema 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 +``` \ No newline at end of file diff --git a/releasing/README.md b/releasing/README.md index f492d2556..b4ee28b66 100644 --- a/releasing/README.md +++ b/releasing/README.md @@ -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. @@ -142,6 +143,10 @@ this should be automated, and descriptions in PR's should be standardized to make automation possible. See kubebuilder project. +#### Fetching New OpenAPI Data +The Kubernetes OpenAPI data changes once per quarter. Instructions +on how to get a new OpenAPI sample can be found in the +[OpenAPI Readme]. ## Public Modules From 01beba86979e8b24dc7ca435007a272a0cff735c Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Thu, 8 Oct 2020 16:46:16 -0700 Subject: [PATCH 05/11] formatting documentation: --- kyaml/openapi/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kyaml/openapi/README.md b/kyaml/openapi/README.md index 90f91c8cf..887a376a6 100644 --- a/kyaml/openapi/README.md +++ b/kyaml/openapi/README.md @@ -7,7 +7,7 @@ This document describes how to fetch OpenAPI data from a particular kubernetes version number. -###Fetching the Schema +### Fetching the Schema In the [kyaml] directory, fetch the schema ``` make schema @@ -22,13 +22,13 @@ make schema VERSION=v1.14.1 This will update the [OpenAPI schema]. -###Generating Swagger.go +### Generating Swagger.go In the [kyaml] directory, generate the swagger.go files. ``` make openapi ``` -###Run all tests +### Run all tests In the [home] directory, run the tests. ``` make prow-presubmit-check >& /tmp/k.txt; echo $? From 1dfc9a88a82be478c5b5465146eeba8e14517ba1 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Fri, 9 Oct 2020 12:31:14 -0700 Subject: [PATCH 06/11] moved openapi instructions to top of readme --- releasing/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/releasing/README.md b/releasing/README.md index b4ee28b66..a5f0efe0b 100644 --- a/releasing/README.md +++ b/releasing/README.md @@ -29,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 once per quarter. Instructions +on how to get a new OpenAPI sample can be found in the +[OpenAPI Readme]. + #### Establish clean state ``` @@ -143,11 +148,6 @@ this should be automated, and descriptions in PR's should be standardized to make automation possible. See kubebuilder project. -#### Fetching New OpenAPI Data -The Kubernetes OpenAPI data changes once per quarter. Instructions -on how to get a new OpenAPI sample can be found in the -[OpenAPI Readme]. - ## Public Modules [`sigs.k8s.io/cli-utils`]: #sigsk8siocli-utils From 430665e9847c19194550e8c4a5f85e8a77070084 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 13 Oct 2020 13:21:19 -0700 Subject: [PATCH 07/11] version -> api_version --- kyaml/Makefile | 4 ++-- kyaml/openapi/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kyaml/Makefile b/kyaml/Makefile index c921aa354..f165cdf2d 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -43,12 +43,12 @@ openapi: $(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 -VERSION="v1.19.1" +API_VERSION="v1.19.1" schema: which $(GOPATH)/bin/kind || GO111MODULE=on go get sigs.k8s.io/kind@v0.9.0 which $(GOPATH)/bin/kpt || GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true - $(GOPATH)/bin/kind create cluster --image kindest/node:$(VERSION) --name=getopenapidata + $(GOPATH)/bin/kind create cluster --image kindest/node:$(API_VERSION) --name=getopenapidata $(GOPATH)/bin/kpt live fetch-k8s-schema --pretty-print > openapi/kubernetesapi/swagger.json $(GOPATH)/bin/kind delete cluster --name=getopenapidata cp /tmp/kubeconfig.txt $(HOME)/.kube/config | true diff --git a/kyaml/openapi/README.md b/kyaml/openapi/README.md index 887a376a6..52920d2bf 100644 --- a/kyaml/openapi/README.md +++ b/kyaml/openapi/README.md @@ -13,11 +13,11 @@ In the [kyaml] directory, fetch the schema make schema ``` -You can specify a specific version with the "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 VERSION=v1.14.1 +make schema API_VERSION=v1.14.1 ``` This will update the [OpenAPI schema]. From e107020bd23870ec24e56dd6effc5f84c0d229f5 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 13 Oct 2020 13:53:25 -0700 Subject: [PATCH 08/11] edited make schema for kyaml --- kyaml/Makefile | 11 ++++++++--- releasing/README.md | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/kyaml/Makefile b/kyaml/Makefile index f165cdf2d..0eb4acb8b 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -43,14 +43,19 @@ openapi: $(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 -API_VERSION="v1.19.1" -schema: +kind: which $(GOPATH)/bin/kind || GO111MODULE=on go get sigs.k8s.io/kind@v0.9.0 + +kpt: which $(GOPATH)/bin/kpt || GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt + +API_VERSION="v1.19.1" +schema: kind kpt cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true $(GOPATH)/bin/kind create cluster --image kindest/node:$(API_VERSION) --name=getopenapidata - $(GOPATH)/bin/kpt live fetch-k8s-schema --pretty-print > openapi/kubernetesapi/swagger.json + $(GOPATH)/bin/kpt live fetch-k8s-schema --pretty-print > /tmp/new_swagger.json $(GOPATH)/bin/kind delete cluster --name=getopenapidata cp /tmp/kubeconfig.txt $(HOME)/.kube/config | true + cp /tmp/new_swagger.json openapi/kubernetesapi/swagger.json diff --git a/releasing/README.md b/releasing/README.md index a5f0efe0b..5d23bd7e1 100644 --- a/releasing/README.md +++ b/releasing/README.md @@ -30,7 +30,7 @@ The dependencies determine the release order: Thus, do `kyaml` first, then `cli-utils`, etc. #### Consider fetching new OpenAPI data -The Kubernetes OpenAPI data changes once per quarter. Instructions +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]. From 222b2d4485e1aaa93b85e4149718f442a5ae9324 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 13 Oct 2020 16:25:29 -0700 Subject: [PATCH 09/11] added MYGOBIN variable for kind --- kyaml/Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kyaml/Makefile b/kyaml/Makefile index 0eb4acb8b..46130237b 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -1,7 +1,9 @@ # 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 + +.PHONY: generate license fix vet fmt test lint tidy openapi schema GOPATH := $(shell go env GOPATH) @@ -43,18 +45,18 @@ openapi: $(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 -kind: - which $(GOPATH)/bin/kind || GO111MODULE=on go get sigs.k8s.io/kind@v0.9.0 +$(MYGOBIN)/kind: + GO111MODULE=on go get sigs.k8s.io/kind@v0.9.0 kpt: which $(GOPATH)/bin/kpt || GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt API_VERSION="v1.19.1" -schema: kind kpt +schema: $(MYGOBIN)/kind kpt cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true - $(GOPATH)/bin/kind create cluster --image kindest/node:$(API_VERSION) --name=getopenapidata + $(MYGOBIN)/kind create cluster --image kindest/node:$(API_VERSION) --name=getopenapidata $(GOPATH)/bin/kpt live fetch-k8s-schema --pretty-print > /tmp/new_swagger.json - $(GOPATH)/bin/kind delete cluster --name=getopenapidata + $(MYGOBIN)/kind delete cluster --name=getopenapidata cp /tmp/kubeconfig.txt $(HOME)/.kube/config | true cp /tmp/new_swagger.json openapi/kubernetesapi/swagger.json From de8e16df1553dc11cd4aea45bdf182332cd1f6e4 Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 13 Oct 2020 17:11:00 -0700 Subject: [PATCH 10/11] added script for installing kpt --- hack/install_kpt.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 hack/install_kpt.sh diff --git a/hack/install_kpt.sh b/hack/install_kpt.sh new file mode 100755 index 000000000..c10ff62e8 --- /dev/null +++ b/hack/install_kpt.sh @@ -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. From 1386ec3850cbda94af3635b5b644e682a7c22f2c Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Tue, 13 Oct 2020 17:19:03 -0700 Subject: [PATCH 11/11] edited kpt target --- kyaml/Makefile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/kyaml/Makefile b/kyaml/Makefile index 46130237b..cb9664530 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -2,11 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 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 - -GOPATH := $(shell go env GOPATH) - all: generate license fix vet fmt test lint tidy fix: @@ -46,16 +45,23 @@ openapi: $(GOPATH)/bin/go-bindata --pkg kustomizationapi -o openapi/kustomizationapi/swagger.go openapi/kustomizationapi/swagger.json $(MYGOBIN)/kind: - GO111MODULE=on go get sigs.k8s.io/kind@v0.9.0 + ( \ + 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; \ + ) -kpt: - which $(GOPATH)/bin/kpt || GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt +$(MYGOBIN)/kpt: + ../hack/install_kpt.sh 0.34.0 $(MYGOBIN) API_VERSION="v1.19.1" -schema: $(MYGOBIN)/kind kpt +schema: $(MYGOBIN)/kind $(MYGOBIN)/kpt cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true $(MYGOBIN)/kind create cluster --image kindest/node:$(API_VERSION) --name=getopenapidata - $(GOPATH)/bin/kpt live fetch-k8s-schema --pretty-print > /tmp/new_swagger.json + $(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