From e2db4799f82aeffb19e9a509fe148c2cb32e08a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Va=C5=A1ek?= Date: Tue, 2 Sep 2025 22:42:39 +0200 Subject: [PATCH] Update func plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Incorporate fix for newer Tekton. Signed-off-by: Matej VaĊĦek --- go.mod | 2 +- go.sum | 4 +- .../func/pkg/pipelines/tekton/tasks.go | 51 +++++++++++++++++++ .../func/pkg/pipelines/tekton/templates.go | 40 ++++++++++----- .../pkg/pipelines/tekton/templates_pack.go | 1 + .../pkg/pipelines/tekton/templates_s2i.go | 1 + vendor/modules.txt | 4 +- 7 files changed, 84 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 44f1dbb063..6575b9cad5 100644 --- a/go.mod +++ b/go.mod @@ -290,6 +290,6 @@ require ( replace ( k8s.io/client-go => k8s.io/client-go v0.30.10 - knative.dev/func => github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250820114648-23f4490237ad + knative.dev/func => github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250902202941-96eed712cf14 knative.dev/kn-plugin-event => github.com/openshift-knative/kn-plugin-event v0.43.1-0.20250505073738-1d80299d87eb ) diff --git a/go.sum b/go.sum index 95e905cb04..aa19637e5a 100644 --- a/go.sum +++ b/go.sum @@ -1497,8 +1497,8 @@ github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaL github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec= github.com/openshift-knative/kn-plugin-event v0.43.1-0.20250505073738-1d80299d87eb h1:pnk1Mw27NO/gntKymU4DDaRRbrGMY1a9Wu8hI2d/CK8= github.com/openshift-knative/kn-plugin-event v0.43.1-0.20250505073738-1d80299d87eb/go.mod h1:AB3tJ9HfekmLRSMPgcevg5oxO6WwKVrYqchBajXZ1xc= -github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250820114648-23f4490237ad h1:R727qHXX54tR4ALaJfEMRxn8xleX6B3XL6a9ELg5NuU= -github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250820114648-23f4490237ad/go.mod h1:9FVSpi1LvVlZ/JoNf5Z+sBCgLObzkVIHHvx9fSo5/mA= +github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250902202941-96eed712cf14 h1:X8Xv+QSU3k2glAznik2h2GiJFXIsGSARmpq9wnFGALY= +github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250902202941-96eed712cf14/go.mod h1:9FVSpi1LvVlZ/JoNf5Z+sBCgLObzkVIHHvx9fSo5/mA= github.com/openshift-pipelines/pipelines-as-code v0.27.0 h1:uxpva7/Ad/QEvc40BCBFEWrmYlAjCZ9dZCFYPYWW61c= github.com/openshift-pipelines/pipelines-as-code v0.27.0/go.mod h1:rzfXtaqbUrsAock3f948p9ekXWc3DFFk9acz5BsEwA4= github.com/openshift/source-to-image v1.4.1-0.20240605122348-f94ff357628b h1:FGmtvZdOUj8+oEmL773UwU348D1mx42KHSqFoEAXwtw= diff --git a/vendor/knative.dev/func/pkg/pipelines/tekton/tasks.go b/vendor/knative.dev/func/pkg/pipelines/tekton/tasks.go index 4d4ec76b92..dfa4efbc18 100644 --- a/vendor/knative.dev/func/pkg/pipelines/tekton/tasks.go +++ b/vendor/knative.dev/func/pkg/pipelines/tekton/tasks.go @@ -1,8 +1,14 @@ package tekton import ( + "context" "fmt" "strings" + + "gopkg.in/yaml.v3" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/func/pkg/k8s" ) var DeployerImage = "ghcr.io/knative/func-utils:latest" @@ -454,6 +460,51 @@ spec: `, DeployerImage) } +func getGitCloneTask() (string, error) { + c, err := k8s.NewDynamicClient() + if err != nil { + return "", fmt.Errorf("cannot create k8s client: %v", err) + } + taskGVR := schema.GroupVersionResource{ + Group: "tekton.dev", + Version: "v1", + Resource: "tasks", + } + o, err := c.Resource(taskGVR).Namespace("openshift-pipelines").Get(context.Background(), "git-clone", metav1.GetOptions{}) + if err != nil { + return "", fmt.Errorf("cannot get git-clone task: %v", err) + } + + /* BEGIN fixup workspaces */ + spec := o.Object["spec"].(map[string]any) + workspaces := spec["workspaces"].([]any) + type ws struct { + Name string + Optional bool + } + spec["workspaces"] = append(workspaces, + ws{Name: "dockerconfig", Optional: true}, + ws{Name: "cache", Optional: true}, + ) + /* END fixup workspaces */ + + /* BEGIN delete unnecessary fields */ + delete(o.Object["metadata"].(map[string]any), "managedFields") + stepTemplate := spec["stepTemplate"].(map[string]any) + delete(stepTemplate, "computeResources") + steps := spec["steps"].([]any) + for idx := range steps { + delete(steps[idx].(map[string]any), "computeResources") + } + /* END delete unnecessary fields */ + + bs, err := yaml.Marshal(o.Object) + if err != nil { + return "", fmt.Errorf("cannot marshal object to yaml: %v", err) + } + return string(bs), nil +} + // GetClusterTasks returns multi-document yaml containing tekton tasks used by func. func GetClusterTasks() string { tasks := getBuildpackTask() + "\n---\n" + getS2ITask() + "\n---\n" + getDeployTask() + "\n---\n" + getScaffoldTask() diff --git a/vendor/knative.dev/func/pkg/pipelines/tekton/templates.go b/vendor/knative.dev/func/pkg/pipelines/tekton/templates.go index 2471243ae1..db74f89aeb 100644 --- a/vendor/knative.dev/func/pkg/pipelines/tekton/templates.go +++ b/vendor/knative.dev/func/pkg/pipelines/tekton/templates.go @@ -41,26 +41,26 @@ const ( name: git-clone workspaces: - name: output - workspace: source-workspace` - // TODO fix Tekton Hub reference + workspace: source-workspace + - name: cache + workspace: cache-workspace + - name: dockerconfig + workspace: dockerconfig-workspace` + taskGitCloneTaskRef = `- name: fetch-sources params: - - name: url + - name: URL value: $(params.gitRepository) - - name: revision + - name: REVISION value: $(params.gitRevision) - taskRef: - resolver: hub - params: - - name: kind - value: task - - name: name - value: git-clone - - name: version - value: "0.4" workspaces: - name: output - workspace: source-workspace` + workspace: source-workspace + - name: cache + workspace: cache-workspace + - name: dockerconfig + workspace: dockerconfig-workspace` + runAfterFetchSourcesRef = `runAfter: - fetch-sources` @@ -96,6 +96,7 @@ type templateData struct { // Task references GitCloneTaskRef string + GitCloneTaskSpec string FuncBuildpacksTaskRef string FuncS2iTaskRef string FuncDeployTaskRef string @@ -307,10 +308,20 @@ func createAndApplyPipelineTemplate(f fn.Function, namespace string, labels map[ // If Git is set up create fetch task and reference it from build task, // otherwise sources have been already uploaded to workspace PVC. gitCloneTaskRef := "" + gitCloneTaskSpec := "" runAfterFetchSources := "" if f.Build.Git.URL != "" { runAfterFetchSources = runAfterFetchSourcesRef gitCloneTaskRef = taskGitCloneTaskRef + gct, err := getGitCloneTask() + if err != nil { + return fmt.Errorf("error getting git clone task: %v", err) + } + ts, err := getTaskSpec(gct) + if err != nil { + return err + } + gitCloneTaskSpec = ts } data := templateData{ @@ -320,6 +331,7 @@ func createAndApplyPipelineTemplate(f fn.Function, namespace string, labels map[ PipelineName: getPipelineName(f), RunAfterFetchSources: runAfterFetchSources, GitCloneTaskRef: gitCloneTaskRef, + GitCloneTaskSpec: gitCloneTaskSpec, } for _, val := range []struct { diff --git a/vendor/knative.dev/func/pkg/pipelines/tekton/templates_pack.go b/vendor/knative.dev/func/pkg/pipelines/tekton/templates_pack.go index f38c39d36f..d0c0296950 100644 --- a/vendor/knative.dev/func/pkg/pipelines/tekton/templates_pack.go +++ b/vendor/knative.dev/func/pkg/pipelines/tekton/templates_pack.go @@ -42,6 +42,7 @@ spec: type: array tasks: {{.GitCloneTaskRef}} + {{.GitCloneTaskSpec}} - name: scaffold params: - name: path diff --git a/vendor/knative.dev/func/pkg/pipelines/tekton/templates_s2i.go b/vendor/knative.dev/func/pkg/pipelines/tekton/templates_s2i.go index 2c4c53a6f0..55960c9bb9 100644 --- a/vendor/knative.dev/func/pkg/pipelines/tekton/templates_s2i.go +++ b/vendor/knative.dev/func/pkg/pipelines/tekton/templates_s2i.go @@ -46,6 +46,7 @@ spec: default: 'image:///usr/libexec/s2i' tasks: {{.GitCloneTaskRef}} + {{.GitCloneTaskSpec}} - name: scaffold params: - name: path diff --git a/vendor/modules.txt b/vendor/modules.txt index 73f089ea43..c758309139 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2174,7 +2174,7 @@ knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1 knative.dev/eventing-kafka-broker/control-plane/pkg/client/clientset/versioned/scheme knative.dev/eventing-kafka-broker/control-plane/pkg/client/clientset/versioned/typed/sources/v1beta1 knative.dev/eventing-kafka-broker/control-plane/pkg/client/clientset/versioned/typed/sources/v1beta1/fake -# knative.dev/func v0.43.2 => github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250820114648-23f4490237ad +# knative.dev/func v0.43.2 => github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250902202941-96eed712cf14 ## explicit; go 1.23.0 knative.dev/func/cmd knative.dev/func/cmd/prompt @@ -2433,5 +2433,5 @@ sigs.k8s.io/structured-merge-diff/v4/value sigs.k8s.io/yaml sigs.k8s.io/yaml/goyaml.v2 # k8s.io/client-go => k8s.io/client-go v0.30.10 -# knative.dev/func => github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250820114648-23f4490237ad +# knative.dev/func => github.com/openshift-knative/kn-plugin-func v1.1.3-0.20250902202941-96eed712cf14 # knative.dev/kn-plugin-event => github.com/openshift-knative/kn-plugin-event v0.43.1-0.20250505073738-1d80299d87eb