Skip to content

Commit 897f14b

Browse files
authored
Merge pull request #1035 from sbueringer/pr-fix-default-issue
🐛 Fix duplicate default value when generating CRDs with corev1.Protocol
2 parents 5a195b7 + 2f6801d commit 897f14b

File tree

5 files changed

+2848
-740
lines changed

5 files changed

+2848
-740
lines changed

pkg/crd/known_types.go

-9
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ import (
2525
// KnownPackages overrides types in some comment packages that have custom validation
2626
// but don't have validation markers on them (since they're from core Kubernetes).
2727
var KnownPackages = map[string]PackageOverride{
28-
"k8s.io/api/core/v1": func(p *Parser, pkg *loader.Package) {
29-
// Explicit defaulting for the corev1.Protocol type in lieu of https://github.com/kubernetes/enhancements/pull/1928
30-
p.Schemata[TypeIdent{Name: "Protocol", Package: pkg}] = apiext.JSONSchemaProps{
31-
Type: "string",
32-
Default: &apiext.JSON{Raw: []byte(`"TCP"`)},
33-
}
34-
p.AddPackage(pkg)
35-
},
36-
3728
"k8s.io/apimachinery/pkg/apis/meta/v1": func(p *Parser, pkg *loader.Package) {
3829
p.Schemata[TypeIdent{Name: "ObjectMeta", Package: pkg}] = apiext.JSONSchemaProps{
3930
Type: "object",

pkg/crd/testdata/cronjob_types.go

+7
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,13 @@ type CronJobSpec struct {
342342
// +kubebuilder:validation:items:XIntOrString
343343
// +kubebuilder:validation:items:Pattern="^((100|[0-9]{1,2})%|[0-9]+)$"
344344
IntOrStringArrayWithAPattern []*intstr.IntOrString `json:"intOrStringArrayWithAPattern,omitempty"`
345+
346+
// This tests that we can embed protocol correctly (without ending up with allOf).
347+
// Context: https://github.com/kubernetes-sigs/controller-tools/issues/1027
348+
// Defaults to "TCP".
349+
// +optional
350+
// +default="TCP"
351+
Protocol corev1.Protocol `json:"protocol,omitempty" protobuf:"bytes,4,opt,name=protocol,casttype=Protocol"`
345352
}
346353

347354
type ContainsNestedMap struct {

pkg/crd/testdata/go.mod

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
module testdata.kubebuilder.io/cronjob
22

3-
go 1.15
3+
go 1.22.0
4+
5+
toolchain go1.22.1
6+
7+
require (
8+
k8s.io/api v0.31.0
9+
k8s.io/apimachinery v0.31.0
10+
)
411

512
require (
6-
k8s.io/api v0.19.2
7-
k8s.io/apimachinery v0.19.2
13+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
14+
github.com/go-logr/logr v1.4.2 // indirect
15+
github.com/gogo/protobuf v1.3.2 // indirect
16+
github.com/google/gofuzz v1.2.0 // indirect
17+
github.com/json-iterator/go v1.1.12 // indirect
18+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
19+
github.com/modern-go/reflect2 v1.0.2 // indirect
20+
github.com/x448/float16 v0.8.4 // indirect
21+
golang.org/x/net v0.26.0 // indirect
22+
golang.org/x/text v0.16.0 // indirect
23+
gopkg.in/inf.v0 v0.9.1 // indirect
24+
gopkg.in/yaml.v2 v2.4.0 // indirect
25+
k8s.io/klog/v2 v2.130.1 // indirect
26+
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
27+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
28+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
829
)

0 commit comments

Comments
 (0)