@@ -17,7 +17,6 @@ limitations under the License.
17
17
package pod
18
18
19
19
import (
20
- "flag"
21
20
"fmt"
22
21
"strings"
23
22
@@ -32,19 +31,6 @@ import (
32
31
"k8s.io/utils/pointer"
33
32
)
34
33
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
-
48
34
const InfiniteSleepCommand = "trap exit TERM; while true; do sleep 1; done"
49
35
50
36
// GenerateScriptCmd generates the corresponding command lines to execute a command.
@@ -72,7 +58,7 @@ func GetDefaultTestImageID() imageutils.ImageID {
72
58
// If the Node OS is windows, currently we return Agnhost image for Windows node
73
59
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
74
60
func GetTestImage (id imageutils.ImageID ) string {
75
- if NodeOSDistroIs ("windows" ) {
61
+ if framework . NodeOSDistroIs ("windows" ) {
76
62
return imageutils .GetE2EImage (imageutils .Agnhost )
77
63
}
78
64
return imageutils .GetE2EImage (id )
@@ -82,7 +68,7 @@ func GetTestImage(id imageutils.ImageID) string {
82
68
// If the Node OS is windows, currently we return Agnhost image for Windows node
83
69
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
84
70
func GetTestImageID (id imageutils.ImageID ) imageutils.ImageID {
85
- if NodeOSDistroIs ("windows" ) {
71
+ if framework . NodeOSDistroIs ("windows" ) {
86
72
return imageutils .Agnhost
87
73
}
88
74
return id
@@ -92,7 +78,7 @@ func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
92
78
// If the Node OS is windows, we return nill due to issue with invalid permissions set on projected volumes
93
79
// https://github.com/kubernetes/kubernetes/issues/102849
94
80
func GetDefaultNonRootUser () * int64 {
95
- if NodeOSDistroIs ("windows" ) {
81
+ if framework . NodeOSDistroIs ("windows" ) {
96
82
return nil
97
83
}
98
84
return pointer .Int64 (DefaultNonRootUser )
@@ -102,7 +88,7 @@ func GetDefaultNonRootUser() *int64 {
102
88
// If the Node OS is windows, currently we will ignore the inputs and return nil.
103
89
// TODO: Will modify it after windows has its own security context
104
90
func GeneratePodSecurityContext (fsGroup * int64 , seLinuxOptions * v1.SELinuxOptions ) * v1.PodSecurityContext {
105
- if NodeOSDistroIs ("windows" ) {
91
+ if framework . NodeOSDistroIs ("windows" ) {
106
92
return nil
107
93
}
108
94
return & v1.PodSecurityContext {
@@ -115,7 +101,7 @@ func GeneratePodSecurityContext(fsGroup *int64, seLinuxOptions *v1.SELinuxOption
115
101
// If the Node OS is windows, currently we will ignore the inputs and return nil.
116
102
// TODO: Will modify it after windows has its own security context
117
103
func GenerateContainerSecurityContext (level psaapi.Level ) * v1.SecurityContext {
118
- if NodeOSDistroIs ("windows" ) {
104
+ if framework . NodeOSDistroIs ("windows" ) {
119
105
return nil
120
106
}
121
107
@@ -139,7 +125,7 @@ func GenerateContainerSecurityContext(level psaapi.Level) *v1.SecurityContext {
139
125
// GetLinuxLabel returns the default SELinuxLabel based on OS.
140
126
// If the node OS is windows, it will return nil
141
127
func GetLinuxLabel () * v1.SELinuxOptions {
142
- if NodeOSDistroIs ("windows" ) {
128
+ if framework . NodeOSDistroIs ("windows" ) {
143
129
return nil
144
130
}
145
131
return & v1.SELinuxOptions {
@@ -162,7 +148,7 @@ func GetRestrictedPodSecurityContext() *v1.PodSecurityContext {
162
148
SeccompProfile : & v1.SeccompProfile {Type : v1 .SeccompProfileTypeRuntimeDefault },
163
149
}
164
150
165
- if NodeOSDistroIs ("windows" ) {
151
+ if framework . NodeOSDistroIs ("windows" ) {
166
152
psc .WindowsOptions = & v1.WindowsSecurityContextOptions {}
167
153
psc .WindowsOptions .RunAsUserName = pointer .String (DefaultNonRootUserName )
168
154
}
@@ -205,7 +191,7 @@ func MixinRestrictedPodSecurity(pod *v1.Pod) error {
205
191
if pod .Spec .SecurityContext .SeccompProfile == nil {
206
192
pod .Spec .SecurityContext .SeccompProfile = & v1.SeccompProfile {Type : v1 .SeccompProfileTypeRuntimeDefault }
207
193
}
208
- if NodeOSDistroIs ("windows" ) && pod .Spec .SecurityContext .WindowsOptions == nil {
194
+ if framework . NodeOSDistroIs ("windows" ) && pod .Spec .SecurityContext .WindowsOptions == nil {
209
195
pod .Spec .SecurityContext .WindowsOptions = & v1.WindowsSecurityContextOptions {}
210
196
pod .Spec .SecurityContext .WindowsOptions .RunAsUserName = pointer .String (DefaultNonRootUserName )
211
197
}
0 commit comments