Skip to content

Commit 2f203e4

Browse files
authored
Merge pull request #480 from munnerz/corev1-protocol-default-value
✨ Set default value for corev1.Protocol type if not already specified
2 parents 4f077b9 + 0c2ff29 commit 2f203e4

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/crd/known_types.go

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

2836
"k8s.io/apimachinery/pkg/apis/meta/v1": func(p *Parser, pkg *loader.Package) {
2937
// ObjectMeta is managed by the Kubernetes API server, so no need to

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,7 @@ spec:
16191619
can be referred to by services.
16201620
type: string
16211621
protocol:
1622+
default: TCP
16221623
description: Protocol for port. Must be
16231624
UDP, TCP, or SCTP. Defaults to "TCP".
16241625
type: string
@@ -2828,6 +2829,7 @@ spec:
28282829
can be referred to by services.
28292830
type: string
28302831
protocol:
2832+
default: TCP
28312833
description: Protocol for port. Must be
28322834
UDP, TCP, or SCTP. Defaults to "TCP".
28332835
type: string

0 commit comments

Comments
 (0)