@@ -20,9 +20,14 @@ import (
2020 "embed"
2121 "os"
2222 "path/filepath"
23+ "strings"
24+ "time"
2325
2426 "github.com/onsi/gomega"
27+ "github.com/project-codeflare/codeflare-common/support"
28+ corev1 "k8s.io/api/core/v1"
2529 "k8s.io/apimachinery/pkg/api/meta"
30+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2631 "k8s.io/apimachinery/pkg/runtime/schema"
2732 "k8s.io/apimachinery/pkg/runtime/serializer"
2833 "k8s.io/cli-runtime/pkg/genericclioptions"
@@ -33,8 +38,6 @@ import (
3338 "k8s.io/kubectl/pkg/cmd/cp"
3439 "k8s.io/kubectl/pkg/cmd/util"
3540 "k8s.io/kubectl/pkg/scheme"
36-
37- "github.com/project-codeflare/codeflare-common/support"
3841)
3942
4043//go:embed *.py *.txt *.sh
@@ -109,3 +112,46 @@ func (r restClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterfac
109112func (r restClientGetter ) ToRESTMapper () (meta.RESTMapper , error ) {
110113 return nil , nil
111114}
115+
116+ func SetupCodeflareSDKInsidePod (test support.Test , namespace * corev1.Namespace , labelName string ) {
117+
118+ // Get pod name
119+ podName := GetPodName (test , namespace , labelName )
120+
121+ // Get rest config
122+ restConfig , err := GetRestConfig (test )
123+ if err != nil {
124+ test .T ().Errorf ("Error getting rest config: %v" , err )
125+ }
126+
127+ // Copy codeflare-sdk to the pod
128+ srcDir := "../.././"
129+ dstDir := "/codeflare-sdk"
130+ if err := CopyToPod (test , namespace .Name , podName , restConfig , srcDir , dstDir ); err != nil {
131+ test .T ().Errorf ("Error copying codeflare-sdk to pod: %v" , err )
132+ }
133+ }
134+
135+ func GetPodName (test support.Test , namespace * corev1.Namespace , labelName string ) string {
136+ podName := ""
137+ foundPod := false
138+ for ! foundPod {
139+ pods , _ := test .Client ().Core ().CoreV1 ().Pods (namespace .Name ).List (test .Ctx (), metav1.ListOptions {
140+ LabelSelector : "job-name=" + labelName ,
141+ })
142+ for _ , pod := range pods .Items {
143+
144+ if strings .HasPrefix (pod .Name , labelName + "-" ) && pod .Status .Phase == corev1 .PodRunning {
145+ podName = pod .Name
146+ foundPod = true
147+ test .T ().Logf ("Pod is running!" )
148+ break
149+ }
150+ }
151+ if ! foundPod {
152+ test .T ().Logf ("Waiting for pod to start..." )
153+ time .Sleep (5 * time .Second )
154+ }
155+ }
156+ return podName
157+ }
0 commit comments