Skip to content

Commit

Permalink
Merge pull request #1035 from sbueringer/pr-fix-default-issue
Browse files Browse the repository at this point in the history
🐛 Fix duplicate default value when generating CRDs with corev1.Protocol
  • Loading branch information
k8s-ci-robot authored Aug 14, 2024
2 parents 5a195b7 + 2f6801d commit 897f14b
Show file tree
Hide file tree
Showing 5 changed files with 2,848 additions and 740 deletions.
9 changes: 0 additions & 9 deletions pkg/crd/known_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ import (
// KnownPackages overrides types in some comment packages that have custom validation
// but don't have validation markers on them (since they're from core Kubernetes).
var KnownPackages = map[string]PackageOverride{
"k8s.io/api/core/v1": func(p *Parser, pkg *loader.Package) {
// Explicit defaulting for the corev1.Protocol type in lieu of https://github.com/kubernetes/enhancements/pull/1928
p.Schemata[TypeIdent{Name: "Protocol", Package: pkg}] = apiext.JSONSchemaProps{
Type: "string",
Default: &apiext.JSON{Raw: []byte(`"TCP"`)},
}
p.AddPackage(pkg)
},

"k8s.io/apimachinery/pkg/apis/meta/v1": func(p *Parser, pkg *loader.Package) {
p.Schemata[TypeIdent{Name: "ObjectMeta", Package: pkg}] = apiext.JSONSchemaProps{
Type: "object",
Expand Down
7 changes: 7 additions & 0 deletions pkg/crd/testdata/cronjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ type CronJobSpec struct {
// +kubebuilder:validation:items:XIntOrString
// +kubebuilder:validation:items:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$"
IntOrStringArrayWithAPattern []*intstr.IntOrString `json:"intOrStringArrayWithAPattern,omitempty"`

// This tests that we can embed protocol correctly (without ending up with allOf).
// Context: https://github.com/kubernetes-sigs/controller-tools/issues/1027
// Defaults to "TCP".
// +optional
// +default="TCP"
Protocol corev1.Protocol `json:"protocol,omitempty" protobuf:"bytes,4,opt,name=protocol,casttype=Protocol"`
}

type ContainsNestedMap struct {
Expand Down
27 changes: 24 additions & 3 deletions pkg/crd/testdata/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
module testdata.kubebuilder.io/cronjob

go 1.15
go 1.22.0

toolchain go1.22.1

require (
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
)

require (
k8s.io/api v0.19.2
k8s.io/apimachinery v0.19.2
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
Loading

0 comments on commit 897f14b

Please sign in to comment.