Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dnsConfig and dnsPolicy in pod spec #12897

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion config/core/configmaps/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
app.kubernetes.io/component: controller
app.kubernetes.io/version: devel
annotations:
knative.dev/example-checksum: "e1c6e542"
knative.dev/example-checksum: "433d7e74"
data:
_example: |-
################################
Expand Down Expand Up @@ -88,6 +88,18 @@ data:
# See: https://knative.dev/docs/serving/feature-flags/#kubernetes-runtime-class
kubernetes.podspec-runtimeclassname: "disabled"

# Indicates whether Kubernetes DNSPolicy support is enabled
#
# WARNING: Cannot safely be disabled once enabled.
# See: https://knative.dev/docs/serving/feature-flags/#kubernetes-dnspolicy
kubernetes.podspec-dnspolicy: "disabled"

# Indicates whether Kubernetes DNSConfig support is enabled
#
# WARNING: Cannot safely be disabled once enabled.
# See: https://knative.dev/docs/serving/feature-flags/#kubernetes-dnsconfig
kubernetes.podspec-dnsconfig: "disabled"

# This feature allows end-users to set a subset of fields on the Pod's SecurityContext
#
# When set to "enabled" or "allowed" it allows the following
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/config/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func defaultFeaturesConfig() *Features {
PodSpecPersistentVolumeClaim: Disabled,
PodSpecPersistentVolumeWrite: Disabled,
PodSpecInitContainers: Disabled,
PodSpecDNSPolicy: Disabled,
PodSpecDNSConfig: Disabled,
TagHeaderBasedRouting: Disabled,
AutoDetectHTTP2: Disabled,
}
Expand Down Expand Up @@ -85,6 +87,8 @@ func NewFeaturesConfigFromMap(data map[string]string) (*Features, error) {
asFlag("kubernetes.podspec-init-containers", &nc.PodSpecInitContainers),
asFlag("kubernetes.podspec-persistent-volume-claim", &nc.PodSpecPersistentVolumeClaim),
asFlag("kubernetes.podspec-persistent-volume-write", &nc.PodSpecPersistentVolumeWrite),
asFlag("kubernetes.podspec-dnspolicy", &nc.PodSpecDNSPolicy),
asFlag("kubernetes.podspec-dnsconfig", &nc.PodSpecDNSConfig),
asFlag("tag-header-based-routing", &nc.TagHeaderBasedRouting),
asFlag("autodetect-http2", &nc.AutoDetectHTTP2)); err != nil {
return nil, err
Expand Down Expand Up @@ -116,6 +120,8 @@ type Features struct {
PodSpecInitContainers Flag
PodSpecPersistentVolumeClaim Flag
PodSpecPersistentVolumeWrite Flag
PodSpecDNSPolicy Flag
PodSpecDNSConfig Flag
TagHeaderBasedRouting Flag
AutoDetectHTTP2 Flag
}
Expand Down
58 changes: 58 additions & 0 deletions pkg/apis/config/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func TestFeaturesConfiguration(t *testing.T) {
PodSpecTolerations: Enabled,
PodSpecPriorityClassName: Enabled,
PodSpecSchedulerName: Enabled,
PodSpecDNSPolicy: Enabled,
PodSpecDNSConfig: Enabled,
TagHeaderBasedRouting: Enabled,
}),
data: map[string]string{
Expand All @@ -84,6 +86,8 @@ func TestFeaturesConfiguration(t *testing.T) {
"kubernetes.podspec-tolerations": "Enabled",
"kubernetes.podspec-priorityclassname": "Enabled",
"kubernetes.podspec-schedulername": "Enabled",
"kubernetes.podspec-dnspolicy": "Enabled",
"kubernetes.podspec-dnsconfig": "Enabled",
"tag-header-based-routing": "Enabled",
},
}, {
Expand Down Expand Up @@ -491,6 +495,60 @@ func TestFeaturesConfiguration(t *testing.T) {
data: map[string]string{
"kubernetes.podspec-schedulername": "Disabled",
},
}, {
name: "kubernetes.podspec-dnspolicy Allowed",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecDNSPolicy: Allowed,
}),
data: map[string]string{
"kubernetes.podspec-dnspolicy": "Allowed",
},
}, {
name: "kubernetes.podspec-dnspolicy Enabled",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecDNSPolicy: Enabled,
}),
data: map[string]string{
"kubernetes.podspec-dnspolicy": "Enabled",
},
}, {
name: "kubernetes.podspec-dnspolicy Disabled",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecDNSPolicy: Disabled,
}),
data: map[string]string{
"kubernetes.podspec-dnspolicy": "Disabled",
},
}, {
name: "kubernetes.podspec-dnsconfig Allowed",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecDNSConfig: Allowed,
}),
data: map[string]string{
"kubernetes.podspec-dnsconfig": "Allowed",
},
}, {
name: "kubernetes.podspec-dnsconfig Enabled",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecDNSConfig: Enabled,
}),
data: map[string]string{
"kubernetes.podspec-dnsconfig": "Enabled",
},
}, {
name: "kubernetes.podspec-dnsconfig Disabled",
wantErr: false,
wantFeatures: defaultWith(&Features{
PodSpecDNSConfig: Disabled,
}),
data: map[string]string{
"kubernetes.podspec-dnsconfig": "Disabled",
},
}}

