mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-15 12:18:57 +00:00
Merge pull request #3617 from natasha41575/UseCustomOpenApiSchema
add openapi/path field to use custom openapi schema document
This commit is contained in:
@@ -6,6 +6,7 @@ package target
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -377,10 +378,17 @@ func (kt *KustTarget) accumulateDirectory(
|
|||||||
return nil, errors.Wrapf(
|
return nil, errors.Wrapf(
|
||||||
err, "couldn't make target for path '%s'", ldr.Root())
|
err, "couldn't make target for path '%s'", ldr.Root())
|
||||||
}
|
}
|
||||||
err = openapi.SetSchemaVersion(subKt.Kustomization().OpenAPI, false)
|
var bytes []byte
|
||||||
|
path := ldr.Root()
|
||||||
|
if openApiPath, exists := subKt.Kustomization().OpenAPI["path"]; exists {
|
||||||
|
bytes, err = ldr.Load(filepath.Join(path, openApiPath))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = openapi.SetSchema(subKt.Kustomization().OpenAPI, bytes, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(
|
return nil, err
|
||||||
err, "couldn't set openapi version for path '%s'", ldr.Root())
|
|
||||||
}
|
}
|
||||||
if isComponent && subKt.kustomization.Kind != types.ComponentKind {
|
if isComponent && subKt.kustomization.Kind != types.ComponentKind {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func writeK(path string, content string) FileGen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeTestBase(th kusttest_test.Harness) {
|
func writeTestBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/base", `
|
||||||
resources:
|
resources:
|
||||||
- deploy.yaml
|
- deploy.yaml
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
@@ -42,7 +42,7 @@ configMapGenerator:
|
|||||||
- testValue=purple
|
- testValue=purple
|
||||||
- otherValue=green
|
- otherValue=green
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/base/deploy.yaml", `
|
th.WriteF("/base/deploy.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -53,7 +53,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeTestComponent(th kusttest_test.Harness) {
|
func writeTestComponent(th kusttest_test.Harness) {
|
||||||
th.WriteC("/app/comp", `
|
th.WriteC("/comp", `
|
||||||
namePrefix: comp-
|
namePrefix: comp-
|
||||||
replicas:
|
replicas:
|
||||||
- name: storefront
|
- name: storefront
|
||||||
@@ -67,7 +67,7 @@ configMapGenerator:
|
|||||||
- testValue=blue
|
- testValue=blue
|
||||||
- compValue=red
|
- compValue=red
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/comp/stub.yaml", `
|
th.WriteF("/comp/stub.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -78,7 +78,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeOverlayProd(th kusttest_test.Harness) {
|
func writeOverlayProd(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/prod", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
- db
|
- db
|
||||||
@@ -90,7 +90,7 @@ components:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeDB(th kusttest_test.Harness) {
|
func writeDB(th kusttest_test.Harness) {
|
||||||
deployment("db", "/app/prod/db")(th)
|
deployment("db", "/prod/db")(th)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deployment(name string, path string) FileGen {
|
func deployment(name string, path string) FileGen {
|
||||||
@@ -114,7 +114,7 @@ func TestComponent(t *testing.T) {
|
|||||||
// resources that come before it in the resources list of the parent Kustomization.
|
// resources that come before it in the resources list of the parent Kustomization.
|
||||||
"basic-component": {
|
"basic-component": {
|
||||||
input: []FileGen{writeTestBase, writeTestComponent, writeOverlayProd},
|
input: []FileGen{writeTestBase, writeTestComponent, writeOverlayProd},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -149,14 +149,14 @@ spec:
|
|||||||
},
|
},
|
||||||
"multiple-components": {
|
"multiple-components": {
|
||||||
input: []FileGen{writeTestBase, writeTestComponent, writeDB,
|
input: []FileGen{writeTestBase, writeTestComponent, writeDB,
|
||||||
writeC("/app/additionalcomp", `
|
writeC("/additionalcomp", `
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- otherValue=orange
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
writeK("/app/prod", `
|
writeK("/prod", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
- db
|
- db
|
||||||
@@ -166,7 +166,7 @@ components:
|
|||||||
- ../additionalcomp
|
- ../additionalcomp
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -201,7 +201,7 @@ spec:
|
|||||||
},
|
},
|
||||||
"nested-components": {
|
"nested-components": {
|
||||||
input: []FileGen{writeTestBase, writeTestComponent, writeDB,
|
input: []FileGen{writeTestBase, writeTestComponent, writeDB,
|
||||||
writeC("/app/additionalcomp", `
|
writeC("/additionalcomp", `
|
||||||
components:
|
components:
|
||||||
- ../comp
|
- ../comp
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
@@ -210,7 +210,7 @@ configMapGenerator:
|
|||||||
literals:
|
literals:
|
||||||
- otherValue=orange
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
writeK("/app/prod", `
|
writeK("/prod", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
- db
|
- db
|
||||||
@@ -219,7 +219,7 @@ components:
|
|||||||
- ../additionalcomp
|
- ../additionalcomp
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -256,13 +256,13 @@ spec:
|
|||||||
// without being affected by the component in another branch of the resource tree
|
// without being affected by the component in another branch of the resource tree
|
||||||
"basic-component-with-repeated-base": {
|
"basic-component-with-repeated-base": {
|
||||||
input: []FileGen{writeTestBase, writeTestComponent, writeOverlayProd,
|
input: []FileGen{writeTestBase, writeTestComponent, writeOverlayProd,
|
||||||
writeK("/app/repeated", `
|
writeK("/repeated", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
- ../prod
|
- ../prod
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/repeated",
|
runPath: "/repeated",
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -312,7 +312,7 @@ spec:
|
|||||||
},
|
},
|
||||||
"applying-component-directly-should-be-same-as-kustomization": {
|
"applying-component-directly-should-be-same-as-kustomization": {
|
||||||
input: []FileGen{writeTestBase, writeTestComponent,
|
input: []FileGen{writeTestBase, writeTestComponent,
|
||||||
writeC("/app/direct-component", `
|
writeC("/direct-component", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
@@ -323,7 +323,7 @@ configMapGenerator:
|
|||||||
- testValue=blue
|
- testValue=blue
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/direct-component",
|
runPath: "/direct-component",
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -344,7 +344,7 @@ metadata:
|
|||||||
},
|
},
|
||||||
"missing-optional-component-api-version": {
|
"missing-optional-component-api-version": {
|
||||||
input: []FileGen{writeTestBase, writeOverlayProd,
|
input: []FileGen{writeTestBase, writeOverlayProd,
|
||||||
writeF("/app/comp/"+konfig.DefaultKustomizationFileName(), `
|
writeF("/comp/"+konfig.DefaultKustomizationFileName(), `
|
||||||
kind: Component
|
kind: Component
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
@@ -353,7 +353,7 @@ configMapGenerator:
|
|||||||
- otherValue=orange
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -382,25 +382,25 @@ spec:
|
|||||||
// accumulator when "comp-b" is accumulated. In practice we could use simple Kustomizations for this example.
|
// accumulator when "comp-b" is accumulated. In practice we could use simple Kustomizations for this example.
|
||||||
"components-can-add-the-same-base-if-the-first-renames-resources": {
|
"components-can-add-the-same-base-if-the-first-renames-resources": {
|
||||||
input: []FileGen{writeTestBase,
|
input: []FileGen{writeTestBase,
|
||||||
deployment("proxy", "/app/comp-a/proxy.yaml"),
|
deployment("proxy", "/comp-a/proxy.yaml"),
|
||||||
writeC("/app/comp-a", `
|
writeC("/comp-a", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
|
|
||||||
nameSuffix: "-a"
|
nameSuffix: "-a"
|
||||||
`),
|
`),
|
||||||
writeC("/app/comp-b", `
|
writeC("/comp-b", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
|
|
||||||
nameSuffix: "-b"
|
nameSuffix: "-b"
|
||||||
`),
|
`),
|
||||||
writeK("/app/prod", `
|
writeK("/prod", `
|
||||||
components:
|
components:
|
||||||
- ../comp-a
|
- ../comp-a
|
||||||
- ../comp-b`),
|
- ../comp-b`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -436,34 +436,34 @@ metadata:
|
|||||||
|
|
||||||
"multiple-bases-can-add-the-same-component-if-it-doesn-not-define-named-entities": {
|
"multiple-bases-can-add-the-same-component-if-it-doesn-not-define-named-entities": {
|
||||||
input: []FileGen{
|
input: []FileGen{
|
||||||
writeC("/app/comp", `
|
writeC("/comp", `
|
||||||
namespace: prod
|
namespace: prod
|
||||||
`),
|
`),
|
||||||
writeK("/app/base-a", `
|
writeK("/base-a", `
|
||||||
resources:
|
resources:
|
||||||
- proxy.yaml
|
- proxy.yaml
|
||||||
|
|
||||||
components:
|
components:
|
||||||
- ../comp
|
- ../comp
|
||||||
`),
|
`),
|
||||||
deployment("proxy-a", "/app/base-a/proxy.yaml"),
|
deployment("proxy-a", "/base-a/proxy.yaml"),
|
||||||
writeK("/app/base-b", `
|
writeK("/base-b", `
|
||||||
resources:
|
resources:
|
||||||
- proxy.yaml
|
- proxy.yaml
|
||||||
|
|
||||||
components:
|
components:
|
||||||
- ../comp
|
- ../comp
|
||||||
`),
|
`),
|
||||||
deployment("proxy-b", "/app/base-b/proxy.yaml"),
|
deployment("proxy-b", "/base-b/proxy.yaml"),
|
||||||
writeK("/app/prod", `
|
writeK("/prod", `
|
||||||
resources:
|
resources:
|
||||||
- proxy.yaml
|
- proxy.yaml
|
||||||
- ../base-a
|
- ../base-a
|
||||||
- ../base-b
|
- ../base-b
|
||||||
`),
|
`),
|
||||||
deployment("proxy-prod", "/app/prod/proxy.yaml"),
|
deployment("proxy-prod", "/prod/proxy.yaml"),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
// Note that the namepsace has not been applied to proxy-prod because it was not in scope when the
|
// Note that the namepsace has not been applied to proxy-prod because it was not in scope when the
|
||||||
// component was applied
|
// component was applied
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
@@ -513,30 +513,30 @@ func TestComponentErrors(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
"components-cannot-be-added-to-resources": {
|
"components-cannot-be-added-to-resources": {
|
||||||
input: []FileGen{writeTestBase, writeTestComponent,
|
input: []FileGen{writeTestBase, writeTestComponent,
|
||||||
writeK("/app/compinres", `
|
writeK("/compinres", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
- ../comp
|
- ../comp
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "app/compinres",
|
runPath: "compinres",
|
||||||
expectedError: "expected kind != 'Component' for path '/app/comp'",
|
expectedError: "expected kind != 'Component' for path '/comp'",
|
||||||
},
|
},
|
||||||
"kustomizations-cannot-be-added-to-components": {
|
"kustomizations-cannot-be-added-to-components": {
|
||||||
input: []FileGen{writeTestBase, writeTestComponent,
|
input: []FileGen{writeTestBase, writeTestComponent,
|
||||||
writeK("/app/kustincomponents", `
|
writeK("/kustincomponents", `
|
||||||
components:
|
components:
|
||||||
- ../base
|
- ../base
|
||||||
- ../comp
|
- ../comp
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/kustincomponents",
|
runPath: "/kustincomponents",
|
||||||
expectedError: "accumulating components: accumulateDirectory: \"expected kind 'Component' for path " +
|
expectedError: "accumulating components: accumulateDirectory: \"expected kind 'Component' for path " +
|
||||||
"'/app/base' but got 'Kustomization'",
|
"'/base' but got 'Kustomization'",
|
||||||
},
|
},
|
||||||
"files-cannot-be-added-to-components-list": {
|
"files-cannot-be-added-to-components-list": {
|
||||||
input: []FileGen{writeTestBase,
|
input: []FileGen{writeTestBase,
|
||||||
writeF("/app/filesincomponents/stub.yaml", `
|
writeF("/filesincomponents/stub.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -544,18 +544,18 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
`),
|
`),
|
||||||
writeK("/app/filesincomponents", `
|
writeK("/filesincomponents", `
|
||||||
components:
|
components:
|
||||||
- stub.yaml
|
- stub.yaml
|
||||||
- ../comp
|
- ../comp
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/filesincomponents",
|
runPath: "/filesincomponents",
|
||||||
expectedError: "'/app/filesincomponents/stub.yaml' must be a directory to be a root",
|
expectedError: "'/filesincomponents/stub.yaml' must be a directory to be a root",
|
||||||
},
|
},
|
||||||
"invalid-component-api-version": {
|
"invalid-component-api-version": {
|
||||||
input: []FileGen{writeTestBase, writeOverlayProd,
|
input: []FileGen{writeTestBase, writeOverlayProd,
|
||||||
writeF("/app/comp/"+konfig.DefaultKustomizationFileName(), `
|
writeF("/comp/"+konfig.DefaultKustomizationFileName(), `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Component
|
kind: Component
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
@@ -565,22 +565,22 @@ configMapGenerator:
|
|||||||
- otherValue=orange
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedError: "apiVersion for Component should be kustomize.config.k8s.io/v1alpha1",
|
expectedError: "apiVersion for Component should be kustomize.config.k8s.io/v1alpha1",
|
||||||
},
|
},
|
||||||
"components-cannot-add-the-same-resource": {
|
"components-cannot-add-the-same-resource": {
|
||||||
input: []FileGen{writeTestBase,
|
input: []FileGen{writeTestBase,
|
||||||
writeC("/app/comp-a", `
|
writeC("/comp-a", `
|
||||||
resources:
|
resources:
|
||||||
- proxy.yaml
|
- proxy.yaml
|
||||||
`),
|
`),
|
||||||
deployment("proxy", "/app/comp-a/proxy.yaml"),
|
deployment("proxy", "/comp-a/proxy.yaml"),
|
||||||
writeC("/app/comp-b", `
|
writeC("/comp-b", `
|
||||||
resources:
|
resources:
|
||||||
- proxy.yaml
|
- proxy.yaml
|
||||||
`),
|
`),
|
||||||
deployment("proxy", "/app/comp-b/proxy.yaml"),
|
deployment("proxy", "/comp-b/proxy.yaml"),
|
||||||
writeK("/app/prod", `
|
writeK("/prod", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
|
|
||||||
@@ -588,49 +588,49 @@ components:
|
|||||||
- ../comp-a
|
- ../comp-a
|
||||||
- ../comp-b`),
|
- ../comp-b`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy",
|
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy",
|
||||||
},
|
},
|
||||||
"components-cannot-add-the-same-base": {
|
"components-cannot-add-the-same-base": {
|
||||||
input: []FileGen{writeTestBase,
|
input: []FileGen{writeTestBase,
|
||||||
deployment("proxy", "/app/comp-a/proxy.yaml"),
|
deployment("proxy", "/comp-a/proxy.yaml"),
|
||||||
writeC("/app/comp-a", `
|
writeC("/comp-a", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
`),
|
`),
|
||||||
writeC("/app/comp-b", `
|
writeC("/comp-b", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
`),
|
`),
|
||||||
writeK("/app/prod", `
|
writeK("/prod", `
|
||||||
components:
|
components:
|
||||||
- ../comp-a
|
- ../comp-a
|
||||||
- ../comp-b`),
|
- ../comp-b`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|storefront",
|
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|storefront",
|
||||||
},
|
},
|
||||||
"components-cannot-add-bases-containing-the-same-resource": {
|
"components-cannot-add-bases-containing-the-same-resource": {
|
||||||
input: []FileGen{writeTestBase,
|
input: []FileGen{writeTestBase,
|
||||||
writeC("/app/comp-a", `
|
writeC("/comp-a", `
|
||||||
resources:
|
resources:
|
||||||
- ../base-a
|
- ../base-a
|
||||||
`),
|
`),
|
||||||
writeK("/app/base-a", `
|
writeK("/base-a", `
|
||||||
resources:
|
resources:
|
||||||
- proxy.yaml
|
- proxy.yaml
|
||||||
`),
|
`),
|
||||||
deployment("proxy", "/app/base-a/proxy.yaml"),
|
deployment("proxy", "/base-a/proxy.yaml"),
|
||||||
writeC("/app/comp-b", `
|
writeC("/comp-b", `
|
||||||
resources:
|
resources:
|
||||||
- ../base-b
|
- ../base-b
|
||||||
`),
|
`),
|
||||||
writeK("/app/base-b", `
|
writeK("/base-b", `
|
||||||
resources:
|
resources:
|
||||||
- proxy.yaml
|
- proxy.yaml
|
||||||
`),
|
`),
|
||||||
deployment("proxy", "/app/base-b/proxy.yaml"),
|
deployment("proxy", "/base-b/proxy.yaml"),
|
||||||
writeK("/app/prod", `
|
writeK("/prod", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
|
|
||||||
@@ -638,7 +638,7 @@ components:
|
|||||||
- ../comp-a
|
- ../comp-a
|
||||||
- ../comp-b`),
|
- ../comp-b`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/prod",
|
||||||
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy",
|
expectedError: "may not add resource with an already registered id: ~G_v1_Deployment|~X|proxy",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package krusty
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/builtins"
|
"sigs.k8s.io/kustomize/api/builtins"
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
@@ -73,7 +74,14 @@ func (b *Kustomizer) Run(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = openapi.SetSchemaVersion(kt.Kustomization().OpenAPI, true)
|
var bytes []byte
|
||||||
|
if openApiPath, exists := kt.Kustomization().OpenAPI["path"]; exists {
|
||||||
|
bytes, err = ldr.Load(filepath.Join(ldr.Root(), openApiPath))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = openapi.SetSchema(kt.Kustomization().OpenAPI, bytes, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
230
api/krusty/openapicustomschema_test.go
Normal file
230
api/krusty/openapicustomschema_test.go
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
package krusty_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/openapi"
|
||||||
|
)
|
||||||
|
|
||||||
|
func writeTestSchema(th kusttest_test.Harness, filepath string) {
|
||||||
|
bytes, _ := ioutil.ReadFile("testdata/customschema.json")
|
||||||
|
th.WriteF(filepath+"mycrd_schema.json", string(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeCustomResource(th kusttest_test.Harness, filepath string) {
|
||||||
|
th.WriteF(filepath, `
|
||||||
|
apiVersion: example.com/v1alpha1
|
||||||
|
kind: MyCRD
|
||||||
|
metadata:
|
||||||
|
name: service
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: server
|
||||||
|
image: server
|
||||||
|
command: example
|
||||||
|
ports:
|
||||||
|
- name: grpc
|
||||||
|
protocol: TCP
|
||||||
|
containerPort: 8080
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeTestComponentWithCustomSchema(th kusttest_test.Harness) {
|
||||||
|
writeTestSchema(th, "/comp/")
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
th.WriteC("/comp", `
|
||||||
|
openapi:
|
||||||
|
path: mycrd_schema.json
|
||||||
|
`)
|
||||||
|
th.WriteF("/comp/stub.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: stub
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const customSchemaPatch = `
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- |-
|
||||||
|
apiVersion: example.com/v1alpha1
|
||||||
|
kind: MyCRD
|
||||||
|
metadata:
|
||||||
|
name: service
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: server
|
||||||
|
image: nginx
|
||||||
|
`
|
||||||
|
|
||||||
|
const patchedCustomResource = `
|
||||||
|
apiVersion: example.com/v1alpha1
|
||||||
|
kind: MyCRD
|
||||||
|
metadata:
|
||||||
|
name: service
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- command: example
|
||||||
|
image: nginx
|
||||||
|
name: server
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
name: grpc
|
||||||
|
protocol: TCP
|
||||||
|
`
|
||||||
|
|
||||||
|
// Test for issue #2825
|
||||||
|
func TestCustomOpenApiFieldBasicUsage(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- mycrd.yaml
|
||||||
|
openapi:
|
||||||
|
path: mycrd_schema.json
|
||||||
|
`+customSchemaPatch)
|
||||||
|
writeCustomResource(th, "/mycrd.yaml")
|
||||||
|
writeTestSchema(th, "./")
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, patchedCustomResource)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error if user tries to specify both builtin version
|
||||||
|
// and custom schema
|
||||||
|
func TestCustomOpenApiFieldBothPathAndVersion(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- mycrd.yaml
|
||||||
|
openapi:
|
||||||
|
version: v1.18.8
|
||||||
|
path: mycrd_schema.json
|
||||||
|
`+customSchemaPatch)
|
||||||
|
writeCustomResource(th, "/mycrd.yaml")
|
||||||
|
writeTestSchema(th, "./")
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t,
|
||||||
|
"builtin version and custom schema provided, cannot use both",
|
||||||
|
err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test for if the filepath specified is not found
|
||||||
|
func TestCustomOpenApiFieldFileNotFound(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- mycrd.yaml
|
||||||
|
openapi:
|
||||||
|
path: mycrd_schema.json
|
||||||
|
`+customSchemaPatch)
|
||||||
|
writeCustomResource(th, "/mycrd.yaml")
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t,
|
||||||
|
"'/mycrd_schema.json' doesn't exist",
|
||||||
|
err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCustomOpenApiFieldFromBase(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
resources:
|
||||||
|
- mycrd.yaml
|
||||||
|
openapi:
|
||||||
|
path: mycrd_schema.json
|
||||||
|
`)
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
`+customSchemaPatch)
|
||||||
|
writeCustomResource(th, "base/mycrd.yaml")
|
||||||
|
writeTestSchema(th, "/base/")
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, patchedCustomResource)
|
||||||
|
assert.Equal(t, "using custom schema from file provided",
|
||||||
|
openapi.GetSchemaVersion())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCustomOpenApiFieldFromOverlay(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
resources:
|
||||||
|
- mycrd.yaml
|
||||||
|
`)
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
openapi:
|
||||||
|
path: mycrd_schema.json
|
||||||
|
`+customSchemaPatch)
|
||||||
|
writeCustomResource(th, "base/mycrd.yaml")
|
||||||
|
writeTestSchema(th, "/overlay/")
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, patchedCustomResource)
|
||||||
|
assert.Equal(t, "using custom schema from file provided",
|
||||||
|
openapi.GetSchemaVersion())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCustomOpenApiFieldOverlayTakesPrecedence(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
resources:
|
||||||
|
- mycrd.yaml
|
||||||
|
openapi:
|
||||||
|
path: mycrd_schema.json
|
||||||
|
`)
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
openapi:
|
||||||
|
version: v1.19.1
|
||||||
|
`+customSchemaPatch)
|
||||||
|
writeCustomResource(th, "base/mycrd.yaml")
|
||||||
|
writeTestSchema(th, "/base/")
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: example.com/v1alpha1
|
||||||
|
kind: MyCRD
|
||||||
|
metadata:
|
||||||
|
name: service
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx
|
||||||
|
name: server
|
||||||
|
`)
|
||||||
|
assert.Equal(t, "v1191", openapi.GetSchemaVersion())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCustomOpenAPIFieldFromComponent(t *testing.T) {
|
||||||
|
input := []FileGen{
|
||||||
|
writeTestBase,
|
||||||
|
writeTestComponentWithCustomSchema,
|
||||||
|
writeOverlayProd}
|
||||||
|
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
for _, f := range input {
|
||||||
|
f(th)
|
||||||
|
}
|
||||||
|
openapi.ResetOpenAPI()
|
||||||
|
th.Run(runPath, th.MakeDefaultOptions())
|
||||||
|
assert.Equal(t, "using custom schema from file provided", openapi.GetSchemaVersion())
|
||||||
|
}
|
||||||
@@ -11,13 +11,13 @@ import (
|
|||||||
|
|
||||||
func TestOpenApiFieldBasicUsage(t *testing.T) {
|
func TestOpenApiFieldBasicUsage(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK(".", `
|
||||||
openapi:
|
openapi:
|
||||||
version: v1.18.8
|
version: v1.18.8
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/deployment.yaml", `
|
th.WriteF("/deployment.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -29,7 +29,7 @@ spec:
|
|||||||
- image: whatever
|
- image: whatever
|
||||||
`)
|
`)
|
||||||
|
|
||||||
m := th.Run("/app", th.MakeDefaultOptions())
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -46,13 +46,13 @@ spec:
|
|||||||
|
|
||||||
func TestOpenApiFieldNotBuiltin(t *testing.T) {
|
func TestOpenApiFieldNotBuiltin(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK(".", `
|
||||||
openapi:
|
openapi:
|
||||||
version: v1.14.1
|
version: v1.14.1
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/deployment.yaml", `
|
th.WriteF("/deployment.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -64,7 +64,7 @@ spec:
|
|||||||
- image: whatever
|
- image: whatever
|
||||||
`)
|
`)
|
||||||
|
|
||||||
err := th.RunWithErr("/app", th.MakeDefaultOptions())
|
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected an error")
|
t.Fatalf("expected an error")
|
||||||
}
|
}
|
||||||
@@ -72,11 +72,11 @@ spec:
|
|||||||
|
|
||||||
func TestOpenApiFieldDefaultVersion(t *testing.T) {
|
func TestOpenApiFieldDefaultVersion(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK(".", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/deployment.yaml", `
|
th.WriteF("/deployment.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -88,7 +88,7 @@ spec:
|
|||||||
- image: whatever
|
- image: whatever
|
||||||
`)
|
`)
|
||||||
|
|
||||||
m := th.Run("/app", th.MakeDefaultOptions())
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -260,7 +260,7 @@ spec:
|
|||||||
|
|
||||||
func TestOpenAPIFieldFromComponentDefault(t *testing.T) {
|
func TestOpenAPIFieldFromComponentDefault(t *testing.T) {
|
||||||
input := []FileGen{writeTestBase, writeTestComponent, writeOverlayProd}
|
input := []FileGen{writeTestBase, writeTestComponent, writeOverlayProd}
|
||||||
runPath := "/app/prod"
|
runPath := "/prod"
|
||||||
|
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
for _, f := range input {
|
for _, f := range input {
|
||||||
@@ -271,11 +271,11 @@ func TestOpenAPIFieldFromComponentDefault(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeTestComponentWithOlderOpenAPIVersion(th kusttest_test.Harness) {
|
func writeTestComponentWithOlderOpenAPIVersion(th kusttest_test.Harness) {
|
||||||
th.WriteC("/app/comp", `
|
th.WriteC("/comp", `
|
||||||
openapi:
|
openapi:
|
||||||
version: v1.18.8
|
version: v1.18.8
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/comp/stub.yaml", `
|
th.WriteF("/comp/stub.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -285,12 +285,13 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const runPath = "prod"
|
||||||
|
|
||||||
func TestOpenAPIFieldFromComponent(t *testing.T) {
|
func TestOpenAPIFieldFromComponent(t *testing.T) {
|
||||||
input := []FileGen{
|
input := []FileGen{
|
||||||
writeTestBase,
|
writeTestBase,
|
||||||
writeTestComponentWithOlderOpenAPIVersion,
|
writeTestComponentWithOlderOpenAPIVersion,
|
||||||
writeOverlayProd}
|
writeOverlayProd}
|
||||||
runPath := "/app/prod"
|
|
||||||
|
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
for _, f := range input {
|
for _, f := range input {
|
||||||
|
|||||||
92532
api/krusty/testdata/customschema.json
vendored
Normal file
92532
api/krusty/testdata/customschema.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,9 @@ var globalSchema openapiData
|
|||||||
// kubernetesOpenAPIVersion specifies which builtin kubernetes schema to use
|
// kubernetesOpenAPIVersion specifies which builtin kubernetes schema to use
|
||||||
var kubernetesOpenAPIVersion string
|
var kubernetesOpenAPIVersion string
|
||||||
|
|
||||||
|
// customSchemaFile stores the custom OpenApi schema if it is provided
|
||||||
|
var customSchema []byte
|
||||||
|
|
||||||
// openapiData contains the parsed openapi state. this is in a struct rather than
|
// openapiData contains the parsed openapi state. this is in a struct rather than
|
||||||
// a list of vars so that it can be reset from tests.
|
// a list of vars so that it can be reset from tests.
|
||||||
type openapiData struct {
|
type openapiData struct {
|
||||||
@@ -363,25 +366,20 @@ func (rs *ResourceSchema) PatchStrategyAndKeyList() (string, []string) {
|
|||||||
// empty patch strategy
|
// empty patch strategy
|
||||||
return "", []string{}
|
return "", []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
mkList, found := rs.Schema.Extensions[kubernetesMergeKeyMapList]
|
mkList, found := rs.Schema.Extensions[kubernetesMergeKeyMapList]
|
||||||
if found {
|
if found {
|
||||||
// mkList is []interface, convert to []string
|
// mkList is []interface, convert to []string
|
||||||
mkListStr := make([]string, len(mkList.([]interface{})))
|
mkListStr := make([]string, len(mkList.([]interface{})))
|
||||||
|
|
||||||
for i, v := range mkList.([]interface{}) {
|
for i, v := range mkList.([]interface{}) {
|
||||||
mkListStr[i] = v.(string)
|
mkListStr[i] = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps.(string), mkListStr
|
return ps.(string), mkListStr
|
||||||
}
|
}
|
||||||
|
|
||||||
mk, found := rs.Schema.Extensions[kubernetesMergeKeyExtensionKey]
|
mk, found := rs.Schema.Extensions[kubernetesMergeKeyExtensionKey]
|
||||||
if !found {
|
if !found {
|
||||||
// no mergeKey -- may be a primitive associative list (e.g. finalizers)
|
// no mergeKey -- may be a primitive associative list (e.g. finalizers)
|
||||||
return ps.(string), []string{}
|
return ps.(string), []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps.(string), []string{mk.(string)}
|
return ps.(string), []string{mk.(string)}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,45 +432,72 @@ const (
|
|||||||
kindKey = "kind"
|
kindKey = "kind"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetSchemaVersion sets the kubernetes OpenAPI schema version to use
|
// SetSchema sets the kubernetes OpenAPI schema version to use
|
||||||
func SetSchemaVersion(openAPIField map[string]string, reset bool) error {
|
func SetSchema(openAPIField map[string]string, schema []byte, reset bool) error {
|
||||||
// this should only be set once
|
// this should only be set once
|
||||||
if kubernetesOpenAPIVersion != "" && !reset {
|
schemaIsSet := (kubernetesOpenAPIVersion != "") || customSchema != nil
|
||||||
|
if schemaIsSet && !reset {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
kubernetesOpenAPIVersion = strings.ReplaceAll(openAPIField["version"], ".", "")
|
version, exists := openAPIField["version"]
|
||||||
|
if exists && schema != nil {
|
||||||
|
return fmt.Errorf("builtin version and custom schema provided, cannot use both")
|
||||||
|
}
|
||||||
|
|
||||||
|
if schema != nil { // use custom schema
|
||||||
|
customSchema = schema
|
||||||
|
kubernetesOpenAPIVersion = "custom"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// use builtin version
|
||||||
|
kubernetesOpenAPIVersion = strings.ReplaceAll(version, ".", "")
|
||||||
if kubernetesOpenAPIVersion == "" {
|
if kubernetesOpenAPIVersion == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, ok := kubernetesapi.OpenAPIMustAsset[kubernetesOpenAPIVersion]; !ok {
|
if _, ok := kubernetesapi.OpenAPIMustAsset[kubernetesOpenAPIVersion]; !ok {
|
||||||
return fmt.Errorf("the specified OpenAPI version is not built in")
|
return fmt.Errorf("the specified OpenAPI version is not built in")
|
||||||
}
|
}
|
||||||
|
customSchema = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSchemaVersion returns what kubernetes OpenAPI version is being used
|
// GetSchemaVersion returns what kubernetes OpenAPI version is being used
|
||||||
func GetSchemaVersion() string {
|
func GetSchemaVersion() string {
|
||||||
if kubernetesOpenAPIVersion == "" {
|
switch {
|
||||||
|
case kubernetesOpenAPIVersion == "" && customSchema == nil:
|
||||||
return kubernetesOpenAPIDefaultVersion
|
return kubernetesOpenAPIDefaultVersion
|
||||||
|
case customSchema != nil:
|
||||||
|
return "using custom schema from file provided"
|
||||||
|
default:
|
||||||
|
return kubernetesOpenAPIVersion
|
||||||
}
|
}
|
||||||
return kubernetesOpenAPIVersion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// initSchema parses the json schema
|
// initSchema parses the json schema
|
||||||
func initSchema() {
|
func initSchema() {
|
||||||
|
if customSchema != nil {
|
||||||
|
ResetOpenAPI()
|
||||||
|
err := parse(customSchema)
|
||||||
|
if err != nil {
|
||||||
|
panic("invalid schema file")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
currentVersion := kubernetesOpenAPIVersion
|
currentVersion := kubernetesOpenAPIVersion
|
||||||
if currentVersion == "" {
|
if currentVersion == "" {
|
||||||
currentVersion = kubernetesOpenAPIDefaultVersion
|
currentVersion = kubernetesOpenAPIDefaultVersion
|
||||||
}
|
}
|
||||||
if globalSchema.currentOpenAPIVersion != currentVersion {
|
if globalSchema.currentOpenAPIVersion != currentVersion {
|
||||||
parseSchema(currentVersion)
|
parseBuiltinSchema(currentVersion)
|
||||||
}
|
}
|
||||||
globalSchema.currentOpenAPIVersion = currentVersion
|
globalSchema.currentOpenAPIVersion = currentVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseSchema calls parse to parse the json schemas
|
// parseBuiltinSchema calls parse to parse the json schemas
|
||||||
func parseSchema(version string) {
|
func parseBuiltinSchema(version string) {
|
||||||
if globalSchema.noUseBuiltInSchema {
|
if globalSchema.noUseBuiltInSchema {
|
||||||
// don't parse the built in schema
|
// don't parse the built in schema
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user