-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow for setting default configurations for workflows, Fixes #1923, #2044 #2331
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2b9b943
new start
69276aa
updated to use commen object def
22756ff
updated the ttlcontroller to use the defaults if they are available
9c17390
test is running
0baedc3
updated with more tests!
822fba0
tests pass
aca356b
updated further to also check used default for expired
50b27ec
updated with futher tests
79477ab
missed pointer
e034db7
Merge branch 'master' into master
alexec 18f45d6
Update config.go
NikeNano 75c6cc5
removed comment
c6b91cc
Update workflow/ttlcontroller/ttlcontroller_test.go
NikeNano 81228ff
Merge branch 'master' into remote_master
fcd03c1
initial work
1823b9e
updated after feedback
ab94227
updated the error handling
750e05f
changed design in addingWorkflowdefault....
d4d1985
updated
d7e8f55
updated the tests
f7bfb82
need to update with further tests
45ecb37
misstake before we only want to do the merge
fdac75e
added more test cases
052d567
updated with short documentation
c1bf852
Update config.go
NikeNano c5f5f2d
Update controller.go
NikeNano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package controller | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
@@ -17,6 +18,7 @@ import ( | |
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/selection" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/util/strategicpatch" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/kubernetes" | ||
|
@@ -45,8 +47,10 @@ type WorkflowController struct { | |
// namespace of the workflow controller | ||
namespace string | ||
managedNamespace string | ||
|
||
// configMap is the name of the config map in which to derive configuration of the controller from | ||
configMap string | ||
|
||
// Config is the workflow controller's configuration | ||
Config config.WorkflowControllerConfig | ||
|
||
|
@@ -355,16 +359,22 @@ func (wfc *WorkflowController) processNextItem() bool { | |
wfc.throttler.Remove(key) | ||
return true | ||
} | ||
err = wfc.addingWorkflowDefaultValueIfValueNotExist(wf) | ||
if err != nil { | ||
log.Warnf("Failed to unmarshal key '%s' to workflow object: %v", key, err) | ||
woc := newWorkflowOperationCtx(wf, wfc) | ||
woc.markWorkflowFailed(fmt.Sprintf("invalid spec: %s", err.Error())) | ||
woc.persistUpdates() | ||
wfc.throttler.Remove(key) | ||
} | ||
|
||
if wf.ObjectMeta.Labels[common.LabelKeyCompleted] == "true" { | ||
wfc.throttler.Remove(key) | ||
// can get here if we already added the completed=true label, | ||
// but we are still draining the controller's workflow workqueue | ||
return true | ||
} | ||
|
||
woc := newWorkflowOperationCtx(wf, wfc) | ||
|
||
// Loading running workflow from persistence storage if nodeStatusOffload enabled | ||
if wf.Status.IsOffloadNodeStatus() { | ||
nodes, err := wfc.offloadNodeStatusRepo.Get(string(wf.UID), wf.GetOffloadNodeStatusVersion()) | ||
|
@@ -417,6 +427,33 @@ func (wfc *WorkflowController) processNextItem() bool { | |
return true | ||
} | ||
|
||
// addingWorkflowDefaultValueIfValueNotExist sets values in the workflow.Spec with defaults from the | ||
// workflowController. Values in the workflow will be given the upper hand over the defaults. | ||
// The defaults for the workflow controller is set in the WorkflowController.Config.DefautWorkflowSpec | ||
func (wfc *WorkflowController) addingWorkflowDefaultValueIfValueNotExist(wf *wfv1.Workflow) error { | ||
//var workflowSpec *wfv1.WorkflowSpec = &wf.Spec | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this unused line? |
||
if wfc.Config.DefautWorkflowSpec != nil { | ||
defaultsSpec, err := json.Marshal(*wfc.Config.DefautWorkflowSpec) | ||
if err != nil { | ||
return err | ||
} | ||
workflowSpec, err := json.Marshal(wf.Spec) | ||
if err != nil { | ||
return err | ||
} | ||
// https://github.com/kubernetes/apimachinery/blob/2373d029717c4d169463414a6127cd1d0d12680e/pkg/util/strategicpatch/patch.go#L94 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link to the docs directly? https://godoc.org/k8s.io/apimachinery/pkg/util/strategicpatch#StrategicMergePatch |
||
new, err := strategicpatch.StrategicMergePatch(defaultsSpec, workflowSpec, wfv1.WorkflowSpec{}) | ||
if err != nil { | ||
return err | ||
} | ||
err = json.Unmarshal(new, &wf.Spec) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (wfc *WorkflowController) podWorker() { | ||
for wfc.processNextPodItem() { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a docstring above this, like the rest of the configs