mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #130108 from carlory/cleanup-after-81245
remove NodeOSDistroIs from test/e2e/framework/pod
This commit is contained in:
commit
931ad2a9fd
@ -25,6 +25,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/uuid"
|
"k8s.io/apimachinery/pkg/util/uuid"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
admissionapi "k8s.io/pod-security-admission/api"
|
admissionapi "k8s.io/pod-security-admission/api"
|
||||||
)
|
)
|
||||||
@ -176,7 +177,7 @@ func MakeSecPod(podConfig *Config) (*v1.Pod, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
podName := "pod-" + string(uuid.NewUUID())
|
podName := "pod-" + string(uuid.NewUUID())
|
||||||
if podConfig.FsGroup == nil && !NodeOSDistroIs("windows") {
|
if podConfig.FsGroup == nil && !framework.NodeOSDistroIs("windows") {
|
||||||
podConfig.FsGroup = func(i int64) *int64 {
|
podConfig.FsGroup = func(i int64) *int64 {
|
||||||
return &i
|
return &i
|
||||||
}(1000)
|
}(1000)
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package pod
|
package pod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -32,19 +31,6 @@ import (
|
|||||||
"k8s.io/utils/pointer"
|
"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"
|
const InfiniteSleepCommand = "trap exit TERM; while true; do sleep 1; done"
|
||||||
|
|
||||||
// GenerateScriptCmd generates the corresponding command lines to execute a command.
|
// 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
|
// 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.
|
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
|
||||||
func GetTestImage(id imageutils.ImageID) string {
|
func GetTestImage(id imageutils.ImageID) string {
|
||||||
if NodeOSDistroIs("windows") {
|
if framework.NodeOSDistroIs("windows") {
|
||||||
return imageutils.GetE2EImage(imageutils.Agnhost)
|
return imageutils.GetE2EImage(imageutils.Agnhost)
|
||||||
}
|
}
|
||||||
return imageutils.GetE2EImage(id)
|
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
|
// 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.
|
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
|
||||||
func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
|
func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
|
||||||
if NodeOSDistroIs("windows") {
|
if framework.NodeOSDistroIs("windows") {
|
||||||
return imageutils.Agnhost
|
return imageutils.Agnhost
|
||||||
}
|
}
|
||||||
return id
|
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
|
// 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
|
// https://github.com/kubernetes/kubernetes/issues/102849
|
||||||
func GetDefaultNonRootUser() *int64 {
|
func GetDefaultNonRootUser() *int64 {
|
||||||
if NodeOSDistroIs("windows") {
|
if framework.NodeOSDistroIs("windows") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return pointer.Int64(DefaultNonRootUser)
|
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.
|
// 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
|
// TODO: Will modify it after windows has its own security context
|
||||||
func GeneratePodSecurityContext(fsGroup *int64, seLinuxOptions *v1.SELinuxOptions) *v1.PodSecurityContext {
|
func GeneratePodSecurityContext(fsGroup *int64, seLinuxOptions *v1.SELinuxOptions) *v1.PodSecurityContext {
|
||||||
if NodeOSDistroIs("windows") {
|
if framework.NodeOSDistroIs("windows") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &v1.PodSecurityContext{
|
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.
|
// 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
|
// TODO: Will modify it after windows has its own security context
|
||||||
func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
|
func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
|
||||||
if NodeOSDistroIs("windows") {
|
if framework.NodeOSDistroIs("windows") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +125,7 @@ func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
|
|||||||
// GetLinuxLabel returns the default SELinuxLabel based on OS.
|
// GetLinuxLabel returns the default SELinuxLabel based on OS.
|
||||||
// If the node OS is windows, it will return nil
|
// If the node OS is windows, it will return nil
|
||||||
func GetLinuxLabel() *v1.SELinuxOptions {
|
func GetLinuxLabel() *v1.SELinuxOptions {
|
||||||
if NodeOSDistroIs("windows") {
|
if framework.NodeOSDistroIs("windows") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &v1.SELinuxOptions{
|
return &v1.SELinuxOptions{
|
||||||
@ -162,7 +148,7 @@ func GetRestrictedPodSecurityContext() *v1.PodSecurityContext {
|
|||||||
SeccompProfile: &v1.SeccompProfile{Type: v1.SeccompProfileTypeRuntimeDefault},
|
SeccompProfile: &v1.SeccompProfile{Type: v1.SeccompProfileTypeRuntimeDefault},
|
||||||
}
|
}
|
||||||
|
|
||||||
if NodeOSDistroIs("windows") {
|
if framework.NodeOSDistroIs("windows") {
|
||||||
psc.WindowsOptions = &v1.WindowsSecurityContextOptions{}
|
psc.WindowsOptions = &v1.WindowsSecurityContextOptions{}
|
||||||
psc.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
|
psc.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
|
||||||
}
|
}
|
||||||
@ -205,7 +191,7 @@ func MixinRestrictedPodSecurity(pod *v1.Pod) error {
|
|||||||
if pod.Spec.SecurityContext.SeccompProfile == nil {
|
if pod.Spec.SecurityContext.SeccompProfile == nil {
|
||||||
pod.Spec.SecurityContext.SeccompProfile = &v1.SeccompProfile{Type: v1.SeccompProfileTypeRuntimeDefault}
|
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 = &v1.WindowsSecurityContextOptions{}
|
||||||
pod.Spec.SecurityContext.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
|
pod.Spec.SecurityContext.WindowsOptions.RunAsUserName = pointer.String(DefaultNonRootUserName)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user