-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from mshitrit/add-options-for-pod-executor
adding options to pod execution
- Loading branch information
Showing
2 changed files
with
61 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package command | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
type optionType int | ||
|
||
const ( | ||
useCustomizedPod optionType = iota | ||
noOutputExpected | ||
) | ||
|
||
type RunOption interface { | ||
getOptionType() optionType | ||
getOptionValue() interface{} | ||
} | ||
|
||
type runOption struct { | ||
optionType | ||
value interface{} | ||
} | ||
|
||
func (ro *runOption) getOptionType() optionType { | ||
return ro.optionType | ||
} | ||
|
||
func (ro *runOption) getOptionValue() interface{} { | ||
return ro.value | ||
} | ||
|
||
// CreateOptionUseCustomizedExecutePod allows executing a command on a pod provided by this option instead of the default one | ||
func CreateOptionUseCustomizedExecutePod(pod *corev1.Pod) RunOption { | ||
return &runOption{useCustomizedPod, pod} | ||
} | ||
|
||
// CreateOptionNoExpectedOutput allows executing a command on a pod when no output is expected from the command | ||
func CreateOptionNoExpectedOutput() RunOption { | ||
return &runOption{optionType: noOutputExpected} | ||
} | ||
|
||
func convertToMap(opts []RunOption) map[optionType]interface{} { | ||
runOptions := make(map[optionType]interface{}) | ||
for _, option := range opts { | ||
runOptions[option.getOptionType()] = option.getOptionValue() | ||
} | ||
|
||
return runOptions | ||
} |