Navigation Menu

Skip to content

Commit

Permalink
feat(kube-run): pod and container name can be used in --overrides
Browse files Browse the repository at this point in the history
%container_name% and %pod_name% now replaced with container/pod name in `kube-run --overrides`.

Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Apr 21, 2022
1 parent 18345ce commit 686b402
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/werf/kube_run/kube_run.go
Expand Up @@ -168,7 +168,7 @@ func NewCmd() *cobra.Command {
common.SetupPlatform(&commonCmdData, cmd)

cmd.Flags().StringVarP(&cmdData.Pod, "pod", "", os.Getenv("WERF_POD"), "Set created pod name (default $WERF_POD or autogenerated if not specified)")
cmd.Flags().StringVarP(&cmdData.Overrides, "overrides", "", os.Getenv("WERF_OVERRIDES"), "Inline JSON to override/extend any fields in created Pod, e.g. to add imagePullSecrets field (default $WERF_OVERRIDES)")
cmd.Flags().StringVarP(&cmdData.Overrides, "overrides", "", os.Getenv("WERF_OVERRIDES"), "Inline JSON to override/extend any fields in created Pod, e.g. to add imagePullSecrets field (default $WERF_OVERRIDES). %pod_name% and %container_name% will be replaced with names of a created pod and a container.")
cmd.Flags().StringVarP(&cmdData.ExtraOptions, "extra-options", "", os.Getenv("WERF_EXTRA_OPTIONS"), "Pass extra options to \"kubectl run\" command (default $WERF_EXTRA_OPTIONS)")
cmd.Flags().BoolVarP(&cmdData.Rm, "rm", "", common.GetBoolEnvironmentDefaultTrue("WERF_RM"), "Remove pod and other created resources after command completion (default $WERF_RM or true if not specified)")
cmd.Flags().BoolVarP(&cmdData.RmWithNamespace, "rm-with-namespace", "", common.GetBoolEnvironmentDefaultFalse("WERF_RM_WITH_NAMESPACE"), "Remove also a namespace after command completion (default $WERF_RM_WITH_NAMESPACE or false if not specified)")
Expand Down Expand Up @@ -272,6 +272,8 @@ func runMain(ctx context.Context) error {
}
secret := pod

cmdData.Overrides = templateOverrides(cmdData.Overrides, pod, pod)

_, werfConfig, err := common.GetRequiredWerfConfig(ctx, &commonCmdData, giterminismManager, common.GetWerfConfigOptions(&commonCmdData, false))
if err != nil {
return fmt.Errorf("unable to load werf config: %w", err)
Expand Down Expand Up @@ -698,3 +700,8 @@ func addImagePullSecret(secret string, overrides map[string]interface{}) (map[st
overrides["spec"].(map[string]interface{})["imagePullSecrets"] = append(overrides["spec"].(map[string]interface{})["imagePullSecrets"].([]interface{}), newImagePullSecret)
return overrides, nil
}

func templateOverrides(line, podName, containerName string) string {
result := strings.ReplaceAll(line, "%container_name%", containerName)
return strings.ReplaceAll(result, "%pod_name%", podName)
}

0 comments on commit 686b402

Please sign in to comment.