-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [KEP-23] add toggle task (#1361)
* feat: add toggle task * add discovery client in toggle task tests * fix typo for toggle task in package.go * regenerate the golden files for toggletask * Update pkg/engine/task/task_toggle.go * address PR comments * Apply suggestions from code review * fix error formatting * add verify for param used in toggletask * removed dead code * fix linting * Apply suggestions from code review * fix linting * address PR comments and use delegateTask * e2e tests for ToggleTask * Fixed duplicate resources field in CRDs for task spec Adjusted IT again * Moved toggle task test to e2e instead of IT * Fixed param description in e2e test operator, removed assert for operatorversion which I added for debug Signed-off-by: Zain Malik <zmalikshxil@gmail.com> Co-authored-by: Aleksey Dukhovniy <adukhovniy@mesosphere.io> Co-authored-by: Jan Schlicht <jan.schlicht+gh@gmail.com> Co-authored-by: Ken Sipe <kensipe@gmail.com> Co-authored-by: Andreas Neumann <aneumann@mesosphere.com>
- Loading branch information
1 parent
8616529
commit 85486ce
Showing
28 changed files
with
514 additions
and
10 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package task | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1" | ||
) | ||
|
||
const ( | ||
toggleTaskError = "ToggleTaskError" | ||
) | ||
|
||
// ToggleTask will apply or delete a set of given resources to the cluster based on value of Parameter. See Run method for more details. | ||
type ToggleTask struct { | ||
Name string | ||
Parameter string | ||
Resources []string | ||
} | ||
|
||
func (tt ToggleTask) Run(ctx Context) (bool, error) { | ||
// 1. - Get the task to run | ||
task, err := tt.delegateTask(ctx) | ||
if err != nil { | ||
return false, fatalExecutionError(err, toggleTaskError, ctx.Meta) | ||
} | ||
// 2. - Run the returned task | ||
return task.Run(ctx) | ||
} | ||
|
||
func (tt ToggleTask) intermediateTaskSpec() v1beta1.TaskSpec { | ||
return v1beta1.TaskSpec{ | ||
ResourceTaskSpec: v1beta1.ResourceTaskSpec{ | ||
Resources: tt.Resources, | ||
}, | ||
} | ||
} | ||
|
||
func (tt ToggleTask) delegateTask(ctx Context) (Tasker, error) { | ||
var task Tasker | ||
// 1. - Get the parameter value | ||
val, exists := ctx.Parameters[tt.Parameter] | ||
if !exists { | ||
return task, fmt.Errorf("no value for parameter %s found", tt.Parameter) | ||
} | ||
enabled, err := strconv.ParseBool(val) | ||
if err != nil { | ||
return task, fmt.Errorf("could not parse value of parameter %s: %v", tt.Parameter, err) | ||
} | ||
// 2. - Return the Apply or Delete task based on parameter value | ||
if enabled { | ||
task, err = newApply(&v1beta1.Task{ | ||
Name: tt.Name, | ||
Kind: ApplyTaskKind, | ||
Spec: tt.intermediateTaskSpec(), | ||
}) | ||
} else { | ||
task, err = newDelete(&v1beta1.Task{ | ||
Name: tt.Name, | ||
Kind: DeleteTaskKind, | ||
Spec: tt.intermediateTaskSpec(), | ||
}) | ||
} | ||
return task, err | ||
} |
Oops, something went wrong.