Skip to content

Commit

Permalink
Remove defaults from CRD v1beta1 (#1116)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored May 25, 2020
1 parent 40e6576 commit a93a5b4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ require (
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-aggregator v0.18.3
k8s.io/kubernetes v1.18.3
kmodules.xyz/client-go v0.0.0-20200525020942-1b7acbb9e92a
kmodules.xyz/client-go v0.0.0-20200525112657-3b8ebfcb5e19
kmodules.xyz/constants v0.0.0-20200506032633-a21e58ceec72
kmodules.xyz/custom-resources v0.0.0-20200524222430-4821d8298762
kmodules.xyz/custom-resources v0.0.0-20200525025248-c2afe49bbec6
kmodules.xyz/objectstore-api v0.0.0-20200521103120-92080446e04d
kmodules.xyz/offshoot-api v0.0.0-20200521035628-e135bf07b226
kmodules.xyz/openshift v0.0.0-20200522123204-ce4abf5433c8
kmodules.xyz/prober v0.0.0-20200521101241-adf06150535c
kmodules.xyz/webhook-runtime v0.0.0-20200522123600-ca70a7e28ed0
stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200524212400-c34c2ec151bf
stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200525113026-1a09ffde2a0a
)

replace (
Expand Down
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -952,16 +952,16 @@ k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl
kmodules.xyz/client-go v0.0.0-20200521005126-35ce6bd4ed46/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200521065424-173e32c78a20/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200522120609-c6430d66212f/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200524205059-e986bc44c91b h1:2ylkWuybCgj1FzQ62BdonjACgXQ2jm3FEf0crrnKTns=
kmodules.xyz/client-go v0.0.0-20200524205059-e986bc44c91b/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200525020942-1b7acbb9e92a h1:W3VPIHqDwyLvgaVhpARqXFR+qRUgsxAISXZDYmVFS+Y=
kmodules.xyz/client-go v0.0.0-20200525020942-1b7acbb9e92a/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200525012433-99c6914a1eca/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200525110342-ae5b70d3b49b h1:Fv9E35891GahcrCO09WfCGSJlpaEpfIyxoBHwOINhiQ=
kmodules.xyz/client-go v0.0.0-20200525110342-ae5b70d3b49b/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/client-go v0.0.0-20200525112657-3b8ebfcb5e19 h1:hgFcY57/qeqdxvBGbjaNSlHXIox4XHmTcYGdJqm+BIw=
kmodules.xyz/client-go v0.0.0-20200525112657-3b8ebfcb5e19/go.mod h1:sY/eoe4ktxZEoHpr5NpAQ5s22VSwTE8psJtKVeVgLRY=
kmodules.xyz/constants v0.0.0-20200506032633-a21e58ceec72 h1:0sM6nE7aJon/PSdqZTj0bKJlPyzobXkG0wVYKpjcJJE=
kmodules.xyz/constants v0.0.0-20200506032633-a21e58ceec72/go.mod h1:DbiFk1bJ1KEO94t1SlAn7tzc+Zz95rSXgyUKa2nzPmY=
kmodules.xyz/crd-schema-fuzz v0.0.0-20200521005638-2433a187de95/go.mod h1:jpu8xFsDKd6kAWUAKk8oTu/GQGBWqhrcaDeOJdaCJnk=
kmodules.xyz/custom-resources v0.0.0-20200521070540-2221c4957ef6/go.mod h1:Bxegf34XIvMnFwtWbi/6tcED3IivXDTzK+yYLP0LETo=
kmodules.xyz/custom-resources v0.0.0-20200524222430-4821d8298762 h1:VqMo8mZrsTvY0DuMO5OftxwQ/4KCYs2RpvS7MTfneT0=
kmodules.xyz/custom-resources v0.0.0-20200524222430-4821d8298762/go.mod h1:8PacmvJ1Vq1HoNnbVt0X87j9vQYd+USaQELeQBI5hhk=
kmodules.xyz/custom-resources v0.0.0-20200525025248-c2afe49bbec6 h1:Rl44s9GLXurIdK2JXVdkRnDTPRPFHHd29gisvGkht8k=
kmodules.xyz/custom-resources v0.0.0-20200525025248-c2afe49bbec6/go.mod h1:jOCZrOOLuadTqkTxpg8QdQOzpoM+FIFf/JC2sx814Xc=
kmodules.xyz/objectstore-api v0.0.0-20200521103120-92080446e04d h1:ud3XDScnBdD5q6nLQI/tHLSbuuSwIFaav6IhcQAz2qA=
kmodules.xyz/objectstore-api v0.0.0-20200521103120-92080446e04d/go.mod h1:k6sbzLWYBLRGDNmCj/NwLgj1cniRXCl9ux/P6+7Xd+A=
kmodules.xyz/offshoot-api v0.0.0-20200521035628-e135bf07b226 h1:RZ7H0gl1z/9jLI74YOlGEtNeAknxTEKeAeYH0jakUcM=
Expand Down Expand Up @@ -995,6 +995,6 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200524212400-c34c2ec151bf h1:qxWXC7VsTCs+FB4FSszGisZ8O/4aE68tGbpLqj469pk=
stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200524212400-c34c2ec151bf/go.mod h1:kLqorrag/MYY07FR6ICiCzMnr4CxbPV0uy08PwiRAgM=
stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200525113026-1a09ffde2a0a h1:ydUFsNecfe+fyGL+32md/2L0IpoFLWuIvmKotBqSD0A=
stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200525113026-1a09ffde2a0a/go.mod h1:HHACpj/0CyhIRclo3BRhlai25o+1U/gXquV3xv/7BK0=
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=
52 changes: 52 additions & 0 deletions vendor/kmodules.xyz/client-go/apiextensions/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func RegisterCRDs(client crd_cs.Interface, crds []*CustomResourceDefinition) err
// xref: https://github.com/stashed/stash/issues/1007#issuecomment-570888875
crd.V1beta1.Spec.Validation.OpenAPIV3Schema.Type = ""
}
removeDefaults(crd.V1beta1.Spec.Validation.OpenAPIV3Schema)

_, _, err := v1beta1.CreateOrUpdateCustomResourceDefinition(
context.TODO(),
Expand All @@ -97,6 +98,57 @@ func RegisterCRDs(client crd_cs.Interface, crds []*CustomResourceDefinition) err
return WaitForCRDReady(client.ApiextensionsV1beta1().RESTClient(), crds)
}

func removeDefaults(schema *crdv1beta1.JSONSchemaProps) {
if schema == nil {
return
}

schema.Default = nil

if schema.Items != nil {
removeDefaults(schema.Items.Schema)

for idx := range schema.Items.JSONSchemas {
removeDefaults(&schema.Items.JSONSchemas[idx])
}
}

for idx := range schema.AllOf {
removeDefaults(&schema.AllOf[idx])
}
for idx := range schema.OneOf {
removeDefaults(&schema.OneOf[idx])
}
for idx := range schema.AnyOf {
removeDefaults(&schema.AnyOf[idx])
}
if schema.Not != nil {
removeDefaults(schema.Not)
}
for key, prop := range schema.Properties {
removeDefaults(&prop)
schema.Properties[key] = prop
}
if schema.AdditionalProperties != nil {
removeDefaults(schema.AdditionalProperties.Schema)
}
for key, prop := range schema.PatternProperties {
removeDefaults(&prop)
schema.PatternProperties[key] = prop
}
for key, prop := range schema.Dependencies {
removeDefaults(prop.Schema)
schema.Dependencies[key] = prop
}
if schema.AdditionalItems != nil {
removeDefaults(schema.AdditionalItems.Schema)
}
for key, prop := range schema.Definitions {
removeDefaults(&prop)
schema.Definitions[key] = prop
}
}

func WaitForCRDReady(restClient rest.Interface, crds []*CustomResourceDefinition) error {
err := wait.Poll(3*time.Second, 5*time.Minute, func() (bool, error) {
for _, crd := range crds {
Expand Down
6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ k8s.io/utils/net
k8s.io/utils/path
k8s.io/utils/pointer
k8s.io/utils/trace
# kmodules.xyz/client-go v0.0.0-20200525020942-1b7acbb9e92a
# kmodules.xyz/client-go v0.0.0-20200525112657-3b8ebfcb5e19
kmodules.xyz/client-go
kmodules.xyz/client-go/admissionregistration/v1beta1
kmodules.xyz/client-go/api/v1
Expand Down Expand Up @@ -1068,7 +1068,7 @@ kmodules.xyz/constants/aws
kmodules.xyz/constants/azure
kmodules.xyz/constants/google
kmodules.xyz/constants/openstack
# kmodules.xyz/custom-resources v0.0.0-20200524222430-4821d8298762
# kmodules.xyz/custom-resources v0.0.0-20200525025248-c2afe49bbec6
kmodules.xyz/custom-resources/api/crds
kmodules.xyz/custom-resources/apis/appcatalog
kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1
Expand Down Expand Up @@ -1153,7 +1153,7 @@ sigs.k8s.io/structured-merge-diff/v3/typed
sigs.k8s.io/structured-merge-diff/v3/value
# sigs.k8s.io/yaml v1.2.0
sigs.k8s.io/yaml
# stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200524212400-c34c2ec151bf
# stash.appscode.dev/apimachinery v0.9.0-rc.6.0.20200525113026-1a09ffde2a0a
stash.appscode.dev/apimachinery/api/crds
stash.appscode.dev/apimachinery/apis
stash.appscode.dev/apimachinery/apis/repositories
Expand Down

0 comments on commit a93a5b4

Please sign in to comment.