mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
added support for multiple kubernetes openapi schemas
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
MYGOBIN := $(shell go env GOPATH)/bin
|
MYGOBIN := $(shell go env GOPATH)/bin
|
||||||
|
API_VERSION := "v1.19.1"
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: \
|
all: \
|
||||||
@@ -12,14 +13,13 @@ all: \
|
|||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm kustomizationapi/swagger.go
|
rm kustomizationapi/swagger.go
|
||||||
rm kubernetesapi/swagger.go
|
|
||||||
rm kubernetesapi/openapiinfo.go
|
rm kubernetesapi/openapiinfo.go
|
||||||
|
|
||||||
# To get swagger.json, we need a cluster at the correct version,
|
# This will remove all currently built-in schema,
|
||||||
# so think twice before deleting.
|
# so think twice before deleting.
|
||||||
.PHONY: nuke
|
.PHONY: nuke
|
||||||
nuke: clean
|
nuke: clean
|
||||||
rm kubernetesapi/swagger.json
|
rm -r kubernetesapi/*
|
||||||
|
|
||||||
$(MYGOBIN)/go-bindata:
|
$(MYGOBIN)/go-bindata:
|
||||||
go install github.com/go-bindata/go-bindata/v3/go-bindata
|
go install github.com/go-bindata/go-bindata/v3/go-bindata
|
||||||
@@ -37,26 +37,20 @@ $(MYGOBIN)/kind:
|
|||||||
$(MYGOBIN)/kpt:
|
$(MYGOBIN)/kpt:
|
||||||
../../hack/install_kpt.sh 0.34.0 $(MYGOBIN)
|
../../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
|
kustomizationapi/swagger.go: $(MYGOBIN)/go-bindata kustomizationapi/swagger.json
|
||||||
$(MYGOBIN)/go-bindata \
|
$(MYGOBIN)/go-bindata \
|
||||||
--pkg kustomizationapi \
|
--pkg kustomizationapi \
|
||||||
-o kustomizationapi/swagger.go \
|
-o kustomizationapi/swagger.go \
|
||||||
kustomizationapi/swagger.json
|
kustomizationapi/swagger.json
|
||||||
|
|
||||||
kubernetesapi/openapiinfo.go: kubernetesapi/swagger.json
|
.PHONY: kubernetesapi/openapiinfo.go
|
||||||
./makeOpenApiInfoDotGo.sh kubernetesapi/swagger.json
|
kubernetesapi/openapiinfo.go:
|
||||||
|
./scripts/makeOpenApiInfoDotGo.sh
|
||||||
|
|
||||||
API_VERSION="v1.19.1"
|
.PHONY: kubernetesapi/swagger.json
|
||||||
kubernetesapi/swagger.json: $(MYGOBIN)/kind $(MYGOBIN)/kpt
|
kubernetesapi/swagger.json: $(MYGOBIN)/kind $(MYGOBIN)/kpt
|
||||||
cp $(HOME)/.kube/config /tmp/kubeconfig.txt | true
|
./scripts/fetchSchemaFromCluster.sh $(API_VERSION)
|
||||||
$(MYGOBIN)/kind create cluster --image kindest/node:$(API_VERSION) --name=getopenapidata
|
|
||||||
$(MYGOBIN)/kpt live fetch-k8s-schema --pretty-print > /tmp/new_swagger.json
|
.PHONY: kubernetesapi/swagger.go
|
||||||
$(MYGOBIN)/kind delete cluster --name=getopenapidata
|
kubernetesapi/swagger.go: $(MYGOBIN)/go-bindata kubernetesapi/swagger.json
|
||||||
cp /tmp/kubeconfig.txt $(HOME)/.kube/config | true
|
./scripts/generateSwaggerDotGo.sh $(API_VERSION)
|
||||||
cp /tmp/new_swagger.json kubernetesapi/swagger.json
|
|
||||||
|
|||||||
@@ -1,35 +1,57 @@
|
|||||||
# Sampling New OpenAPI Data
|
# Sampling New OpenAPI Data
|
||||||
|
|
||||||
[OpenAPI schema]: ./kubernetesapi/swagger.json
|
[OpenAPI schema]: ./kubernetesapi/
|
||||||
|
[kind clusters]: https://hub.docker.com/r/kindest/node/tags
|
||||||
|
|
||||||
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. Note that you can
|
||||||
|
only fetch data from versions supported by [kind clusters].
|
||||||
|
|
||||||
### Fetching the Schema
|
### Delete all currently built-in schema
|
||||||
|
```
|
||||||
|
make nuke
|
||||||
|
```
|
||||||
|
|
||||||
In this directory, fetch the openapi schema for the kubernetes api:
|
### Add a new built-in schema
|
||||||
|
|
||||||
|
In this directory, fetch the openapi schema and generate the
|
||||||
|
corresponding swagger.go for the kubernetes api:
|
||||||
|
|
||||||
|
```
|
||||||
|
make kubernetesapi/swagger.go
|
||||||
|
```
|
||||||
|
|
||||||
|
To fetch the schema without generating the swagger.go, you can
|
||||||
|
run:
|
||||||
|
|
||||||
```
|
```
|
||||||
make nuke
|
make nuke
|
||||||
make kubernetesapi/swagger.json
|
make kubernetesapi/swagger.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that generating the swagger.go will re-fetch the schema.
|
||||||
|
|
||||||
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 generating swagger.go for v1.14.1.
|
||||||
|
|
||||||
```
|
```
|
||||||
make kubernetesapi/swagger.json API_VERSION=v1.14.1
|
make kubernetesapi/swagger.go API_VERSION=v1.14.1
|
||||||
```
|
```
|
||||||
|
|
||||||
This will update the [OpenAPI schema].
|
This will update the [OpenAPI schema]. The above command will
|
||||||
|
create a directory kubernetesapi/v1141 and store the resulting
|
||||||
|
swagger.json and swagger.go files there.
|
||||||
|
|
||||||
### Generating Swagger.go
|
### Make the schema available for use
|
||||||
|
|
||||||
In this directory, generate the swagger.go files.
|
While the above commands generate the swagger.go files, they
|
||||||
|
do not make them available for use nor do they update the
|
||||||
|
info field reported by `kustomize openapi info`. To make the
|
||||||
|
newly fetched schema and swagger.go available:
|
||||||
|
|
||||||
```
|
```
|
||||||
make
|
make kubernetesapi/openapiinfo.go
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run all tests
|
### Run all tests
|
||||||
|
|||||||
@@ -1,8 +1,26 @@
|
|||||||
// Copyright 2020 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.
|
// Code generated by ./scripts/makeOpenApiInfoDotGo.sh; DO NOT EDIT.
|
||||||
|
|
||||||
package kubernetesapi
|
package kubernetesapi
|
||||||
|
|
||||||
const Info = "{title:Kubernetes,version:v1.17.0}"
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1184"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1186"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1188"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1190"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1191"
|
||||||
|
)
|
||||||
|
|
||||||
|
const Info = "{title:Kubernetes,version:v1.18.4},{title:Kubernetes,version:v1.18.6},{title:Kubernetes,version:v1.18.8},{title:Kubernetes,version:v1.19.0},{title:Kubernetes,version:v1.19.1}"
|
||||||
|
|
||||||
|
var OpenApiMustAsset = map[string]func(string) []byte{
|
||||||
|
"v1184": v1184.MustAsset,
|
||||||
|
"v1186": v1186.MustAsset,
|
||||||
|
"v1188": v1188.MustAsset,
|
||||||
|
"v1190": v1190.MustAsset,
|
||||||
|
"v1191": v1191.MustAsset,
|
||||||
|
}
|
||||||
|
|
||||||
|
const DefaultOpenApi = "v1191"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
251
kyaml/openapi/kubernetesapi/v1184/swagger.go
Normal file
251
kyaml/openapi/kubernetesapi/v1184/swagger.go
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
251
kyaml/openapi/kubernetesapi/v1186/swagger.go
Normal file
251
kyaml/openapi/kubernetesapi/v1186/swagger.go
Normal file
File diff suppressed because one or more lines are too long
85841
kyaml/openapi/kubernetesapi/v1186/swagger.json
Normal file
85841
kyaml/openapi/kubernetesapi/v1186/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
251
kyaml/openapi/kubernetesapi/v1188/swagger.go
Normal file
251
kyaml/openapi/kubernetesapi/v1188/swagger.go
Normal file
File diff suppressed because one or more lines are too long
85841
kyaml/openapi/kubernetesapi/v1188/swagger.json
Normal file
85841
kyaml/openapi/kubernetesapi/v1188/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
251
kyaml/openapi/kubernetesapi/v1190/swagger.go
Normal file
251
kyaml/openapi/kubernetesapi/v1190/swagger.go
Normal file
File diff suppressed because one or more lines are too long
92486
kyaml/openapi/kubernetesapi/v1190/swagger.json
Normal file
92486
kyaml/openapi/kubernetesapi/v1190/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
251
kyaml/openapi/kubernetesapi/v1191/swagger.go
Normal file
251
kyaml/openapi/kubernetesapi/v1191/swagger.go
Normal file
File diff suppressed because one or more lines are too long
92486
kyaml/openapi/kubernetesapi/v1191/swagger.json
Normal file
92486
kyaml/openapi/kubernetesapi/v1191/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,27 +0,0 @@
|
|||||||
#!/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
|
|
||||||
@@ -395,9 +395,9 @@ func (rs *ResourceSchema) PatchStrategyAndKey() (string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// kubernetesAPIAssetName is the name of the asset containing the statically compiled in
|
// kubernetesAPIDefaultVersion is the latest version number of the statically compiled in
|
||||||
// OpenAPI definitions for Kubernetes built-in types
|
// OpenAPI schema for kubernetes built-in types
|
||||||
kubernetesAPIAssetName = "kubernetesapi/swagger.json"
|
kubernetesAPIDefaultVersion = kubernetesapi.DefaultOpenApi
|
||||||
|
|
||||||
// kustomizationAPIAssetName is the name of the asset containing the statically compiled in
|
// kustomizationAPIAssetName is the name of the asset containing the statically compiled in
|
||||||
// OpenAPI definitions for Kustomization built-in types
|
// OpenAPI definitions for Kustomization built-in types
|
||||||
@@ -436,7 +436,8 @@ func initSchema() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse the swagger, this should never fail
|
// parse the swagger, this should never fail
|
||||||
if err := parse(kubernetesapi.MustAsset(kubernetesAPIAssetName)); err != nil {
|
assetName := "kubernetesapi/" + kubernetesAPIDefaultVersion + "/swagger.json"
|
||||||
|
if err := parse(kubernetesapi.OpenApiMustAsset[kubernetesAPIDefaultVersion](assetName)); err != nil {
|
||||||
// this should never happen
|
// this should never happen
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
14
kyaml/openapi/scripts/fetchSchemaFromCluster.sh
Executable file
14
kyaml/openapi/scripts/fetchSchemaFromCluster.sh
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright 2020 The Kubernetes Authors.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
MYGOBIN=$(go env GOPATH)/bin
|
||||||
|
VERSION=$1
|
||||||
|
|
||||||
|
cp $HOME/.kube/config /tmp/kubeconfig.txt | true
|
||||||
|
$MYGOBIN/kind create cluster --image kindest/node:$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
|
||||||
|
mkdir -p kubernetesapi/"${VERSION//.}"
|
||||||
|
cp /tmp/new_swagger.json kubernetesapi/"${VERSION//.}"/swagger.json
|
||||||
11
kyaml/openapi/scripts/generateSwaggerDotGo.sh
Executable file
11
kyaml/openapi/scripts/generateSwaggerDotGo.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright 2020 The Kubernetes Authors.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
MYGOBIN=$(go env GOPATH)/bin
|
||||||
|
VERSION=$1
|
||||||
|
|
||||||
|
$MYGOBIN/go-bindata \
|
||||||
|
--pkg "${VERSION//.}" \
|
||||||
|
-o kubernetesapi/"${VERSION//.}"/swagger.go \
|
||||||
|
kubernetesapi/"${VERSION//.}"/swagger.json
|
||||||
84
kyaml/openapi/scripts/makeOpenApiInfoDotGo.sh
Executable file
84
kyaml/openapi/scripts/makeOpenApiInfoDotGo.sh
Executable file
@@ -0,0 +1,84 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright 2020 The Kubernetes Authors.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# This will read from the directory kubernetesapi
|
||||||
|
# and use subdirectory names to generate
|
||||||
|
# kubernetesapi/openapiinfo.go
|
||||||
|
#
|
||||||
|
# This script should only be run after the
|
||||||
|
# swagger.json and swagger.go files are generated.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if ! command -v jq &> /dev/null ; then
|
||||||
|
echo Please install jq
|
||||||
|
echo on ubuntu: sudo apt-get install jq
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
info_list=()
|
||||||
|
version_list=()
|
||||||
|
|
||||||
|
V=`ls kubernetesapi | grep v.*`
|
||||||
|
for VERSION in $V
|
||||||
|
do
|
||||||
|
openapiinfo=$(\
|
||||||
|
jq -r '.info' kubernetesapi/$VERSION/swagger.json | \
|
||||||
|
sed 's/[\" *]//g' | \
|
||||||
|
tr -d '\n' )
|
||||||
|
info_list+=( $openapiinfo )
|
||||||
|
version_list+=( ${VERSION} )
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
# add imports to openapiinfo.go
|
||||||
|
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
|
||||||
|
|
||||||
|
import (
|
||||||
|
EOF
|
||||||
|
|
||||||
|
for version in ${version_list[@]}
|
||||||
|
do
|
||||||
|
cat <<EOF >>kubernetesapi/openapiinfo.go
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/$version"
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
|
||||||
|
# add info string for `kustomize openapi info` command
|
||||||
|
OPEN_API_INFO=`echo ${info_list[@]} | tr " " ","`
|
||||||
|
cat <<EOF >>kubernetesapi/openapiinfo.go
|
||||||
|
)
|
||||||
|
|
||||||
|
const Info = "$OPEN_API_INFO"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# add map for `initSchema` in openapi.go to use
|
||||||
|
cat <<EOF >>kubernetesapi/openapiinfo.go
|
||||||
|
|
||||||
|
var OpenApiMustAsset = map[string]func(string)[]byte{
|
||||||
|
EOF
|
||||||
|
|
||||||
|
latest=""
|
||||||
|
for version in ${version_list[@]}
|
||||||
|
do
|
||||||
|
latest=$version
|
||||||
|
cat <<EOF >>kubernetesapi/openapiinfo.go
|
||||||
|
"$version": $version.MustAsset,
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
|
||||||
|
# add latest version to be used as a default
|
||||||
|
cat <<EOF >>kubernetesapi/openapiinfo.go
|
||||||
|
}
|
||||||
|
|
||||||
|
const DefaultOpenApi = "$latest"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user