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

Commit

Permalink
Update and fix conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Regadas <[email protected]>
  • Loading branch information
regadas committed Mar 18, 2021
1 parent 2fb4787 commit e7cfb64
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/benlaurie/objecthash v0.0.0-20180202135721-d1e3d6079fc1
github.com/fatih/color v1.10.0
github.com/flyteorg/flyteidl v0.18.20
github.com/flyteorg/flyteplugins v0.5.37
github.com/flyteorg/flyteplugins v0.5.38
github.com/flyteorg/flytestdlib v0.3.13
github.com/ghodss/yaml v1.0.0
github.com/go-redis/redis v6.15.7+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4
github.com/flyteorg/flyteidl v0.18.17/go.mod h1:b5Fq4Z8a5b0mF6pEwTd48ufvikUGVkWSjZiMT0ZtqKI=
github.com/flyteorg/flyteidl v0.18.20 h1:OGOb2FOHWL363Qp8uzbJeFbQBKYPT30+afv+8BnBlGs=
github.com/flyteorg/flyteidl v0.18.20/go.mod h1:b5Fq4Z8a5b0mF6pEwTd48ufvikUGVkWSjZiMT0ZtqKI=
github.com/flyteorg/flyteplugins v0.5.37 h1:9kl91k2xG5QJbhdSwoTa7XFnLIynBsidcwBlbsysr5s=
github.com/flyteorg/flyteplugins v0.5.37/go.mod h1:CxerBGWWEmNYmPxSMHnwQEr9cc1Fbo/g5fcABazU6Jo=
github.com/flyteorg/flyteplugins v0.5.38 h1:xAQ1J23cRxzwNDgzbmRuuvflq2PFetntRCjuM5RBfTw=
github.com/flyteorg/flyteplugins v0.5.38/go.mod h1:CxerBGWWEmNYmPxSMHnwQEr9cc1Fbo/g5fcABazU6Jo=
github.com/flyteorg/flytestdlib v0.3.13 h1:5ioA/q3ixlyqkFh5kDaHgmPyTP/AHtqq1K/TIbVLUzM=
github.com/flyteorg/flytestdlib v0.3.13/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk=
Expand Down
31 changes: 15 additions & 16 deletions pkg/controller/nodes/task/k8s/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ type PluginManager struct {
kubeClient pluginsCore.KubeClient
metrics PluginMetrics
// Per namespace-resource
backOffController *backoff.Controller
resourceLevelMonitor *ResourceLevelMonitor
overrideInjectOwnerReferences *bool
overrideInjectFinalizer *bool
backOffController *backoff.Controller
resourceLevelMonitor *ResourceLevelMonitor
disableInjectOwnerReferences bool
disableInjectFinalizer bool
}

