diff --git a/kyaml/Makefile b/kyaml/Makefile index bbb7fd563..30733c5b8 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -2,10 +2,9 @@ # 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 +.PHONY: generate license fix vet fmt test lint tidy all: generate license fix vet fmt test lint tidy fix: @@ -15,49 +14,22 @@ fmt: go fmt ./... generate: - (which $(GOPATH)/bin/stringer || go get golang.org/x/tools/cmd/stringer) + (which $(MYGOBIN)/stringer || go get golang.org/x/tools/cmd/stringer) go generate ./... license: - (which $(GOPATH)/bin/addlicense || go get github.com/google/addlicense) - $(GOPATH)/bin/addlicense -y 2019 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . + (which $(MYGOBIN)/addlicense || go get github.com/google/addlicense) + $(MYGOBIN)/addlicense -y 2019 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . tidy: go mod tidy lint: - (which $(GOPATH)/bin/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1) - $(GOPATH)/bin/golangci-lint run ./... + (which $(MYGOBIN)/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1) + $(MYGOBIN)/golangci-lint run ./... test: go test -cover ./... vet: go vet ./... - -openapi: - ./hack/fetchOpenApiData.sh - -$(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 - - diff --git a/kyaml/hack/fetchOpenApiData.sh b/kyaml/hack/fetchOpenApiData.sh deleted file mode 100755 index 0a8e080dc..000000000 --- a/kyaml/hack/fetchOpenApiData.sh +++ /dev/null @@ -1,14 +0,0 @@ -if ! command -v jq &> /dev/null ; then - echo Please install jq - echo on ubuntu: sudo apt-get install jq - exit 1 -fi - -GOPATH=$(go env GOPATH) - -OPENAPIINFO=$(jq -r '.info' openapi/kubernetesapi/swagger.json | sed 's/[\" *]//g' | tr -d '\n') -sed -i "s/Info = \".*\"/Info = \"$OPENAPIINFO\"/g" 'openapi/kubernetesapi/openapiinfo.go' - -(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 diff --git a/kyaml/openapi/Makefile b/kyaml/openapi/Makefile new file mode 100644 index 000000000..99d7bafd9 --- /dev/null +++ b/kyaml/openapi/Makefile @@ -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 diff --git a/kyaml/openapi/README.md b/kyaml/openapi/README.md index 52920d2bf..f1bc7138d 100644 --- a/kyaml/openapi/README.md +++ b/kyaml/openapi/README.md @@ -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 -``` \ No newline at end of file +``` diff --git a/kyaml/openapi/kubernetesapi/openapiinfo.go b/kyaml/openapi/kubernetesapi/openapiinfo.go index 0248f17bb..7f6991019 100644 --- a/kyaml/openapi/kubernetesapi/openapiinfo.go +++ b/kyaml/openapi/kubernetesapi/openapiinfo.go @@ -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}" diff --git a/kyaml/openapi/makeOpenApiInfoDotGo.sh b/kyaml/openapi/makeOpenApiInfoDotGo.sh new file mode 100755 index 000000000..51c5e71fa --- /dev/null +++ b/kyaml/openapi/makeOpenApiInfoDotGo.sh @@ -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 <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