@@ -31,7 +31,7 @@ import (
31
31
"github.com/golang/protobuf/proto"
32
32
"github.com/golang/protobuf/ptypes/timestamp"
33
33
api "github.com/kubeflow/pipelines/backend/api/v1beta1/go_client"
34
- "github.com/kubeflow/pipelines/backend/src/v2/cacheutils "
34
+ "github.com/kubeflow/pipelines/backend/src/v2/client_manager "
35
35
36
36
"github.com/kubeflow/pipelines/api/v2alpha1/go/pipelinespec"
37
37
"github.com/kubeflow/pipelines/backend/src/v2/metadata"
@@ -41,7 +41,6 @@ import (
41
41
"google.golang.org/protobuf/encoding/protojson"
42
42
"google.golang.org/protobuf/types/known/structpb"
43
43
"k8s.io/client-go/kubernetes"
44
- "k8s.io/client-go/rest"
45
44
)
46
45
47
46
type LauncherV2Options struct {
@@ -63,11 +62,7 @@ type LauncherV2 struct {
63
62
command string
64
63
args []string
65
64
options LauncherV2Options
66
-
67
- // clients
68
- metadataClient metadata.ClientInterface
69
- k8sClient kubernetes.Interface
70
- cacheClient cacheutils.Client
65
+ clientManager client_manager.ClientManagerInterface
71
66
}
72
67
73
68
// Client is the struct to hold the Kubernetes Clientset
@@ -76,7 +71,15 @@ type kubernetesClient struct {
76
71
}
77
72
78
73
// NewLauncherV2 is a factory function that returns an instance of LauncherV2.
79
- func NewLauncherV2 (ctx context.Context , executionID int64 , executorInputJSON , componentSpecJSON string , cmdArgs []string , opts * LauncherV2Options ) (l * LauncherV2 , err error ) {
74
+ func NewLauncherV2 (
75
+ ctx context.Context ,
76
+ executionID int64 ,
77
+ executorInputJSON ,
78
+ componentSpecJSON string ,
79
+ cmdArgs []string ,
80
+ opts * LauncherV2Options ,
81
+ clientManager client_manager.ClientManagerInterface ,
82
+ ) (l * LauncherV2 , err error ) {
80
83
defer func () {
81
84
if err != nil {
82
85
err = fmt .Errorf ("failed to create component launcher v2: %w" , err )
@@ -102,32 +105,14 @@ func NewLauncherV2(ctx context.Context, executionID int64, executorInputJSON, co
102
105
if err != nil {
103
106
return nil , err
104
107
}
105
- restConfig , err := rest .InClusterConfig ()
106
- if err != nil {
107
- return nil , fmt .Errorf ("failed to initialize kubernetes client: %w" , err )
108
- }
109
- k8sClient , err := kubernetes .NewForConfig (restConfig )
110
- if err != nil {
111
- return nil , fmt .Errorf ("failed to initialize kubernetes client set: %w" , err )
112
- }
113
- metadataClient , err := metadata .NewClient (opts .MLMDServerAddress , opts .MLMDServerPort )
114
- if err != nil {
115
- return nil , err
116
- }
117
- cacheClient , err := cacheutils .NewClient (opts .CacheDisabled )
118
- if err != nil {
119
- return nil , err
120
- }
121
108
return & LauncherV2 {
122
- executionID : executionID ,
123
- executorInput : executorInput ,
124
- component : component ,
125
- command : cmdArgs [0 ],
126
- args : cmdArgs [1 :],
127
- options : * opts ,
128
- metadataClient : metadataClient ,
129
- k8sClient : k8sClient ,
130
- cacheClient : cacheClient ,
109
+ executionID : executionID ,
110
+ executorInput : executorInput ,
111
+ component : component ,
112
+ command : cmdArgs [0 ],
113
+ args : cmdArgs [1 :],
114
+ options : * opts ,
115
+ clientManager : clientManager ,
131
116
}, nil
132
117
}
133
118
@@ -195,12 +180,12 @@ func (l *LauncherV2) Execute(ctx context.Context) (err error) {
195
180
glog .Infof ("publish success." )
196
181
// At the end of the current task, we check the statuses of all tasks in
197
182
// the current DAG and update the DAG's status accordingly.
198
- dag , err := l .metadataClient .GetDAG (ctx , execution .GetExecution ().CustomProperties ["parent_dag_id" ].GetIntValue ())
183
+ dag , err := l .clientManager . MetadataClient () .GetDAG (ctx , execution .GetExecution ().CustomProperties ["parent_dag_id" ].GetIntValue ())
199
184
if err != nil {
200
185
glog .Errorf ("DAG Status Update: failed to get DAG: %s" , err .Error ())
201
186
}
202
- pipeline , _ := l .metadataClient .GetPipelineFromExecution (ctx , execution .GetID ())
203
- err = l .metadataClient .UpdateDAGExecutionsState (ctx , dag , pipeline )
187
+ pipeline , _ := l .clientManager . MetadataClient () .GetPipelineFromExecution (ctx , execution .GetID ())
188
+ err = l .clientManager . MetadataClient () .UpdateDAGExecutionsState (ctx , dag , pipeline )
204
189
if err != nil {
205
190
glog .Errorf ("failed to update DAG state: %s" , err .Error ())
206
191
}
@@ -220,7 +205,7 @@ func (l *LauncherV2) Execute(ctx context.Context) (err error) {
220
205
if err != nil {
221
206
return err
222
207
}
223
- bucket , err := objectstore .OpenBucket (ctx , l .k8sClient , l .options .Namespace , bucketConfig )
208
+ bucket , err := objectstore .OpenBucket (ctx , l .clientManager . K8sClient () , l .options .Namespace , bucketConfig )
224
209
if err != nil {
225
210
return err
226
211
}
@@ -235,9 +220,9 @@ func (l *LauncherV2) Execute(ctx context.Context) (err error) {
235
220
l .args ,
236
221
bucket ,
237
222
bucketConfig ,
238
- l .metadataClient ,
223
+ l .clientManager . MetadataClient () ,
239
224
l .options .Namespace ,
240
- l .k8sClient ,
225
+ l .clientManager . K8sClient () ,
241
226
l .options .PublishLogs ,
242
227
)
243
228
if err != nil {
@@ -260,7 +245,7 @@ func (l *LauncherV2) Execute(ctx context.Context) (err error) {
260
245
FinishedAt : & timestamp.Timestamp {Seconds : time .Now ().Unix ()},
261
246
Fingerprint : fingerPrint ,
262
247
}
263
- return l .cacheClient .CreateExecutionCache (ctx , task )
248
+ return l .clientManager . CacheClient () .CreateExecutionCache (ctx , task )
264
249
}
265
250
266
251
return nil
@@ -306,7 +291,7 @@ func (l *LauncherV2) prePublish(ctx context.Context) (execution *metadata.Execut
306
291
err = fmt .Errorf ("failed to pre-publish Pod info to ML Metadata: %w" , err )
307
292
}
308
293
}()
309
- execution , err = l .metadataClient .GetExecution (ctx , l .executionID )
294
+ execution , err = l .clientManager . MetadataClient () .GetExecution (ctx , l .executionID )
310
295
if err != nil {
311
296
return nil , err
312
297
}
@@ -315,7 +300,7 @@ func (l *LauncherV2) prePublish(ctx context.Context) (execution *metadata.Execut
315
300
PodUID : l .options .PodUID ,
316
301
Namespace : l .options .Namespace ,
317
302
}
318
- return l .metadataClient .PrePublishExecution (ctx , execution , ecfg )
303
+ return l .clientManager . MetadataClient () .PrePublishExecution (ctx , execution , ecfg )
319
304
}
320
305
321
306
// TODO(Bobgy): consider passing output artifacts info from executor output.
@@ -336,7 +321,7 @@ func (l *LauncherV2) publish(
336
321
// TODO(Bobgy): when adding artifacts, we will need execution.pipeline to be non-nil, because we need
337
322
// to publish output artifacts to the context too.
338
323
// return l.metadataClient.PublishExecution(ctx, execution, outputParameters, outputArtifacts, pb.Execution_COMPLETE)
339
- return l .metadataClient .PublishExecution (ctx , execution , outputParameters , outputArtifacts , status )
324
+ return l .clientManager . MetadataClient () .PublishExecution (ctx , execution , outputParameters , outputArtifacts , status )
340
325
}
341
326
342
327
// executeV2 handles placeholder substitution for inputs, calls execute to
0 commit comments