Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 40fef66

Browse files
authored
Add k8s events to task phase updates (#600)
* wip: Add k8s events to task phase updates Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * Refactor clientset, pluginstate Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * Refactor to use batched events Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * go.mod updates Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * Linits Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * Update flyteidl and flyteplugins versions Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * Update to EventReason Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * Comments Signed-off-by: Andrew Dye <andrewwdye@gmail.com> * Readd GroupVersionKind changes Signed-off-by: Andrew Dye <andrewwdye@gmail.com> --------- Signed-off-by: Andrew Dye <andrewwdye@gmail.com>
1 parent 2aca906 commit 40fef66

19 files changed

Lines changed: 603 additions & 229 deletions

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ require (
66
github.com/DiSiqueira/GoTree v1.0.1-0.20180907134536-53a8e837f295
77
github.com/benlaurie/objecthash v0.0.0-20180202135721-d1e3d6079fc1
88
github.com/fatih/color v1.13.0
9-
github.com/flyteorg/flyteidl v1.5.13
10-
github.com/flyteorg/flyteplugins v1.1.30
9+
github.com/flyteorg/flyteidl v1.5.21
10+
github.com/flyteorg/flyteplugins v1.1.31
1111
github.com/flyteorg/flytestdlib v1.0.24
1212
github.com/ghodss/yaml v1.0.0
1313
github.com/go-redis/redis v6.15.7+incompatible

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
242242
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
243243
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
244244
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
245-
github.com/flyteorg/flyteidl v1.5.13 h1:IQ2Cw+u36ew3BPyRDAcHdzc/GyNEOXOxhKy9jbS4hbo=
246-
github.com/flyteorg/flyteidl v1.5.13/go.mod h1:EtE/muM2lHHgBabjYcxqe9TWeJSL0kXwbI0RgVwI4Og=
247-
github.com/flyteorg/flyteplugins v1.1.30 h1:AVqS6Eb9Nr9Z3Mb3CtP04ffAVS9LMx5Q1Z7AyFFk/e0=
248-
github.com/flyteorg/flyteplugins v1.1.30/go.mod h1:FujFQdL/f9r1HvFR81JCiNYusDy9F0lExhyoyMHXXbg=
245+
github.com/flyteorg/flyteidl v1.5.21 h1:zP1byUlNFqstTe7Io1DiiNgNf+mZAVmGZM04oIUA5kU=
246+
github.com/flyteorg/flyteidl v1.5.21/go.mod h1:EtE/muM2lHHgBabjYcxqe9TWeJSL0kXwbI0RgVwI4Og=
247+
github.com/flyteorg/flyteplugins v1.1.31 h1:9LHEWq6I4/hh4BeSk7qKwgeaBSyedD8V5se54v77yYo=
248+
github.com/flyteorg/flyteplugins v1.1.31/go.mod h1:FujFQdL/f9r1HvFR81JCiNYusDy9F0lExhyoyMHXXbg=
249249
github.com/flyteorg/flytestdlib v1.0.24 h1:jDvymcjlsTRCwOtxPapro0WZBe3isTz+T3Tiq+mZUuk=
250250
github.com/flyteorg/flytestdlib v1.0.24/go.mod h1:6nXa5g00qFIsgdvQ7jKQMJmDniqO0hG6Z5X5olfduqQ=
251251
github.com/flyteorg/stow v0.3.7 h1:Cx7j8/Ux6+toD5hp5fy++927V+yAcAttDeQAlUD/864=

pkg/controller/controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func getAdminClient(ctx context.Context) (client service.AdminServiceClient, sig
323323
}
324324

325325
// New returns a new FlyteWorkflow controller
326-
func New(ctx context.Context, cfg *config.Config, kubeclientset kubernetes.Interface, flytepropellerClientset clientset.Interface,
326+
func New(ctx context.Context, cfg *config.Config, kubeClientset kubernetes.Interface, flytepropellerClientset clientset.Interface,
327327
flyteworkflowInformerFactory informers.SharedInformerFactory, informerFactory k8sInformers.SharedInformerFactory,
328328
kubeClient executors.Client, scope promutils.Scope) (*Controller, error) {
329329

@@ -354,13 +354,13 @@ func New(ctx context.Context, cfg *config.Config, kubeclientset kubernetes.Inter
354354
if err != nil {
355355
return nil, errors.Wrapf(err, "Failed to create EventSink [%v], error %v", events.GetConfig(ctx).Type, err)
356356
}
357-
gc, err := NewGarbageCollector(cfg, scope, clock.RealClock{}, kubeclientset.CoreV1().Namespaces(), flytepropellerClientset.FlyteworkflowV1alpha1())
357+
gc, err := NewGarbageCollector(cfg, scope, clock.RealClock{}, kubeClientset.CoreV1().Namespaces(), flytepropellerClientset.FlyteworkflowV1alpha1())
358358
if err != nil {
359359
logger.Errorf(ctx, "failed to initialize GC for workflows")
360360
return nil, errors.Wrapf(err, "failed to initialize WF GC")
361361
}
362362

363-
eventRecorder, err := utils.NewK8sEventRecorder(ctx, kubeclientset, controllerAgentName, cfg.PublishK8sEvents)
363+
eventRecorder, err := utils.NewK8sEventRecorder(ctx, kubeClientset, controllerAgentName, cfg.PublishK8sEvents)
364364
if err != nil {
365365
logger.Errorf(ctx, "failed to event recorder %v", err)
366366
return nil, errors.Wrapf(err, "failed to initialize resource lock.")
@@ -372,7 +372,7 @@ func New(ctx context.Context, cfg *config.Config, kubeclientset kubernetes.Inter
372372
numWorkers: cfg.Workers,
373373
}
374374

375-
lock, err := leader.NewResourceLock(kubeclientset.CoreV1(), kubeclientset.CoordinationV1(), eventRecorder, cfg.LeaderElection)
375+
lock, err := leader.NewResourceLock(kubeClientset.CoreV1(), kubeClientset.CoordinationV1(), eventRecorder, cfg.LeaderElection)
376376
if err != nil {
377377
logger.Errorf(ctx, "failed to initialize resource lock.")
378378
return nil, errors.Wrapf(err, "failed to initialize resource lock.")
@@ -440,7 +440,7 @@ func New(ctx context.Context, cfg *config.Config, kubeclientset kubernetes.Inter
440440

441441
recoveryClient := recovery.NewClient(adminClient)
442442
nodeHandlerFactory, err := factory.NewHandlerFactory(ctx, launchPlanActor, launchPlanActor,
443-
kubeClient, catalogClient, recoveryClient, &cfg.EventConfig, cfg.ClusterID, signalClient, scope)
443+
kubeClient, kubeClientset, catalogClient, recoveryClient, &cfg.EventConfig, cfg.ClusterID, signalClient, scope)
444444
if err != nil {
445445
return nil, errors.Wrapf(err, "failed to create node handler factory")
446446
}

pkg/controller/executors/dag_structure.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/flyteorg/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
77
)
88

9+
//go:generate mockery -name DAGStructure -name DAGStructureWithStartNode -case=underscore
10+
911
// An interface that captures the Directed Acyclic Graph structure in which the nodes are connected.
1012
// If NodeLookup and DAGStructure are used together a traversal can be implemented.
1113
type DAGStructure interface {

pkg/controller/executors/execution_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"github.com/flyteorg/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
55
)
66

7+
// go:generate mockery -case=underscore
8+
79
type TaskDetailsGetter interface {
810
GetTask(id v1alpha1.TaskID) (v1alpha1.ExecutableTask, error)
911
}

pkg/controller/executors/kube.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"sigs.k8s.io/controller-runtime/pkg/client"
1414
)
1515

16+
//go:generate mockery -name Client -case=underscore
17+
1618
// Client is a friendlier controller-runtime client that gets passed to executors
1719
type Client interface {
1820
// GetClient returns a client configured with the Config

pkg/controller/executors/node_lookup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/flyteorg/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
77
)
88

9+
//go:generate mockery -name NodeLookup -case=underscore
10+
911
// NodeLookup provides a structure that enables looking up all nodes within the current execution hierarchy/context.
1012
// NOTE: execution hierarchy may change the nodes available, this is because when a SubWorkflow is being executed, only
1113
// the nodes within the subworkflow are visible

pkg/controller/executors/workflow.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/flyteorg/flytepropeller/pkg/apis/flyteworkflow/v1alpha1"
77
)
88

9+
//go:generate mockery -name Workflow -case=underscore
10+
911
type Workflow interface {
1012
Initialize(ctx context.Context) error
1113
HandleFlyteWorkflow(ctx context.Context, w *v1alpha1.FlyteWorkflow) error

pkg/controller/nodes/factory/handler_factory.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package factory
33
import (
44
"context"
55

6+
"k8s.io/client-go/kubernetes"
7+
68
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service"
79

810
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/catalog"
@@ -33,6 +35,7 @@ type handlerFactory struct {
3335
workflowLauncher launchplan.Executor
3436
launchPlanReader launchplan.Reader
3537
kubeClient executors.Client
38+
kubeClientset kubernetes.Interface
3639
catalogClient catalog.Client
3740
recoveryClient recovery.Client
3841
eventConfig *config.EventConfig
@@ -50,7 +53,7 @@ func (f *handlerFactory) GetHandler(kind v1alpha1.NodeKind) (interfaces.NodeHand
5053
}
5154

5255
func (f *handlerFactory) Setup(ctx context.Context, executor interfaces.Node, setup interfaces.SetupContext) error {
53-
t, err := task.New(ctx, f.kubeClient, f.catalogClient, f.eventConfig, f.clusterID, f.scope)
56+
t, err := task.New(ctx, f.kubeClient, f.kubeClientset, f.catalogClient, f.eventConfig, f.clusterID, f.scope)
5457
if err != nil {
5558
return err
5659
}
@@ -79,13 +82,14 @@ func (f *handlerFactory) Setup(ctx context.Context, executor interfaces.Node, se
7982
}
8083

8184
func NewHandlerFactory(ctx context.Context, workflowLauncher launchplan.Executor, launchPlanReader launchplan.Reader,
82-
kubeClient executors.Client, catalogClient catalog.Client, recoveryClient recovery.Client, eventConfig *config.EventConfig,
85+
kubeClient executors.Client, kubeClientset kubernetes.Interface, catalogClient catalog.Client, recoveryClient recovery.Client, eventConfig *config.EventConfig,
8386
clusterID string, signalClient service.SignalServiceClient, scope promutils.Scope) (interfaces.HandlerFactory, error) {
8487

8588
return &handlerFactory{
8689
workflowLauncher: workflowLauncher,
8790
launchPlanReader: launchPlanReader,
8891
kubeClient: kubeClient,
92+
kubeClientset: kubeClientset,
8993
catalogClient: catalogClient,
9094
recoveryClient: recoveryClient,
9195
eventConfig: eventConfig,

pkg/controller/nodes/task/handler.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"runtime/debug"
77
"time"
88

9+
"k8s.io/client-go/kubernetes"
10+
911
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
1012
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
1113
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/event"
@@ -195,6 +197,7 @@ type Handler struct {
195197
metrics *metrics
196198
pluginRegistry PluginRegistryIface
197199
kubeClient pluginCore.KubeClient
200+
kubeClientset kubernetes.Interface
198201
secretManager pluginCore.SecretManager
199202
resourceManager resourcemanager.BaseResourceManager
200203
cfg *config.Config
@@ -229,7 +232,7 @@ func (t *Handler) Setup(ctx context.Context, sCtx interfaces.SetupContext) error
229232

230233
// Create the resource negotiator here
231234
// and then convert it to proxies later and pass them to plugins
232-
enabledPlugins, defaultForTaskTypes, err := WranglePluginsAndGenerateFinalList(ctx, &t.cfg.TaskPlugins, t.pluginRegistry)
235+
enabledPlugins, defaultForTaskTypes, err := WranglePluginsAndGenerateFinalList(ctx, &t.cfg.TaskPlugins, t.pluginRegistry, t.kubeClientset)
233236
if err != nil {
234237
logger.Errorf(ctx, "Failed to finalize enabled plugins. Error: %s", err)
235238
return err
@@ -840,7 +843,8 @@ func (t Handler) Finalize(ctx context.Context, nCtx interfaces.NodeExecutionCont
840843
}()
841844
}
842845

843-
func New(ctx context.Context, kubeClient executors.Client, client catalog.Client, eventConfig *controllerConfig.EventConfig, clusterID string, scope promutils.Scope) (*Handler, error) {
846+
func New(ctx context.Context, kubeClient executors.Client, kubeClientset kubernetes.Interface, client catalog.Client,
847+
eventConfig *controllerConfig.EventConfig, clusterID string, scope promutils.Scope) (*Handler, error) {
844848
// TODO New should take a pointer
845849
async, err := catalog.NewAsyncClient(client, *catalog.GetConfig(), scope.NewSubScope("async_catalog"))
846850
if err != nil {
@@ -866,6 +870,7 @@ func New(ctx context.Context, kubeClient executors.Client, client catalog.Client
866870
},
867871
pluginScope: scope.NewSubScope("plugin"),
868872
kubeClient: kubeClient,
873+
kubeClientset: kubeClientset,
869874
catalog: client,
870875
asyncCatalog: async,
871876
resourceManager: nil,

0 commit comments

Comments
 (0)