GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pipelines: never upload .func to the cluster in remote builds (#3897) · knative/func@36896cb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkg/pipelines/tekton
    • pipelines_provider.go
    • pipelines_provider_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkg/pipelines/tekton/pipelines_provider.go‎

Copy file name to clipboardExpand all lines: pkg/pipelines/tekton/pipelines_provider.go
+13-7Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,17 @@ func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) (string, fn
281281

282282
// Creates tar stream with the function sources as they were in "./source" directory.
283283
func sourcesAsTarStream(f fn.Function) *io.PipeReader {
284-
ignored := func(p string) bool { return strings.HasPrefix(p, ".git") }
285-
if gi, err := gitignore.CompileIgnoreFile(filepath.Join(f.Root, ".gitignore")); err == nil {
286-
ignored = func(p string) bool {
287-
if strings.HasPrefix(p, ".git") {
288-
return true
289-
}
290-
return gi.MatchesPath(p)
284+
// Apply the same ignore policy as local builds: fn.IsIgnored always excludes
285+
// the DefaultIgnored plus the user's .funcignore patterns. This guarantees local
286+
// runtime data under .func — scaffolding (regenerated on-cluster by the
287+
// func-scaffold step)
288+
userPatterns := fn.ParseFuncIgnore(f.Root)
289+
gi, giErr := gitignore.CompileIgnoreFile(filepath.Join(f.Root, ".gitignore"))
290+
ignored := func(p string) bool {
291+
if fn.IsIgnored(p, userPatterns) {
292+
return true
291293
}
294+
return giErr == nil && gi.MatchesPath(p)
292295
}
293296

294297
pr, pw := io.Pipe()
@@ -327,6 +330,9 @@ func sourcesAsTarStream(f fn.Function) *io.PipeReader {
327330
}
328331

329332
if ignored(relp) {
333+
if fi.IsDir() {
334+
return filepath.SkipDir
335+
}
330336
return nil
331337
}
332338

Collapse file

‎pkg/pipelines/tekton/pipelines_provider_test.go‎

Copy file name to clipboardExpand all lines: pkg/pipelines/tekton/pipelines_provider_test.go
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,54 @@ func TestSourcesAsTarStream(t *testing.T) {
8181
}
8282
}
8383

84+
// TestSourcesAsTarStream_ExcludesFuncDir ensures the local runtime directory
85+
// (.func) is never uploaded to the cluster — most importantly the credential
86+
// file .func/local.yaml — even when the function has NO .gitignore. The
87+
// exclusion must come from the authoritative DefaultIgnored policy, not from a
88+
// .gitignore happening to list it. Scaffolding under .func/build is regenerated
89+
// on-cluster by the func-scaffold step, so it is not needed in the upload.
90+
func TestSourcesAsTarStream_ExcludesFuncDir(t *testing.T) {
91+
root := t.TempDir()
92+
// deliberately NO .gitignore is written
93+
mustWrite := func(rel, content string) {
94+
p := filepath.Join(root, filepath.FromSlash(rel))
95+
if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
96+
t.Fatal(err)
97+
}
98+
if err := os.WriteFile(p, []byte(content), 0600); err != nil {
99+
t.Fatal(err)
100+
}
101+
}
102+
mustWrite("app.js", "module.exports = () => {}\n") // a normal source file
103+
mustWrite(".func/local.yaml", "auth:\n- cluster-url: https://secret\n user:\n token: SECRET\n")
104+
mustWrite(".func/build/service/main.py", "# scaffolding\n")
105+
mustWrite(".func/built-image", "example.com/img@sha256:deadbeef\n")
106+
107+
rc := sourcesAsTarStream(fn.Function{Root: root})
108+
t.Cleanup(func() { _ = rc.Close() })
109+
110+
var appFound bool
111+
tr := tar.NewReader(rc)
112+
for {
113+
hdr, err := tr.Next()
114+
if err != nil {
115+
if errors.Is(err, io.EOF) {
116+
break
117+
}
118+
t.Fatal(err)
119+
}
120+
if strings.HasPrefix(hdr.Name, "source/.func") {
121+
t.Errorf(".func entry leaked into the upload stream: %q", hdr.Name)
122+
}
123+
if hdr.Name == "source/app.js" {
124+
appFound = true
125+
}
126+
}
127+
if !appFound {
128+
t.Error("the app.js source file is missing from the stream")
129+
}
130+
}
131+
84132
func Test_createPipelinePersistentVolumeClaim(t *testing.T) {
85133
type mockType func(ctx context.Context, name, namespaceOverride string, labels map[string]string, annotations map[string]string, accessMode corev1.PersistentVolumeAccessMode, resourceRequest resource.Quantity, storageClass string) (err error)
86134

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.