func (e *PluginManager) AddObjectMetadata(taskCtx pluginsCore.TaskExecutionMetadata, o client.Object, cfg *config.K8sPluginConfig) {
Expand All @@ -109,12 +109,11 @@ func (e *PluginManager) AddObjectMetadata(taskCtx pluginsCore.TaskExecutionMetad
o.SetLabels(utils.UnionMaps(o.GetLabels(), utils.CopyMap(taskCtx.GetLabels()), cfg.DefaultLabels))
o.SetName(taskCtx.GetTaskExecutionID().GetGeneratedName())

if e.overrideInjectOwnerReferences != nil && *e.overrideInjectOwnerReferences {
if !e.disableInjectOwnerReferences {
o.SetOwnerReferences([]metav1.OwnerReference{taskCtx.GetOwnerReference()})
}

overrideInjectFinalizer := e.overrideInjectFinalizer
if (overrideInjectFinalizer != nil && *overrideInjectFinalizer) || cfg.InjectFinalizer {
if cfg.InjectFinalizer && !e.disableInjectFinalizer {
f := append(o.GetFinalizers(), finalizer)
o.SetFinalizers(f)
}
Expand Down Expand Up @@ -421,7 +420,7 @@ func NewPluginManager(ctx context.Context, iCtx pluginsCore.SetupContext, entry
}

workflowParentPredicate := func(o metav1.Object) bool {
if entry.OverrideInjectOwnerReferences != nil && *entry.OverrideInjectOwnerReferences {
if entry.DisableInjectOwnerReferences {
return true
}

Expand Down Expand Up @@ -515,14 +514,14 @@ func NewPluginManager(ctx context.Context, iCtx pluginsCore.SetupContext, entry
rm.RunCollectorOnce(ctx)

return &PluginManager{
id: entry.ID,
plugin: entry.Plugin,
resourceToWatch: entry.ResourceToWatch,
metrics: newPluginMetrics(metricsScope),
kubeClient: kubeClient,
resourceLevelMonitor: rm,
overrideInjectOwnerReferences: entry.OverrideInjectOwnerReferences,
overrideInjectFinalizer: entry.OverrideInjectFinalizer,
id: entry.ID,
plugin: entry.Plugin,
resourceToWatch: entry.ResourceToWatch,
metrics: newPluginMetrics(metricsScope),
kubeClient: kubeClient,
resourceLevelMonitor: rm,
disableInjectOwnerReferences: entry.DisableInjectOwnerReferences,
disableInjectFinalizer: entry.DisableInjectFinalizer,
}, nil
}

Expand Down
52 changes: 35 additions & 17 deletions pkg/controller/nodes/task/k8s/plugin_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,7 @@ func TestPluginManager_CustomKubeClient(t *testing.T) {
}

func TestPluginManager_AddObjectMetadata_IgnoreOwnerReferences(t *testing.T) {
override := true
pluginManager := PluginManager{overrideInjectOwnerReferences: &override}
pluginManager := PluginManager{disableInjectOwnerReferences: true}
genName := "genName"
ns := "ns"
or := v12.OwnerReference{}
Expand All @@ -611,11 +610,9 @@ func TestPluginManager_AddObjectMetadata_IgnoreOwnerReferences(t *testing.T) {
}

func TestPluginManager_AddObjectMetadata_InjectFinalizer(t *testing.T) {
overrideInjectOwnerRef := true
overrideInjectFinalizer := true
pluginManager := PluginManager{
overrideInjectOwnerReferences: &overrideInjectOwnerRef,
overrideInjectFinalizer: &overrideInjectFinalizer,
disableInjectOwnerReferences: true,
disableInjectFinalizer: true,
}
genName := "genName"
ns := "ns"
Expand All @@ -626,17 +623,38 @@ func TestPluginManager_AddObjectMetadata_InjectFinalizer(t *testing.T) {

o := &v1.Pod{}
cfg := config.GetK8sPluginConfig()
pluginManager.AddObjectMetadata(tm, o, cfg)
assert.Equal(t, genName, o.GetName())
// empty OwnerReference since we are ignoring
assert.Equal(t, 0, len(o.GetOwnerReferences()))
assert.Equal(t, ns, o.GetNamespace())
assert.Equal(t, map[string]string{
"cluster-autoscaler.kubernetes.io/safe-to-evict": "false",
"aKey": "aVal",
}, o.GetAnnotations())
assert.Equal(t, l, o.GetLabels())
assert.Equal(t, 1, len(o.GetFinalizers()))

t.Run("Disable enbaled InjectFinalizer", func(t *testing.T) {
// enable finalizer injection
cfg.InjectFinalizer = true
pluginManager.AddObjectMetadata(tm, o, cfg)
assert.Equal(t, genName, o.GetName())
// empty OwnerReference since we are ignoring
assert.Equal(t, 0, len(o.GetOwnerReferences()))
assert.Equal(t, ns, o.GetNamespace())
assert.Equal(t, map[string]string{
"cluster-autoscaler.kubernetes.io/safe-to-evict": "false",
"aKey": "aVal",
}, o.GetAnnotations())
assert.Equal(t, l, o.GetLabels())
assert.Equal(t, 0, len(o.GetFinalizers()))
})

t.Run("Disable disabled InjectFinalizer", func(t *testing.T) {
// enable finalizer injection
cfg.InjectFinalizer = false
pluginManager.AddObjectMetadata(tm, o, cfg)
assert.Equal(t, genName, o.GetName())
// empty OwnerReference since we are ignoring
assert.Equal(t, 0, len(o.GetOwnerReferences()))
assert.Equal(t, ns, o.GetNamespace())
assert.Equal(t, map[string]string{
"cluster-autoscaler.kubernetes.io/safe-to-evict": "false",
"aKey": "aVal",
}, o.GetAnnotations())
assert.Equal(t, l, o.GetLabels())
assert.Equal(t, 0, len(o.GetFinalizers()))
})
}

func TestPluginManager_AddObjectMetadata(t *testing.T) {
Expand Down

0 comments on commit e7cfb64

Please sign in to comment.