Skip to content

Commit

Permalink
Merge pull request #4390 from werf/feat-kube-run-pod-and-container-na…
Browse files Browse the repository at this point in the history
…me-exposed-in-overrides

feat(kube-run): pod and container name can be used in --overrides
  • Loading branch information
ilya-lesikov committed Apr 21, 2022
2 parents 18345ce + 0062332 commit f2db2f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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)
}
3 changes: 2 additions & 1 deletion docs/_includes/reference/cli/werf_kube_run.md
Expand Up @@ -142,7 +142,8 @@ werf kube-run [options] [IMAGE_NAME] [-- COMMAND ARG...]
deploy.namespace custom template from werf.yaml or $WERF_NAMESPACE)
--overrides=''
Inline JSON to override/extend any fields in created Pod, e.g. to add imagePullSecrets
field (default $WERF_OVERRIDES)
field (default $WERF_OVERRIDES). %pod_name% and %container_name% will be replaced with
names of a created pod and a container.
--platform=''
Enable platform emulation when building images with werf. The only supported option for
now is linux/amd64.
Expand Down

0 comments on commit f2db2f6

Please sign in to comment.