mirror of https://github.com/knative/client.git
Add --service-account-name flag (#401)
* Add --service-account-name flag * Change the flag --service-account-name to --service-account, and change its default value from "-" to an empty string. In addition, CHANGELOG.adoc is changed. * Update docs with ./hack/build.sh
This commit is contained in:
parent
43f8386b82
commit
14ec594e56
|
@ -58,6 +58,10 @@
|
||||||
| Add documentation for traffic splitting and tagging targets
|
| Add documentation for traffic splitting and tagging targets
|
||||||
| https://github.com/knative/client/pull/331[#331]
|
| https://github.com/knative/client/pull/331[#331]
|
||||||
|
|
||||||
|
| 🎁
|
||||||
|
| Add --service-account flag
|
||||||
|
| https://github.com/knative/client/pull/401[#401]
|
||||||
|
|
||||||
|===
|
|===
|
||||||
|
|
||||||
## v0.2.0 (2019-07-10)
|
## v0.2.0 (2019-07-10)
|
||||||
|
|
|
@ -58,6 +58,7 @@ kn service create NAME --image IMAGE [flags]
|
||||||
--requests-cpu string The requested CPU (e.g., 250m).
|
--requests-cpu string The requested CPU (e.g., 250m).
|
||||||
--requests-memory string The requested memory (e.g., 64Mi).
|
--requests-memory string The requested memory (e.g., 64Mi).
|
||||||
--revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}")
|
--revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}")
|
||||||
|
--service-account string Service account name to set. Empty service account name will result to clear the service account.
|
||||||
--wait-timeout int Seconds to wait before giving up on waiting for service to be ready. (default 60)
|
--wait-timeout int Seconds to wait before giving up on waiting for service to be ready. (default 60)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ kn service update NAME [flags]
|
||||||
--requests-cpu string The requested CPU (e.g., 250m).
|
--requests-cpu string The requested CPU (e.g., 250m).
|
||||||
--requests-memory string The requested memory (e.g., 64Mi).
|
--requests-memory string The requested memory (e.g., 64Mi).
|
||||||
--revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}")
|
--revision-name string The revision name to set. Must start with the service name and a dash as a prefix. Empty revision name will result in the server generating a name for the revision. Accepts golang templates, allowing {{.Service}} for the service name, {{.Generation}} for the generation, and {{.Random [n]}} for n random consonants. (default "{{.Service}}-{{.Random 5}}-{{.Generation}}")
|
||||||
|
--service-account string Service account name to set. Empty service account name will result to clear the service account.
|
||||||
--tag strings Set tag (format: --tag revisionRef=tagName) where revisionRef can be a revision or '@latest' string representing latest ready revision. This flag can be specified multiple times.
|
--tag strings Set tag (format: --tag revisionRef=tagName) where revisionRef can be a revision or '@latest' string representing latest ready revision. This flag can be specified multiple times.
|
||||||
--traffic strings Set traffic distribution (format: --traffic revisionRef=percent) where revisionRef can be a revision or a tag or '@latest' string representing latest ready revision. This flag can be given multiple times with percent summing up to 100%.
|
--traffic strings Set traffic distribution (format: --traffic revisionRef=percent) where revisionRef can be a revision or a tag or '@latest' string representing latest ready revision. This flag can be given multiple times with percent summing up to 100%.
|
||||||
--untag strings Untag revision (format: --untag tagName). This flag can be spcified multiple times.
|
--untag strings Untag revision (format: --untag tagName). This flag can be spcified multiple times.
|
||||||
|
|
|
@ -40,6 +40,7 @@ type ConfigurationEditFlags struct {
|
||||||
Labels []string
|
Labels []string
|
||||||
NamePrefix string
|
NamePrefix string
|
||||||
RevisionName string
|
RevisionName string
|
||||||
|
ServiceAccountName string
|
||||||
|
|
||||||
// Preferences about how to do the action.
|
// Preferences about how to do the action.
|
||||||
LockToDigest bool
|
LockToDigest bool
|
||||||
|
@ -107,7 +108,8 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) {
|
||||||
"keep the running image for the service constant when not explicitly specifying "+
|
"keep the running image for the service constant when not explicitly specifying "+
|
||||||
"the image. (--no-lock-to-digest pulls the image tag afresh with each new revision)")
|
"the image. (--no-lock-to-digest pulls the image tag afresh with each new revision)")
|
||||||
// Don't mark as changing the revision.
|
// Don't mark as changing the revision.
|
||||||
|
command.Flags().StringVar(&p.ServiceAccountName, "service-account", "", "Service account name to set. Empty service account name will result to clear the service account.")
|
||||||
|
p.markFlagMakesRevision("service-account")
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUpdateFlags adds the flags specific to update.
|
// AddUpdateFlags adds the flags specific to update.
|
||||||
|
@ -254,6 +256,13 @@ func (p *ConfigurationEditFlags) Apply(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd.Flags().Changed("service-account") {
|
||||||
|
err = servinglib.UpdateServiceAccountName(template, p.ServiceAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -472,3 +472,24 @@ func TestServiceCreateEnvForce(t *testing.T) {
|
||||||
t.Fatalf("wrong output: %s", output)
|
t.Fatalf("wrong output: %s", output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServiceCreateWithServiceAccountName(t *testing.T) {
|
||||||
|
action, created, _, err := fakeServiceCreate([]string{
|
||||||
|
"service", "create", "foo", "--image", "gcr.io/foo/bar:baz",
|
||||||
|
"--service-account", "foo-bar-account",
|
||||||
|
"--async"}, false, false)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if !action.Matches("create", "services") {
|
||||||
|
t.Fatalf("Bad action %v", action)
|
||||||
|
}
|
||||||
|
|
||||||
|
template, err := servinglib.RevisionTemplateOfService(created)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if template.Spec.ServiceAccountName != "foo-bar-account" {
|
||||||
|
t.Fatalf("wrong service account name:%v", template.Spec.ServiceAccountName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -245,6 +245,13 @@ func UpdateLabels(service *servingv1alpha1.Service, template *servingv1alpha1.Re
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateServiceAccountName updates the service account name used for the corresponding knative service
|
||||||
|
func UpdateServiceAccountName(template *servingv1alpha1.RevisionTemplateSpec, serviceAccountName string) error {
|
||||||
|
serviceAccountName = strings.TrimSpace(serviceAccountName)
|
||||||
|
template.Spec.ServiceAccountName = serviceAccountName
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// =======================================================================================
|
// =======================================================================================
|
||||||
|
|
||||||
func updateEnvVarsFromMap(env []corev1.EnvVar, toUpdate map[string]string) []corev1.EnvVar {
|
func updateEnvVarsFromMap(env []corev1.EnvVar, toUpdate map[string]string) []corev1.EnvVar {
|
||||||
|
|
|
@ -408,6 +408,17 @@ func TestUpdateLabelsRemoveExisting(t *testing.T) {
|
||||||
assert.DeepEqual(t, expected, actual)
|
assert.DeepEqual(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateServiceAccountName(t *testing.T) {
|
||||||
|
template, _ := getV1alpha1RevisionTemplateWithOldFields()
|
||||||
|
template.Spec.ServiceAccountName = ""
|
||||||
|
|
||||||
|
UpdateServiceAccountName(template, "foo-bar")
|
||||||
|
assert.Equal(t, template.Spec.ServiceAccountName, "foo-bar")
|
||||||
|
|
||||||
|
UpdateServiceAccountName(template, "")
|
||||||
|
assert.Equal(t, template.Spec.ServiceAccountName, "")
|
||||||
|
}
|
||||||
|
|
||||||
// =========================================================================================================
|
// =========================================================================================================
|
||||||
|
|
||||||
func getV1alpha1RevisionTemplateWithOldFields() (*servingv1alpha1.RevisionTemplateSpec, *corev1.Container) {
|
func getV1alpha1RevisionTemplateWithOldFields() (*servingv1alpha1.RevisionTemplateSpec, *corev1.Container) {
|
||||||
|
|
Loading…
Reference in New Issue