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

Allow setting service account with kubectl run #46318

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/kubectl/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func addRunFlags(cmd *cobra.Command) {
cmd.Flags().Bool("rm", false, "If true, delete resources created in this command for attached containers.")
cmd.Flags().String("overrides", "", i18n.T("An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field."))
cmd.Flags().StringArray("env", []string{}, "Environment variables to set in the container")
cmd.Flags().String("serviceaccount", "", "Service account to set in the pod spec")
cmd.Flags().String("port", "", i18n.T("The port that this container exposes. If --expose is true, this is also the port used by the service that is created."))
cmd.Flags().Int("hostport", -1, "The host port mapping for the container port. To demonstrate a single-machine container.")
cmd.Flags().StringP("labels", "l", "", "Labels to apply to the pod(s).")
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubectl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (DeploymentV1Beta1) ParamNames() []GeneratorParam {
{"env", false},
{"requests", false},
{"limits", false},
{"serviceaccount", false},
}
}

Expand Down Expand Up @@ -141,6 +142,7 @@ func (DeploymentAppsV1Beta1) ParamNames() []GeneratorParam {
{"env", false},
{"requests", false},
{"limits", false},
{"serviceaccount", false},
}
}

Expand Down Expand Up @@ -306,6 +308,7 @@ func (JobV1) ParamNames() []GeneratorParam {
{"requests", false},
{"limits", false},
{"restart", false},
{"serviceaccount", false},
}
}

Expand Down Expand Up @@ -400,6 +403,7 @@ func (CronJobV2Alpha1) ParamNames() []GeneratorParam {
{"limits", false},
{"restart", false},
{"schedule", true},
{"serviceaccount", false},
}
}

Expand Down Expand Up @@ -498,6 +502,7 @@ func (BasicReplicationController) ParamNames() []GeneratorParam {
{"env", false},
{"requests", false},
{"limits", false},
{"serviceaccount", false},
}
}

Expand Down Expand Up @@ -603,6 +608,7 @@ func makePodSpec(params map[string]string, name string) (*v1.PodSpec, error) {
}

spec := v1.PodSpec{
ServiceAccountName: params["serviceaccount"],
Containers: []v1.Container{
{
Name: name,
Expand Down Expand Up @@ -761,6 +767,7 @@ func (BasicPod) ParamNames() []GeneratorParam {
{"env", false},
{"requests", false},
{"limits", false},
{"serviceaccount", false},
}
}

Expand Down Expand Up @@ -821,6 +828,7 @@ func (BasicPod) Generate(genericParams map[string]interface{}) (runtime.Object,
Labels: labels,
},
Spec: v1.PodSpec{
ServiceAccountName: params["serviceaccount"],
Containers: []v1.Container{
{
Name: name,
Expand Down