Merge pull request #3661 from natasha41575/TrimOpenApi

update openapi version to v1.20.4
This commit is contained in:
Kubernetes Prow Robot
2021-03-02 16:39:19 -08:00
committed by GitHub
19 changed files with 4468 additions and 351531 deletions

View File

@@ -108,7 +108,7 @@ func TestCustomOpenApiFieldBothPathAndVersion(t *testing.T) {
resources:
- mycrd.yaml
openapi:
version: v1.18.8
version: v1.20.4
path: mycrd_schema.json
`+customSchemaPatch)
writeCustomResource(th, "mycrd.yaml")
@@ -193,7 +193,7 @@ openapi:
resources:
- ../base
openapi:
version: v1.19.1
version: v1.20.4
`+customSchemaPatch)
writeCustomResource(th, "base/mycrd.yaml")
writeTestSchema(th, "base/")
@@ -211,7 +211,7 @@ spec:
- image: nginx
name: server
`)
assert.Equal(t, "v1191", openapi.GetSchemaVersion())
assert.Equal(t, "v1204", openapi.GetSchemaVersion())
}
func TestCustomOpenAPIFieldFromComponent(t *testing.T) {
@@ -225,6 +225,6 @@ func TestCustomOpenAPIFieldFromComponent(t *testing.T) {
f(th)
}
openapi.ResetOpenAPI()
th.Run(runPath, th.MakeDefaultOptions())
th.Run("prod", th.MakeDefaultOptions())
assert.Equal(t, "using custom schema from file provided", openapi.GetSchemaVersion())
}

View File

@@ -13,7 +13,7 @@ func TestOpenApiFieldBasicUsage(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
openapi:
version: v1.18.8
version: v1.20.4
resources:
- deployment.yaml
`)
@@ -41,7 +41,7 @@ spec:
containers:
- image: whatever
`)
assert.Equal(t, "v1188", openapi.GetSchemaVersion())
assert.Equal(t, "v1204", openapi.GetSchemaVersion())
}
func TestOpenApiFieldNotBuiltin(t *testing.T) {
@@ -102,201 +102,3 @@ spec:
`)
assert.Equal(t, kubernetesapi.DefaultOpenAPI, openapi.GetSchemaVersion())
}
func TestOpenApiFieldFromBase(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
openapi:
version: v1.19.0
namePrefix: a-
resources:
- deployment.yaml
`)
th.WriteF("base/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
spec:
template:
spec:
containers:
- image: whatever
`)
th.WriteK("overlay", `
namePrefix: b-
resources:
- ../base
patchesStrategicMerge:
- depPatch.yaml
`)
th.WriteF("overlay/depPatch.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
spec:
replicas: 999
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: b-a-myDeployment
spec:
replicas: 999
template:
spec:
containers:
- image: whatever
`)
assert.Equal(t, "v1190", openapi.GetSchemaVersion())
}
func TestOpenApiFieldFromOverlay(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
namePrefix: a-
resources:
- deployment.yaml
`)
th.WriteF("base/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
spec:
template:
spec:
containers:
- image: whatever
`)
th.WriteK("overlay", `
openapi:
version: v1.18.8
namePrefix: b-
resources:
- ../base
patchesStrategicMerge:
- depPatch.yaml
`)
th.WriteF("overlay/depPatch.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
spec:
replicas: 999
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: b-a-myDeployment
spec:
replicas: 999
template:
spec:
containers:
- image: whatever
`)
assert.Equal(t, "v1188", openapi.GetSchemaVersion())
}
func TestOpenApiFieldOverlayTakesPrecedence(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
openapi:
version: v1.19.0
namePrefix: a-
resources:
- deployment.yaml
`)
th.WriteF("base/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
spec:
template:
spec:
containers:
- image: whatever
`)
th.WriteK("overlay", `
openapi:
version: v1.18.8
namePrefix: b-
resources:
- ../base
patchesStrategicMerge:
- depPatch.yaml
`)
th.WriteF("overlay/depPatch.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
spec:
replicas: 999
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: b-a-myDeployment
spec:
replicas: 999
template:
spec:
containers:
- image: whatever
`)
assert.Equal(t, "v1188", openapi.GetSchemaVersion())
}
func TestOpenAPIFieldFromComponentDefault(t *testing.T) {
input := []FileGen{writeTestBase, writeTestComponent, writeOverlayProd}
runPath := "prod"
th := kusttest_test.MakeHarness(t)
for _, f := range input {
f(th)
}
th.Run(runPath, th.MakeDefaultOptions())
assert.Equal(t, kubernetesapi.DefaultOpenAPI, openapi.GetSchemaVersion())
}
func writeTestComponentWithOlderOpenAPIVersion(th kusttest_test.Harness) {
th.WriteC("comp", `
openapi:
version: v1.18.8
`)
th.WriteF("comp/stub.yaml", `
apiVersion: v1
kind: Deployment
metadata:
name: stub
spec:
replicas: 1
`)
}
const runPath = "prod"
func TestOpenAPIFieldFromComponent(t *testing.T) {
input := []FileGen{
writeTestBase,
writeTestComponentWithOlderOpenAPIVersion,
writeOverlayProd}
th := kusttest_test.MakeHarness(t)
for _, f := range input {
f(th)
}
th.Run(runPath, th.MakeDefaultOptions())
assert.Equal(t, "v1188", openapi.GetSchemaVersion())
}

View File

@@ -3,6 +3,8 @@
run:
deadline: 5m
skip-dirs:
- yaml/internal/k8sgen/pkg
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
@@ -12,7 +14,7 @@ linters:
- bodyclose
- deadcode
- depguard
- dogsled
# - dogsled # uncomment after upgrading golangci-lint (Issue #3663)
- dupl
- errcheck
- gochecknoinits
@@ -39,7 +41,7 @@ linters:
- unparam
- unused
- varcheck
- whitespace
# - whitespace # uncomment after upgrading golangci-lint (Issue #3663)
linters-settings:

View File

@@ -9,8 +9,10 @@ export PATH := $(MYGOBIN):$(PATH)
$(MYGOBIN)/addlicense:
go get github.com/google/addlicense
# TODO: Issue #3663
# Update this version of golangci-lint
$(MYGOBIN)/golangci-lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.17.0
$(MYGOBIN)/k8scopy:
( cd ../cmd/k8scopy; go install . )
@@ -30,9 +32,9 @@ clean:
lint: $(MYGOBIN)/golangci-lint
$(MYGOBIN)/golangci-lint \
--skip-dirs $(k8sGenDir) \
run ./...
license: $(MYGOBIN)/addlicense
$(MYGOBIN)/addlicense \
-y 2021 \

View File

@@ -21,3 +21,18 @@ require (
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
)
// These can be removed after upgrading golangci-lint (Issue #3663)
replace github.com/go-critic/go-critic v0.0.0-20181204210945-c3db6069acc5 => github.com/go-critic/go-critic v0.0.0-20190422201921-c3db6069acc5
replace github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 => github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6
replace github.com/golangci/go-tools v0.0.0-20180109140146-af6baa5dc196 => github.com/golangci/go-tools v0.0.0-20190318060251-af6baa5dc196
replace github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 => github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98
replace github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 => github.com/golangci/gosec v0.0.0-20190211064107-66fb7fc33547
replace github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 => github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217
replace mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 => mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34

View File

@@ -107,7 +107,6 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -152,7 +151,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View File

@@ -6,21 +6,13 @@
package kubernetesapi
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"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1204"
)
const Info = "{title:Kubernetes,version:v1.18.4}\n{title:Kubernetes,version:v1.18.6}\n{title:Kubernetes,version:v1.18.8}\n{title:Kubernetes,version:v1.19.0}\n{title:Kubernetes,version:v1.19.1}"
const Info = "{title:Kubernetes,version:v1.20.4}"
var OpenAPIMustAsset = map[string]func(string) []byte{
"v1184": v1184.MustAsset,
"v1186": v1186.MustAsset,
"v1188": v1188.MustAsset,
"v1190": v1190.MustAsset,
"v1191": v1191.MustAsset,
"v1204": v1204.MustAsset,
}
const DefaultOpenAPI = "v1191"
const DefaultOpenAPI = "v1204"

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -169,13 +169,13 @@ func (m Merger) SetComments(sources walk.Sources) error {
// avoid panic
return nil
}
if source != nil && source.YNode().FootComment != "" {
if source.YNode().FootComment != "" {
dest.YNode().FootComment = source.YNode().FootComment
}
if source != nil && source.YNode().HeadComment != "" {
if source.YNode().HeadComment != "" {
dest.YNode().HeadComment = source.YNode().HeadComment
}
if source != nil && source.YNode().LineComment != "" {
if source.YNode().LineComment != "" {
dest.YNode().LineComment = source.YNode().LineComment
}
return nil