Skip to content

Commit 25912d0

Browse files
committed
WIP: Roughly how each gate conversion will look
1 parent 9f7fcf6 commit 25912d0

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

pkg/api/pod/util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/kubernetes/pkg/apis/core/helper"
3030
apivalidation "k8s.io/kubernetes/pkg/apis/core/validation"
3131
"k8s.io/kubernetes/pkg/features"
32+
"k8s.io/utils/feature"
3233
)
3334

3435
// ContainerType signifies container type
@@ -685,7 +686,8 @@ func dropDisabledFields(
685686
// For other types of containers, validateContainers will handle them.
686687
}
687688

688-
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) && !rroInUse(oldPodSpec) {
689+
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) &&
690+
!feature.Enabled(features.RecursiveReadOnlyMounts3) && !rroInUse(oldPodSpec) {
689691
for i := range podSpec.Containers {
690692
for j := range podSpec.Containers[i].VolumeMounts {
691693
podSpec.Containers[i].VolumeMounts[j].RecursiveReadOnly = nil
@@ -809,7 +811,8 @@ func dropDisabledPodStatusFields(podStatus, oldPodStatus *api.PodStatus, podSpec
809811
podStatus.HostIPs = nil
810812
}
811813

812-
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) && !rroInUse(oldPodSpec) {
814+
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) &&
815+
!feature.Enabled(features.RecursiveReadOnlyMounts3) && !rroInUse(oldPodSpec) {
813816
for i := range podStatus.ContainerStatuses {
814817
podStatus.ContainerStatuses[i].VolumeMounts = nil
815818
}

pkg/features/kube_features.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,15 @@ var (
993993
clientfeatures.LibFeatureGates(),
994994
//kubeaggregatorfeatures.FeatureGates(),
995995
apiextensionsfeatures.FeatureGates())
996+
997+
// owner: @AkihiroSuda
998+
// kep: https://kep.k8s.io/3857
999+
// alpha: v1.30
1000+
//
1001+
// Allows recursive read-only mounts.
1002+
RecursiveReadOnlyMounts3 = kubeGates.Add(&feature.Gate{
1003+
Name: "RecursiveReadOnlyMounts", Default: false, Release: feature.Alpha,
1004+
})
9961005
)
9971006

9981007
func init() {

pkg/kubelet/kubelet_pods.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import (
6868
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
6969
volumevalidation "k8s.io/kubernetes/pkg/volume/validation"
7070
"k8s.io/kubernetes/third_party/forked/golang/expansion"
71+
"k8s.io/utils/feature"
7172
utilnet "k8s.io/utils/net"
7273
)
7374

@@ -347,7 +348,8 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
347348
if err != nil {
348349
return nil, cleanupAction, fmt.Errorf("failed to resolve recursive read-only mode: %w", err)
349350
}
350-
if rro && !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) {
351+
if rro && !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) &&
352+
!feature.Enabled(features.RecursiveReadOnlyMounts3) {
351353
return nil, cleanupAction, fmt.Errorf("recursive read-only mount needs feature gate %q to be enabled", features.RecursiveReadOnlyMounts)
352354
}
353355

@@ -2135,7 +2137,8 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
21352137
}
21362138
// status.VolumeMounts cannot be propagated from kubecontainer.Status
21372139
// because the CRI API is unaware of the volume names.
2138-
if utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) {
2140+
if utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) ||
2141+
feature.Enabled(features.RecursiveReadOnlyMounts3) {
21392142
for _, vol := range container.VolumeMounts {
21402143
volStatus := v1.VolumeMountStatus{
21412144
Name: vol.Name,
@@ -2147,7 +2150,8 @@ func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecon
21472150
if b, err := resolveRecursiveReadOnly(vol, supportsRRO); err != nil {
21482151
klog.ErrorS(err, "failed to resolve recursive read-only mode", "mode", *vol.RecursiveReadOnly)
21492152
} else if b {
2150-
if utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) {
2153+
if utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) ||
2154+
feature.Enabled(features.RecursiveReadOnlyMounts3) {
21512155
rroMode = v1.RecursiveReadOnlyEnabled
21522156
} else {
21532157
klog.ErrorS(nil, "recursive read-only mount needs feature gate to be enabled",

pkg/kubelet/nodestatus/setters.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
4545
"k8s.io/kubernetes/pkg/kubelet/events"
4646
"k8s.io/kubernetes/pkg/volume"
47+
"k8s.io/utils/feature"
4748
netutils "k8s.io/utils/net"
4849

4950
"k8s.io/klog/v2"
@@ -483,7 +484,8 @@ func GoRuntime() Setter {
483484
// RuntimeHandlers returns a Setter that sets RuntimeHandlers on the node.
484485
func RuntimeHandlers(fn func() []kubecontainer.RuntimeHandler) Setter {
485486
return func(ctx context.Context, node *v1.Node) error {
486-
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) {
487+
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) &&
488+
!feature.Enabled(features.RecursiveReadOnlyMounts3) {
487489
return nil
488490
}
489491
handlers := fn()

pkg/registry/core/node/strategy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"k8s.io/kubernetes/pkg/apis/core/validation"
4141
"k8s.io/kubernetes/pkg/features"
4242
"k8s.io/kubernetes/pkg/kubelet/client"
43+
"k8s.io/utils/feature"
4344
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
4445
)
4546

@@ -103,7 +104,8 @@ func dropDisabledFields(node *api.Node, oldNode *api.Node) {
103104
node.Spec.ConfigSource = nil
104105
}
105106

106-
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) {
107+
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) &&
108+
!feature.Enabled(features.RecursiveReadOnlyMounts3) {
107109
node.Status.RuntimeHandlers = nil
108110
}
109111
}

0 commit comments

Comments
 (0)