Skip to content
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(kube-run): pod and container name can be used in --overrides #4390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/werf/kube_run/kube_run.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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