Repository: knative-sandbox/kn-plugin-func
Pull request #749 (2022-01-12 13:19:51)

[main] Update actions
Cron -knative-prow-robot

/cc knative-sandbox/kn-plugin-func-approvers
/assign knative-sandbox/kn-plugin-func-approvers

Produced by: knative-sandbox/knobots/actions/update-actions

Details:
```

```

knative-prow-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative-sandbox/kn-plugin-func/pull/749#" title="Author self-approved">knative-automation</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **lkingland** after the PR has been reviewed.
You can assign the PR to them by writing `/assign @lkingland` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative-sandbox%2Fkn-plugin-func).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/knative-sandbox/kn-plugin-func/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["lkingland"]} -->
codecov[bot]: # [Codecov](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/749?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox) Report
> Merging [#749](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/749?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox) (5717805) into [main](https://codecov.io/gh/knative-sandbox/kn-plugin-func/commit/47c82c0375f3fb7d16092a588cd3bf511e849e3e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox) (47c82c0) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/749/graphs/tree.svg?width=650&height=150&src=pr&token=da1B9bMsQ9&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox)](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/749?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox)

```diff
@@           Coverage Diff           @@
##             main     #749   +/-   ##
=======================================
  Coverage   41.52%   41.52%           
=======================================
  Files          42       42           
  Lines        4101     4101           
=======================================
  Hits         1703     1703           
  Misses       2145     2145           
  Partials      253      253           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/749?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/749?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox). Last update [47c82c0...5717805](https://codecov.io/gh/knative-sandbox/kn-plugin-func/pull/749?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=knative-sandbox).


Patch:
diff --git a/.github/workflows/knative-releasability.yaml b/.github/workflows/knative-releasability.yaml
index a9a2955a..df686a89 100644
--- a/.github/workflows/knative-releasability.yaml
+++ b/.github/workflows/knative-releasability.yaml
@@ -38,9 +38,9 @@ jobs:
     env:
       #########################################
       #   Update this section each release.   #
-      RELEASE: 'v1.1'
-      MODULE_RELEASE: 'v0.28'
-      SLACK_CHANNEL: 'release-1dot1'
+      RELEASE: 'v1.2'
+      MODULE_RELEASE: 'v0.29'
+      SLACK_CHANNEL: 'release-1dot2'
       #########################################
 
     steps:
diff --git a/cmd/deploy.go b/cmd/deploy.go
index fca928b9..cdd6da2a 100644
--- a/cmd/deploy.go
+++ b/cmd/deploy.go
@@ -20,7 +20,6 @@ import (
 	"knative.dev/kn-plugin-func/docker"
 	"knative.dev/kn-plugin-func/docker/creds"
 	"knative.dev/kn-plugin-func/knative"
-	"knative.dev/kn-plugin-func/pipelines"
 	"knative.dev/kn-plugin-func/pipelines/tekton"
 	"knative.dev/kn-plugin-func/progress"
 )
@@ -37,11 +36,13 @@ func newDeployClient(cfg deployConfig) (*fn.Client, error) {
 		pusher *docker.Pusher
 		err    error
 	)
+
+	credentialsProvider := creds.NewCredentialsProvider(
+		creds.WithPromptForCredentials(newPromptForCredentials()),
+		creds.WithPromptForCredentialStore(newPromptForCredentialStore()),
+		creds.WithTransport(cfg.Transport))
+
 	if cfg.Push {
-		credentialsProvider := creds.NewCredentialsProvider(
-			creds.WithPromptForCredentials(newPromptForCredentials()),
-			creds.WithPromptForCredentialStore(newPromptForCredentialStore()),
-			creds.WithTransport(cfg.Transport))
 		pusher, err = docker.NewPusher(
 			docker.WithCredentialsProvider(credentialsProvider),
 			docker.WithProgressListener(listener),
@@ -60,7 +61,7 @@ func newDeployClient(cfg deployConfig) (*fn.Client, error) {
 	pipelinesProvider, err := tekton.NewPipelinesProvider(
 		tekton.WithNamespace(cfg.Namespace),
 		tekton.WithProgressListener(listener),
-		tekton.WithPromptForContainerRegistryCredentials(newPromptForPipelineRegistryCredentials()))
+		tekton.WithCredentialsProvider(credentialsProvider))
 	if err != nil {
 		return nil, err
 	}
@@ -287,44 +288,6 @@ func newPromptForCredentials() func(registry string) (docker.Credentials, error)
 	}
 }
 
-func newPromptForPipelineRegistryCredentials() pipelines.ContainerRegistryCredentialsCallback {
-	return func() (pipelines.ContainerRegistryCredentials, error) {
-		var result pipelines.ContainerRegistryCredentials
-		var qs = []*survey.Question{
-			{
-				Name: "server",
-				Prompt: &survey.Input{
-					Message: "Server:",
-					Default: "https://index.docker.io/v1/",
-				},
-				Validate: survey.Required,
-			},
-			{
-				Name: "username",
-				Prompt: &survey.Input{
-					Message: "Username:",
-				},
-				Validate: survey.Required,
-			},
-			{
-				Name: "password",
-				Prompt: &survey.Password{
-					Message: "Password:",
-				},
-				Validate: survey.Required,
-			},
-		}
-
-		fmt.Printf("Please provide credentials for the image registry used by Pipeline.\n")
-
-		err := survey.Ask(qs, &result)
-		if err != nil {
-			return pipelines.ContainerRegistryCredentials{}, err
-		}
-		return result, nil
-	}
-}
-
 func newPromptForCredentialStore() creds.ChooseCredentialHelperCallback {
 	return func(availableHelpers []string) (string, error) {
 		if len(availableHelpers) < 1 {
diff --git a/docker/pusher.go b/docker/pusher.go
index 5390e08a..571c4781 100644
--- a/docker/pusher.go
+++ b/docker/pusher.go
@@ -12,13 +12,11 @@ import (
 	"net/http"
 	"os"
 	"regexp"
-	"strings"
-
-	"github.com/docker/docker/client"
 
 	fn "knative.dev/kn-plugin-func"
 
 	"github.com/docker/docker/api/types"
+	"github.com/docker/docker/client"
 	"github.com/google/go-containerregistry/pkg/authn"
 	"github.com/google/go-containerregistry/pkg/name"
 	v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -111,18 +109,12 @@ func NewPusher(opts ...Opt) (*Pusher, error) {
 	return result, nil
 }
 
-func GetRegistry(image_url string) (string, error) {
-	var registry string
-	parts := strings.Split(image_url, "/")
-	switch {
-	case len(parts) == 2:
-		registry = fn.DefaultRegistry
-	case len(parts) >= 3:
-		registry = parts[0]
-	default:
-		return "", fmt.Errorf("failed to parse image name: %q", image_url)
+func GetRegistry(img string) (string, error) {
+	ref, err := name.ParseReference(img, name.WeakValidation)
+	if err != nil {
+		return "", err
 	}
-
+	registry := ref.Context().RegistryStr()
 	return registry, nil
 }
 
diff --git a/pipelines/init.go b/pipelines/init.go
new file mode 100644
index 00000000..6af4c599
--- /dev/null
+++ b/pipelines/init.go
@@ -0,0 +1,1 @@
+package pipelines
diff --git a/pipelines/registry_credentials.go b/pipelines/registry_credentials.go
deleted file mode 100644
index 95ab20da..00000000
--- a/pipelines/registry_credentials.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package pipelines
-
-type ContainerRegistryCredentialsCallback func() (ContainerRegistryCredentials, error)
-
-type ContainerRegistryCredentials struct {
-	Username string
-	Password string
-	Server   string
-}
diff --git a/pipelines/tekton/pipeplines_provider.go b/pipelines/tekton/pipeplines_provider.go
index dc472f30..1893c57d 100644
--- a/pipelines/tekton/pipeplines_provider.go
+++ b/pipelines/tekton/pipeplines_provider.go
@@ -5,6 +5,9 @@ import (
 	"fmt"
 	"sync"
 
+	"github.com/google/go-containerregistry/pkg/authn"
+	"github.com/google/go-containerregistry/pkg/name"
+
 	"github.com/tektoncd/cli/pkg/pipelinerun"
 	"github.com/tektoncd/cli/pkg/taskrun"
 	"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
@@ -14,9 +17,9 @@ import (
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 
 	fn "knative.dev/kn-plugin-func"
+	"knative.dev/kn-plugin-func/docker"
 	"knative.dev/kn-plugin-func/k8s"
 	"knative.dev/kn-plugin-func/knative"
-	"knative.dev/kn-plugin-func/pipelines"
 	"knative.dev/pkg/apis"
 )
 
@@ -25,10 +28,10 @@ type Opt func(*PipelinesProvider) error
 type PipelinesProvider struct {
 	// namespace with which to override that set on the default configuration (such as the ~/.kube/config).
 	// If left blank, pipeline creation/run will commence to the configured namespace.
-	namespace                            string
-	Verbose                              bool
-	progressListener                     fn.ProgressListener
-	containerRegistryCredentialsCallback pipelines.ContainerRegistryCredentialsCallback
+	namespace           string
+	Verbose             bool
+	progressListener    fn.ProgressListener
+	credentialsProvider docker.CredentialsProvider
 }
 
 func WithNamespace(namespace string) Opt {
@@ -49,9 +52,9 @@ func WithProgressListener(pl fn.ProgressListener) Opt {
 	}
 }
 
-func WithPromptForContainerRegistryCredentials(cbk pipelines.ContainerRegistryCredentialsCallback) Opt {
+func WithCredentialsProvider(credentialsProvider docker.CredentialsProvider) Opt {
 	return func(pp *PipelinesProvider) error {
-		pp.containerRegistryCredentialsCallback = cbk
+		pp.credentialsProvider = credentialsProvider
 		return nil
 	}
 }
@@ -97,16 +100,25 @@ func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) error {
 		}
 	}
 
+	registry, err := docker.GetRegistry(f.Image)
+	if err != nil {
+		return err
+	}
+
 	_, err = k8s.GetSecret(ctx, getPipelineSecretName(f), pp.namespace)
 	if errors.IsNotFound(err) {
 		pp.progressListener.Stopping()
-		creds, err := pp.containerRegistryCredentialsCallback()
+		creds, err := pp.credentialsProvider(ctx, registry)
 		if err != nil {
 			return err
 		}
 		pp.progressListener.Increment("Creating Pipeline resources")
 
-		err = k8s.CreateDockerRegistrySecret(ctx, getPipelineSecretName(f), pp.namespace, creds.Username, creds.Password, creds.Server)
+		if registry == name.DefaultRegistry {
+			registry = authn.DefaultAuthKey
+		}
+
+		err = k8s.CreateDockerRegistrySecret(ctx, getPipelineSecretName(f), pp.namespace, creds.Username, creds.Password, registry)
 		if err != nil {
 			return err
 		}


Test patch:
diff --git a/docker/pusher_test.go b/docker/pusher_test.go
index 6895b58f..be7f052d 100644
--- a/docker/pusher_test.go
+++ b/docker/pusher_test.go
@@ -45,18 +45,13 @@ func TestGetRegistry(t *testing.T) {
 		{
 			name: "default registry",
 			arg:  "docker.io/mysamplefunc:latest",
-			want: "docker.io",
+			want: "index.docker.io",
 		},
 		{
 			name: "long-form nested url",
 			arg:  "myregistry.io/myorg/myuser/myfunctions/mysamplefunc:latest",
 			want: "myregistry.io",
 		},
-		{
-			name: "invalid url",
-			arg:  "myregistry.io-mysamplefunc:latest",
-			want: "",
-		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {