@@ -21,6 +21,7 @@ import (
21
21
"os"
22
22
"os/exec"
23
23
"path/filepath"
24
+ "regexp"
24
25
"strings"
25
26
"time"
26
27
@@ -101,23 +102,57 @@ func prependMemcgNotificationFlag(args string) string {
101
102
return "--kubelet-flags=--kernel-memcg-notification=true " + args
102
103
}
103
104
104
- // updateOSSpecificKubeletFlags updates the Kubelet args with OS specific
105
- // settings.
106
- func updateOSSpecificKubeletFlags (args , host , workspace string ) (string , error ) {
107
- output , err := SSH (host , "cat" , "/etc/os-release" )
105
+ // osSpecificActions takes OS specific actions required for the node tests
106
+ func osSpecificActions (args , host , workspace string ) (string , error ) {
107
+ output , err := getOSDistribution (host )
108
108
if err != nil {
109
109
return "" , fmt .Errorf ("issue detecting node's OS via node's /etc/os-release. Err: %v, Output:\n %s" , err , output )
110
110
}
111
111
switch {
112
- case strings .Contains (output , "ID=gci" ), strings .Contains (output , "ID=cos" ):
112
+ case strings .Contains (output , "fedora" ), strings .Contains (output , "rhcos" ),
113
+ strings .Contains (output , "centos" ), strings .Contains (output , "rhel" ):
114
+ return args , setKubeletSELinuxLabels (host , workspace )
115
+ case strings .Contains (output , "gci" ), strings .Contains (output , "cos" ):
113
116
args = prependMemcgNotificationFlag (args )
114
117
return prependCOSMounterFlag (args , host , workspace )
115
- case strings .Contains (output , "ID= ubuntu" ):
118
+ case strings .Contains (output , "ubuntu" ):
116
119
return prependMemcgNotificationFlag (args ), nil
117
120
}
118
121
return args , nil
119
122
}
120
123
124
+ // setKubeletSELinuxLabels set the appropriate SELinux labels for the
125
+ // kubelet on Fedora CoreOS distribution
126
+ func setKubeletSELinuxLabels (host , workspace string ) error {
127
+ cmd := getSSHCommand (" && " ,
128
+ fmt .Sprintf ("/usr/bin/chcon -u system_u -r object_r -t bin_t %s" , filepath .Join (workspace , "kubelet" )),
129
+ fmt .Sprintf ("/usr/bin/chcon -u system_u -r object_r -t bin_t %s" , filepath .Join (workspace , "e2e_node.test" )),
130
+ fmt .Sprintf ("/usr/bin/chcon -u system_u -r object_r -t bin_t %s" , filepath .Join (workspace , "ginkgo" )),
131
+ fmt .Sprintf ("/usr/bin/chcon -u system_u -r object_r -t bin_t %s" , filepath .Join (workspace , "mounter" )),
132
+ fmt .Sprintf ("/usr/bin/chcon -R -u system_u -r object_r -t bin_t %s" , filepath .Join (workspace , "cni" , "bin/" )),
133
+ )
134
+ output , err := SSH (host , "sh" , "-c" , cmd )
135
+ if err != nil {
136
+ return fmt .Errorf ("Unable to apply SELinux labels. Err: %v, Output:\n %s" , err , output )
137
+ }
138
+ return nil
139
+ }
140
+
141
+ func getOSDistribution (host string ) (string , error ) {
142
+ output , err := SSH (host , "cat" , "/etc/os-release" )
143
+ if err != nil {
144
+ return "" , fmt .Errorf ("issue detecting node's OS via node's /etc/os-release. Err: %v, Output:\n %s" , err , output )
145
+ }
146
+
147
+ var re = regexp .MustCompile (`(?m)^ID="?(\w+)"?` )
148
+ subMatch := re .FindStringSubmatch (output )
149
+ if len (subMatch ) > 0 {
150
+ return subMatch [1 ], nil
151
+ }
152
+
153
+ return "" , fmt .Errorf ("Unable to parse os-release for the host, %s" , host )
154
+ }
155
+
121
156
// RunTest runs test on the node.
122
157
func (n * NodeE2ERemote ) RunTest (host , workspace , results , imageDesc , junitFilePrefix , testArgs , ginkgoArgs , systemSpecName , extraEnvs string , timeout time.Duration ) (string , error ) {
123
158
// Install the cni plugins and add a basic CNI configuration.
@@ -134,7 +169,7 @@ func (n *NodeE2ERemote) RunTest(host, workspace, results, imageDesc, junitFilePr
134
169
// Kill any running node processes
135
170
cleanupNodeProcesses (host )
136
171
137
- testArgs , err := updateOSSpecificKubeletFlags (testArgs , host , workspace )
172
+ testArgs , err := osSpecificActions (testArgs , host , workspace )
138
173
if err != nil {
139
174
return "" , err
140
175
}
0 commit comments