Skip to content

Commit da2f36b

Browse files
committed
remove NodeOSDistroIs from test/e2e/framework/pod
1 parent 80bf507 commit da2f36b

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

test/e2e/framework/pod/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/util/uuid"
2727
clientset "k8s.io/client-go/kubernetes"
28+
"k8s.io/kubernetes/test/e2e/framework"
2829
imageutils "k8s.io/kubernetes/test/utils/image"
2930
admissionapi "k8s.io/pod-security-admission/api"
3031
)
@@ -176,7 +177,7 @@ func MakeSecPod(podConfig *Config) (*v1.Pod, error) {
176177
}
177178

178179
podName := "pod-" + string(uuid.NewUUID())
179-
if podConfig.FsGroup == nil && !NodeOSDistroIs("windows") {
180+
if podConfig.FsGroup == nil && !framework.NodeOSDistroIs("windows") {
180181
podConfig.FsGroup = func(i int64) *int64 {
181182
return &i
182183
}(1000)

test/e2e/framework/pod/utils.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package pod
1818

1919
import (
20-
"flag"
2120
"fmt"
2221
"strings"
2322

@@ -32,19 +31,6 @@ import (
3231
"k8s.io/utils/pointer"
3332
)
3433

35-
// NodeOSDistroIs returns true if the distro is the same as `--node-os-distro`
36-
// the package framework/pod can't import the framework package (see #81245)
37-
// we need to check if the --node-os-distro=windows is set and the framework package
38-
// is the one that's parsing the flags, as a workaround this method is looking for the same flag again
39-
// TODO: replace with `framework.NodeOSDistroIs` when #81245 is complete
40-
func NodeOSDistroIs(distro string) bool {
41-
var nodeOsDistro *flag.Flag = flag.Lookup("node-os-distro")
42-
if nodeOsDistro != nil && nodeOsDistro.Value.String() == distro {
43-
return true
44-
}
45-
return false
46-
}
47-
4834
const InfiniteSleepCommand = "trap exit TERM; while true; do sleep 1; done"
4935

5036
// GenerateScriptCmd generates the corresponding command lines to execute a command.
@@ -72,7 +58,7 @@ func GetDefaultTestImageID() imageutils.ImageID {
7258
// If the Node OS is windows, currently we return Agnhost image for Windows node
7359
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
7460
func GetTestImage(id imageutils.ImageID) string {
75-
if NodeOSDistroIs("windows") {
61+
if framework.NodeOSDistroIs("windows") {
7662
return imageutils.GetE2EImage(imageutils.Agnhost)
7763
}
7864
return imageutils.GetE2EImage(id)
@@ -82,7 +68,7 @@ func GetTestImage(id imageutils.ImageID) string {
8268
// If the Node OS is windows, currently we return Agnhost image for Windows node
8369
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
8470
func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
85-
if NodeOSDistroIs("windows") {
71+
if framework.NodeOSDistroIs("windows") {
8672
return imageutils.Agnhost
8773
}
8874
return id
@@ -92,7 +78,7 @@ func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
9278
// If the Node OS is windows, we return nill due to issue with invalid permissions set on projected volumes
9379
// https://github.com/kubernetes/kubernetes/issues/102849
9480
func GetDefaultNonRootUser() *int64 {
95-
if NodeOSDistroIs("windows") {
81+
if framework.NodeOSDistroIs("windows") {
9682
return nil
9783
}
9884
return pointer.Int64(DefaultNonRootUser)
@@ -102,7 +88,7 @@ func GetDefaultNonRootUser() *int64 {
10288
// If the Node OS is windows, currently we will ignore the inputs and return nil.
10389
// TODO: Will modify it after windows has its own security context
10490
func GeneratePodSecurityContext(fsGroup *int64, seLinuxOptions *v1.SELinuxOptions) *v1.PodSecurityContext {
105-
if NodeOSDistroIs("windows") {
91+
if framework.NodeOSDistroIs("windows") {
10692
return nil
10793
}
10894
return &v1.PodSecurityContext{
@@ -115,7 +101,7 @@ func GeneratePodSecurityContext(fsGroup *int64, seLinuxOptions *v1.SELinuxOption
115101
// If the Node OS is windows, currently we will ignore the inputs and return nil.
116102
// TODO: Will modify it after windows has its own security context
117103
func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
118-
if NodeOSDistroIs("windows") {
104+
if framework.NodeOSDistroIs("windows") {
119105
return nil
120106
}
121107

@@ -139,7 +125,7 @@ func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
139125
// GetLinuxLabel returns the default SELinuxLabel based on OS.
140126
// If the node OS is windows, it will return nil
141127
func GetLinuxLabel() *v1.SELinuxOptions {
142-
if NodeOSDistroIs("windows") {
128+
if framework.NodeOSDistroIs("windows") {
143129
return nil
144130
}
145131
return &v1.SELinuxOptions{
@@ -162,7 +148,7 @@ func GetRestrictedPodSecurityContext() *v1.PodSecurityContext {
162148
SeccompProfile: &v1.SeccompProfile{Type: v1.SeccompProfileTypeRuntimeDefault},
163149
}
164150

165-
if NodeOSDistroIs("windows") {
151+
if framework.NodeOSDistroIs("windows") {
166152
psc.WindowsOptions = &v1.WindowsSecurityContextOptions{}
167153
psc.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
168154
}
@@ -205,7 +191,7 @@ func MixinRestrictedPodSecurity(pod *v1.Pod) error {
205191
if pod.Spec.SecurityContext.SeccompProfile == nil {
206192
pod.Spec.SecurityContext.SeccompProfile = &v1.SeccompProfile{Type: v1.SeccompProfileTypeRuntimeDefault}
207193
}
208-
if NodeOSDistroIs("windows") && pod.Spec.SecurityContext.WindowsOptions == nil {
194+
if framework.NodeOSDistroIs("windows") && pod.Spec.SecurityContext.WindowsOptions == nil {
209195
pod.Spec.SecurityContext.WindowsOptions = &v1.WindowsSecurityContextOptions{}
210196
pod.Spec.SecurityContext.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
211197
}

0 commit comments

Comments
 (0)