mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-05-28 04:04:39 -04:00
Generate applyconfigurations for kube-aggregator
Signed-off-by: Maciej Szulik <soltysh@gmail.com>
This commit is contained in:
parent
f4eedc41b8
commit
46082bd565
4 changed files with 93 additions and 2 deletions
|
|
@ -30,7 +30,7 @@ import (
|
|||
func main() {
|
||||
err := output()
|
||||
if err != nil {
|
||||
os.Stderr.WriteString(fmt.Sprintf("Failed: %v", err))
|
||||
os.Stderr.WriteString(fmt.Sprintf("Failed: %v", err)) // nolint:errcheck
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -71,6 +71,6 @@ func output() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("error serializing api definitions: %w", err)
|
||||
}
|
||||
os.Stdout.Write(data)
|
||||
os.Stdout.Write(data) // nolint:errcheck
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ kube::codegen::gen_openapi \
|
|||
|
||||
kube::codegen::gen_client \
|
||||
--with-watch \
|
||||
--with-applyconfig \
|
||||
--applyconfig-openapi-schema <(go run k8s.io/kube-aggregator/pkg/generated/openapi/cmd/models-schema) \
|
||||
--output-dir "${SCRIPT_ROOT}/pkg/client" \
|
||||
--output-pkg "${THIS_PKG}/pkg/client" \
|
||||
--clientset-name "clientset_generated" \
|
||||
|
|
|
|||
|
|
@ -29,6 +29,19 @@ trap "cleanup" EXIT SIGINT
|
|||
|
||||
cleanup
|
||||
|
||||
# Ensure model-schema generator matches the version from
|
||||
# k8s.io/kubernetes/pkg/generated/openapi/cmd/models-schema/main.go
|
||||
echo "Ensuring models-schema is up-to-date"
|
||||
K8S_MODELS_SCHEMA="${SCRIPT_ROOT}/../../../../pkg/generated/openapi/cmd/models-schema/main.go"
|
||||
KUBE_AGGREGATOR_MODELS_SCHEMA="${SCRIPT_ROOT}/pkg/generated/openapi/cmd/models-schema/main.go"
|
||||
# these two files will only differ in the imported lines for generated openapi
|
||||
if ! diff -I "k8s.io/kubernetes/pkg/generated/openapi" \
|
||||
-I "k8s.io/kube-aggregator/pkg/generated/openapi" \
|
||||
"${K8S_MODELS_SCHEMA}" "${KUBE_AGGREGATOR_MODELS_SCHEMA}"; then
|
||||
echo "${KUBE_AGGREGATOR_MODELS_SCHEMA} is out of date. Compare changes with ${K8S_MODELS_SCHEMA}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "${TMP_DIFFROOT}"
|
||||
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"k8s.io/kube-aggregator/pkg/generated/openapi"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
"k8s.io/kube-openapi/pkg/validation/spec"
|
||||
)
|
||||
|
||||
// Outputs openAPI schema JSON containing the schema definitions in zz_generated.openapi.go.
|
||||
func main() {
|
||||
err := output()
|
||||
if err != nil {
|
||||
os.Stderr.WriteString(fmt.Sprintf("Failed: %v", err)) // nolint:errcheck
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func output() error {
|
||||
refFunc := func(name string) spec.Ref {
|
||||
return spec.MustCreateRef(fmt.Sprintf("#/definitions/%s", name))
|
||||
}
|
||||
defs := openapi.GetOpenAPIDefinitions(refFunc)
|
||||
schemaDefs := make(map[string]spec.Schema, len(defs))
|
||||
for k, v := range defs {
|
||||
// Replace top-level schema with v2 if a v2 schema is embedded
|
||||
// so that the output of this program is always in OpenAPI v2.
|
||||
// This is done by looking up an extension that marks the embedded v2
|
||||
// schema, and, if the v2 schema is found, make it the resulting schema for
|
||||
// the type.
|
||||
if schema, ok := v.Schema.Extensions[common.ExtensionV2Schema]; ok {
|
||||
if v2Schema, isOpenAPISchema := schema.(spec.Schema); isOpenAPISchema {
|
||||
schemaDefs[k] = v2Schema
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
schemaDefs[k] = v.Schema
|
||||
}
|
||||
data, err := json.Marshal(&spec.Swagger{
|
||||
SwaggerProps: spec.SwaggerProps{
|
||||
Definitions: schemaDefs,
|
||||
Info: &spec.Info{
|
||||
InfoProps: spec.InfoProps{
|
||||
Title: "Kubernetes",
|
||||
Version: "unversioned",
|
||||
},
|
||||
},
|
||||
Swagger: "2.0",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error serializing api definitions: %w", err)
|
||||
}
|
||||
os.Stdout.Write(data) // nolint:errcheck
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in a new issue