@@ -20,9 +20,14 @@ import (
20
20
"embed"
21
21
"os"
22
22
"path/filepath"
23
+ "strings"
24
+ "time"
23
25
24
26
"github.com/onsi/gomega"
27
+ "github.com/project-codeflare/codeflare-common/support"
28
+ corev1 "k8s.io/api/core/v1"
25
29
"k8s.io/apimachinery/pkg/api/meta"
30
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
31
"k8s.io/apimachinery/pkg/runtime/schema"
27
32
"k8s.io/apimachinery/pkg/runtime/serializer"
28
33
"k8s.io/cli-runtime/pkg/genericclioptions"
@@ -33,8 +38,6 @@ import (
33
38
"k8s.io/kubectl/pkg/cmd/cp"
34
39
"k8s.io/kubectl/pkg/cmd/util"
35
40
"k8s.io/kubectl/pkg/scheme"
36
-
37
- "github.com/project-codeflare/codeflare-common/support"
38
41
)
39
42
40
43
//go:embed *.py *.txt *.sh
@@ -109,3 +112,46 @@ func (r restClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterfac
109
112
func (r restClientGetter ) ToRESTMapper () (meta.RESTMapper , error ) {
110
113
return nil , nil
111
114
}
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