for _, tt := range configTests {
Expand Down
8 changes: 6 additions & 2 deletions pkg/apis/serving/fieldmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,18 @@ func PodSpecMask(ctx context.Context, in *corev1.PodSpec) *corev1.PodSpec {
if cfg.Features.PodSpecInitContainers != config.Disabled {
out.InitContainers = in.InitContainers
}
if cfg.Features.PodSpecDNSPolicy != config.Disabled {
out.DNSPolicy = in.DNSPolicy
}
if cfg.Features.PodSpecDNSConfig != config.Disabled {
out.DNSConfig = in.DNSConfig
}

// Disallowed fields
// This list is unnecessary, but added here for clarity
out.RestartPolicy = ""
out.TerminationGracePeriodSeconds = nil
out.ActiveDeadlineSeconds = nil
out.DNSPolicy = ""
out.NodeName = ""
out.HostNetwork = false
out.HostPID = false
Expand All @@ -242,7 +247,6 @@ func PodSpecMask(ctx context.Context, in *corev1.PodSpec) *corev1.PodSpec {
out.Hostname = ""
out.Subdomain = ""
out.Priority = nil
out.DNSConfig = nil
out.ReadinessGates = nil

return out
Expand Down
36 changes: 36 additions & 0 deletions pkg/apis/serving/k8s_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ func withPodSpecInitContainersEnabled() configOption {
cfg.Features.PodSpecInitContainers = config.Enabled
return cfg
}

}
func withPodSpecDNSPolicyEnabled() configOption {
return func(cfg *config.Config) *config.Config {
cfg.Features.PodSpecDNSPolicy = config.Enabled
return cfg
}
}

func withPodSpecDNSConfigEnabled() configOption {
return func(cfg *config.Config) *config.Config {
cfg.Features.PodSpecDNSConfig = config.Enabled
return cfg
}
}

func TestPodSpecValidation(t *testing.T) {
Expand Down Expand Up @@ -1062,6 +1076,28 @@ func TestPodSpecFeatureValidation(t *testing.T) {
Paths: []string{"topologySpreadConstraints"},
},
cfgOpts: []configOption{withPodSpecTopologySpreadConstraintsEnabled()},
}, {
name: "DNSPolicy",
featureSpec: corev1.PodSpec{
DNSPolicy: corev1.DNSDefault,
},
err: &apis.FieldError{
Message: "must not set the field(s)",
Paths: []string{"dnsPolicy"},
},
cfgOpts: []configOption{withPodSpecDNSPolicyEnabled()},
}, {
name: "DNSConfig",
featureSpec: corev1.PodSpec{
DNSConfig: &corev1.PodDNSConfig{
Nameservers: []string{"1.2.3.4"},
},
},
err: &apis.FieldError{
Message: "must not set the field(s)",
Paths: []string{"dnsConfig"},
},
cfgOpts: []configOption{withPodSpecDNSConfigEnabled()},
}, {
name: "HostAliases",
featureSpec: corev1.PodSpec{
Expand Down