github.com/kubeshop/testkube@v1.17.23/pkg/tcl/schedulertcl/test_scheduler.go (about) 1 // Copyright 2024 Testkube. 2 // 3 // Licensed as a Testkube Pro file under the Testkube Community 4 // License (the "License"); you may not use this file except in compliance with 5 // the License. You may obtain a copy of the License at 6 // 7 // https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt 8 9 package schedulertcl 10 11 import ( 12 "strings" 13 14 "github.com/kubeshop/testkube/pkg/api/v1/testkube" 15 ) 16 17 // NewExecutionFromExecutionOptions creates new execution from execution options 18 func NewExecutionFromExecutionOptions(request testkube.ExecutionRequest, execution testkube.Execution) testkube.Execution { 19 execution.ExecutionNamespace = request.ExecutionNamespace 20 21 return execution 22 } 23 24 // GetExecuteOptions returns execute options 25 func GetExecuteOptions(sourceRequest *testkube.ExecutionRequest, 26 destinationRequest testkube.ExecutionRequest) testkube.ExecutionRequest { 27 if sourceRequest == nil { 28 return destinationRequest 29 } 30 31 if destinationRequest.ExecutionNamespace == "" && sourceRequest.ExecutionNamespace != "" { 32 destinationRequest.ExecutionNamespace = sourceRequest.ExecutionNamespace 33 } 34 35 if destinationRequest.ExecutionNamespace != "" { 36 destinationRequest.Namespace = destinationRequest.ExecutionNamespace 37 } 38 39 return destinationRequest 40 } 41 42 // HasExecutionNamespace checks whether execution has execution namespace 43 func HasExecutionNamespace(request *testkube.ExecutionRequest) bool { 44 return request.ExecutionNamespace != "" 45 } 46 47 // GetServiceAccountNamesFromConfig returns service account names from config 48 func GetServiceAccountNamesFromConfig(serviceAccountNames map[string]string, config string) map[string]string { 49 if serviceAccountNames == nil { 50 serviceAccountNames = make(map[string]string) 51 } 52 53 items := strings.Split(config, ",") 54 for _, item := range items { 55 elements := strings.Split(item, "=") 56 if len(elements) != 2 { 57 continue 58 } 59 60 serviceAccountNames[elements[0]] = elements[1] 61 } 62 63 return serviceAccountNames 64 }