mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Refactor making of openapi generated files.
This commit is contained in:
@@ -2,10 +2,9 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
MYGOBIN := $(shell go env GOPATH)/bin
|
MYGOBIN := $(shell go env GOPATH)/bin
|
||||||
GOPATH := $(shell go env GOPATH)
|
|
||||||
export PATH := $(MYGOBIN):$(PATH)
|
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
|
all: generate license fix vet fmt test lint tidy
|
||||||
|
|
||||||
fix:
|
fix:
|
||||||
@@ -15,49 +14,22 @@ fmt:
|
|||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
generate:
|
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 ./...
|
go generate ./...
|
||||||
|
|
||||||
license:
|
license:
|
||||||
(which $(GOPATH)/bin/addlicense || go get github.com/google/addlicense)
|
(which $(MYGOBIN)/addlicense || go get github.com/google/addlicense)
|
||||||
$(GOPATH)/bin/addlicense -y 2019 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE .
|
$(MYGOBIN)/addlicense -y 2019 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE .
|
||||||
|
|
||||||
tidy:
|
tidy:
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
(which $(GOPATH)/bin/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1)
|
(which $(MYGOBIN)/golangci-lint || go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1)
|
||||||
$(GOPATH)/bin/golangci-lint run ./...
|
$(MYGOBIN)/golangci-lint run ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -cover ./...
|
go test -cover ./...
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
go 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
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
62
kyaml/openapi/Makefile
Normal file
62
kyaml/openapi/Makefile
Normal 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
|
||||||
@@ -1,35 +1,41 @@
|
|||||||
# Sampling New OpenAPI Data
|
# Sampling New OpenAPI Data
|
||||||
|
|
||||||
[kyaml]: ../
|
|
||||||
[OpenAPI schema]: ./kubernetesapi/swagger.json
|
[OpenAPI schema]: ./kubernetesapi/swagger.json
|
||||||
[home]: ../../
|
|
||||||
|
|
||||||
This document describes how to fetch OpenAPI data from
|
This document describes how to fetch OpenAPI data from
|
||||||
a particular kubernetes version number.
|
a particular kubernetes version number.
|
||||||
|
|
||||||
### Fetching the Schema
|
### Fetching the Schema
|
||||||
In the [kyaml] directory, fetch the schema
|
|
||||||
|
In this directory, fetch the openapi schema for the kubernetes api:
|
||||||
|
|
||||||
```
|
```
|
||||||
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
|
parameter. The default version is v1.19.1. Here is an
|
||||||
example for fetching the data for v1.14.1.
|
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
|
### 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
|
### 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 $?
|
make prow-presubmit-check >& /tmp/k.txt; echo $?
|
||||||
# The exit code should be zero; if not examine /tmp/k.txt
|
# The exit code should be zero; if not examine /tmp/k.txt
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Code generated by ./makeOpenApiInfoDotGo.sh; DO NOT EDIT.
|
||||||
|
|
||||||
package kubernetesapi
|
package kubernetesapi
|
||||||
|
|
||||||
const Info = "{title:Kubernetes,version:v1.17.0}"
|
const Info = "{title:Kubernetes,version:v1.17.0}"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
27
kyaml/openapi/makeOpenApiInfoDotGo.sh
Executable file
27
kyaml/openapi/makeOpenApiInfoDotGo.sh
Executable 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
|
||||||
Reference in New Issue
Block a user