remove NodeOSDistroIs from test/e2e/framework/pod

This commit is contained in:
carlory 2025-02-12 15:33:37 +08:00
parent 80bf507fac
commit da2f36be58
2 changed files with 10 additions and 23 deletions

View File

@ -25,6 +25,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api"
)
@ -176,7 +177,7 @@ func MakeSecPod(podConfig *Config) (*v1.Pod, error) {
}
podName := "pod-" + string(uuid.NewUUID())
if podConfig.FsGroup == nil && !NodeOSDistroIs("windows") {
if podConfig.FsGroup == nil && !framework.NodeOSDistroIs("windows") {
podConfig.FsGroup = func(i int64) *int64 {
return &i
}(1000)

View File

@ -17,7 +17,6 @@ limitations under the License.
package pod
import (
"flag"
"fmt"
"strings"
@ -32,19 +31,6 @@ import (
"k8s.io/utils/pointer"
)
// NodeOSDistroIs returns true if the distro is the same as `--node-os-distro`
// the package framework/pod can't import the framework package (see #81245)
// we need to check if the --node-os-distro=windows is set and the framework package
// is the one that's parsing the flags, as a workaround this method is looking for the same flag again
// TODO: replace with `framework.NodeOSDistroIs` when #81245 is complete
func NodeOSDistroIs(distro string) bool {
var nodeOsDistro *flag.Flag = flag.Lookup("node-os-distro")
if nodeOsDistro != nil && nodeOsDistro.Value.String() == distro {
return true
}
return false
}
const InfiniteSleepCommand = "trap exit TERM; while true; do sleep 1; done"
// GenerateScriptCmd generates the corresponding command lines to execute a command.
@ -72,7 +58,7 @@ func GetDefaultTestImageID() imageutils.ImageID {
// If the Node OS is windows, currently we return Agnhost image for Windows node
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
func GetTestImage(id imageutils.ImageID) string {
if NodeOSDistroIs("windows") {
if framework.NodeOSDistroIs("windows") {
return imageutils.GetE2EImage(imageutils.Agnhost)
}
return imageutils.GetE2EImage(id)
@ -82,7 +68,7 @@ func GetTestImage(id imageutils.ImageID) string {
// If the Node OS is windows, currently we return Agnhost image for Windows node
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
if NodeOSDistroIs("windows") {
if framework.NodeOSDistroIs("windows") {
return imageutils.Agnhost
}
return id
@ -92,7 +78,7 @@ func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
// If the Node OS is windows, we return nill due to issue with invalid permissions set on projected volumes
// https://github.com/kubernetes/kubernetes/issues/102849
func GetDefaultNonRootUser() *int64 {
if NodeOSDistroIs("windows") {
if framework.NodeOSDistroIs("windows") {
return nil
}
return pointer.Int64(DefaultNonRootUser)
@ -102,7 +88,7 @@ func GetDefaultNonRootUser() *int64 {
// If the Node OS is windows, currently we will ignore the inputs and return nil.
// TODO: Will modify it after windows has its own security context
func GeneratePodSecurityContext(fsGroup *int64, seLinuxOptions *v1.SELinuxOptions) *v1.PodSecurityContext {
if NodeOSDistroIs("windows") {
if framework.NodeOSDistroIs("windows") {
return nil
}
return &v1.PodSecurityContext{
@ -115,7 +101,7 @@ func GeneratePodSecurityContext(fsGroup *int64, seLinuxOptions *v1.SELinuxOption
// If the Node OS is windows, currently we will ignore the inputs and return nil.
// TODO: Will modify it after windows has its own security context
func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
if NodeOSDistroIs("windows") {
if framework.NodeOSDistroIs("windows") {
return nil
}
@ -139,7 +125,7 @@ func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
// GetLinuxLabel returns the default SELinuxLabel based on OS.
// If the node OS is windows, it will return nil
func GetLinuxLabel() *v1.SELinuxOptions {
if NodeOSDistroIs("windows") {
if framework.NodeOSDistroIs("windows") {
return nil
}
return &v1.SELinuxOptions{
@ -162,7 +148,7 @@ func GetRestrictedPodSecurityContext() *v1.PodSecurityContext {
SeccompProfile: &v1.SeccompProfile{Type: v1.SeccompProfileTypeRuntimeDefault},
}
if NodeOSDistroIs("windows") {
if framework.NodeOSDistroIs("windows") {
psc.WindowsOptions = &v1.WindowsSecurityContextOptions{}
psc.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
}
@ -205,7 +191,7 @@ func MixinRestrictedPodSecurity(pod *v1.Pod) error {
if pod.Spec.SecurityContext.SeccompProfile == nil {
pod.Spec.SecurityContext.SeccompProfile = &v1.SeccompProfile{Type: v1.SeccompProfileTypeRuntimeDefault}
}
if NodeOSDistroIs("windows") && pod.Spec.SecurityContext.WindowsOptions == nil {
if framework.NodeOSDistroIs("windows") && pod.Spec.SecurityContext.WindowsOptions == nil {
pod.Spec.SecurityContext.WindowsOptions = &v1.WindowsSecurityContextOptions{}
pod.Spec.SecurityContext.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
}