Skip to content

Commit

Permalink
Add --pull-secret flag
Browse files Browse the repository at this point in the history
 Fixes knative#616

 - Add --pull-secret flag for service create/update operations
 - Setting empty string to flag clears the pull secrets
 - List ImagePullSecrets for service in `service describe` default output
 - Run e2e tests against serving v0.11.1 (ImagePullSecrets introduced in this release)
  • Loading branch information
navidshaikh committed Jan 21, 2020
1 parent de7e388 commit 9af3737
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/cmd/kn_service_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ kn service create NAME --image IMAGE [flags]
-n, --namespace string Specify the namespace to operate in.
--no-lock-to-digest do not 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)
-p, --port int32 The port where application listens on.
--pull-secrets string Image pull secrets to set. Empty image pull secrets will result to clear the pull secrets.
--requests-cpu string The requested CPU (e.g., 250m).
--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}}")
Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ kn service update NAME [flags]
-n, --namespace string Specify the namespace to operate in.
--no-lock-to-digest do not 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)
-p, --port int32 The port where application listens on.
--pull-secrets string Image pull secrets to set. Empty image pull secrets will result to clear the pull secrets.
--requests-cpu string The requested CPU (e.g., 250m).
--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}}")
Expand Down
10 changes: 10 additions & 0 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ConfigurationEditFlags struct {
NamePrefix string
RevisionName string
ServiceAccountName string
ImagePullSecrets string
Annotations []string

// Preferences about how to do the action.
Expand Down Expand Up @@ -145,6 +146,11 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) {
"any number of times to set multiple annotations. "+
"To unset, specify the annotation name followed by a \"-\" (e.g., name-).")
p.markFlagMakesRevision("annotation")
command.Flags().StringVar(&p.ImagePullSecrets,
"pull-secrets",
"",
"Image pull secrets to set. Empty image pull secrets will result to clear the pull secrets.")
p.markFlagMakesRevision("pull-secrets")
}

// AddUpdateFlags adds the flags specific to update.
Expand Down Expand Up @@ -337,6 +343,10 @@ func (p *ConfigurationEditFlags) Apply(
}
}

if cmd.Flags().Changed("pull-secrets") {
servinglib.UpdateImagePullSecrets(template, p.ImagePullSecrets)
}

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/kn/commands/service/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func writeService(dw printers.PrefixWriter, service *v1alpha1.Service) {
if (service.Spec.Template != nil) && (service.Spec.Template.Spec.ServiceAccountName != "") {
dw.WriteAttribute("ServiceAccount", service.Spec.Template.Spec.ServiceAccountName)
}
if (service.Spec.Template != nil) && service.Spec.Template.Spec.ImagePullSecrets != nil {
dw.WriteAttribute("ImagePullSecrets", service.Spec.Template.Spec.ImagePullSecrets[0].Name)
}
}

// Write out revisions associated with this service. By default only active
Expand Down
12 changes: 12 additions & 0 deletions pkg/serving/config_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ func UpdateServiceAccountName(template *servingv1alpha1.RevisionTemplateSpec, se
return nil
}

// UpdateImagePullSecrets updates the image pull secrets used for the corresponding knative service
func UpdateImagePullSecrets(template *servingv1alpha1.RevisionTemplateSpec, pullsecrets string) {
pullsecrets = strings.TrimSpace(pullsecrets)
if pullsecrets == "" {
template.Spec.ImagePullSecrets = nil
} else {
template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{{
Name: pullsecrets,
}}
}
}

// GenerateVolumeName generates a volume name with respect to a given path string.
// Current implementation basically sanitizes the path string by changing "/" into "."
// To reduce any chance of duplication, a checksum part generated from the path string is appended to the sanitized string.
Expand Down
11 changes: 11 additions & 0 deletions pkg/serving/config_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,17 @@ func TestUpdateServiceAccountName(t *testing.T) {
assert.Equal(t, template.Spec.ServiceAccountName, "")
}

func TestUpdateImagePullSecrets(t *testing.T) {
template, _ := getV1alpha1RevisionTemplateWithOldFields()
template.Spec.ImagePullSecrets = nil

UpdateImagePullSecrets(template, "quay")
assert.Equal(t, template.Spec.ImagePullSecrets[0].Name, "quay")

UpdateImagePullSecrets(template, " ")
assert.Check(t, template.Spec.ImagePullSecrets == nil)
}

func TestUpdateAnnotationsNew(t *testing.T) {
service, template, _ := getV1alpha1Service()

Expand Down
2 changes: 1 addition & 1 deletion test/presubmit-integration-tests-latest-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# We currently take 0.10.0 for Serving and 0.10.2 for Eventing as the
# latest release version.

export KNATIVE_SERVING_VERSION="0.11.0"
export KNATIVE_SERVING_VERSION="0.11.1"
export KNATIVE_EVENTING_VERSION="0.11.0"

$(dirname $0)/presubmit-tests.sh --integration-tests

0 comments on commit 9af3737

Please sign in to comment.