@@ -17,13 +17,24 @@ package testenv
17
17
import (
18
18
"encoding/json"
19
19
"fmt"
20
+ "os/exec"
21
+ "strings"
20
22
21
23
gomega "github.com/onsi/gomega"
22
24
23
25
enterprisev1 "github.com/splunk/splunk-operator/pkg/apis/enterprise/v1beta1"
24
26
splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
27
+ logf "sigs.k8s.io/controller-runtime/pkg/log"
25
28
)
26
29
30
+ // PodDetailsStruct captures output of kubectl get pods podname -o json
31
+ type PodDetailsStruct struct {
32
+ Spec struct {
33
+ ServiceAccount string `json:"serviceAccount"`
34
+ ServiceAccountName string `json:"serviceAccountName"`
35
+ }
36
+ }
37
+
27
38
// StandaloneReady verify Standlone is in ReadyStatus and does not flip-flop
28
39
func StandaloneReady (deployment * Deployment , deploymentName string , standalone * enterprisev1.Standalone , testenvInstance * TestEnv ) {
29
40
gomega .Eventually (func () splcommon.Phase {
@@ -223,3 +234,23 @@ func VerifyLMConfiguredOnPod(deployment *Deployment, podName string) {
223
234
return lmConfigured
224
235
}, deployment .GetTimeout (), PollInterval ).Should (gomega .Equal (true ))
225
236
}
237
+
238
+ // VerifyServiceAccountConfiguredOnPod check if given service account is configured on given pod
239
+ func VerifyServiceAccountConfiguredOnPod (deployment * Deployment , ns string , podName string , serviceAccount string ) {
240
+ gomega .Eventually (func () bool {
241
+ output , err := exec .Command ("kubectl" , "get" , "pods" , "-n" , ns , podName , "-o" , "json" ).Output ()
242
+ if err != nil {
243
+ cmd := fmt .Sprintf ("kubectl get pods -n %s %s -o json" , ns , podName )
244
+ logf .Log .Error (err , "Failed to execute command" , "command" , cmd )
245
+ return false
246
+ }
247
+ restResponse := PodDetailsStruct {}
248
+ err = json .Unmarshal ([]byte (output ), & restResponse )
249
+ if err != nil {
250
+ logf .Log .Error (err , "Failed to parse cluster searchheads" )
251
+ return false
252
+ }
253
+ logf .Log .Info ("Service Account on Pod" , "FOUND" , restResponse .Spec .ServiceAccount , "EXPECTED" , serviceAccount )
254
+ return strings .Contains (serviceAccount , restResponse .Spec .ServiceAccount )
255
+ }, deployment .GetTimeout (), PollInterval ).Should (gomega .Equal (true ))
256
+ }
0 commit comments