GeezerVison is showing github.com — pipelines: never upload .func to the cluster in direct remote deploy by gauron99 · Pull Request #3897 · knative/func
pipelines: never upload .func to the cluster in direct remote deploy
#3897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.go
(2)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -281,14 +281,17 @@ func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) (string, fn
// Creates tar stream with the function sources as they were in "./source" directory.
func sourcesAsTarStream(f fn.Function) *io.PipeReader {
ignored := func(p string) bool { return strings.HasPrefix(p, ".git") }
if gi, err := gitignore.CompileIgnoreFile(filepath.Join(f.Root, ".gitignore")); err == nil {
ignored = func(p string) bool {
if strings.HasPrefix(p, ".git") {
return true
}
return gi.MatchesPath(p)
// Apply the same ignore policy as local builds: fn.IsIgnored always excludes
// the DefaultIgnored plus the user's .funcignore patterns. This guarantees local
// runtime data under .func — scaffolding (regenerated on-cluster by the
// func-scaffold step)
userPatterns := fn.ParseFuncIgnore(f.Root)
gi, giErr := gitignore.CompileIgnoreFile(filepath.Join(f.Root, ".gitignore"))
ignored := func(p string) bool {
if fn.IsIgnored(p, userPatterns) {
Comment thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
nit
You can inline userPatterns here, it's not called anywhere else:
if fn .IsIgnored (p , fn .ParseFuncIgnore (f .Root )) {
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
that would actually re-read .funcignore file every ignored function call inside the Walk below. Its extracted so that read is only fired once
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
return true
}
return giErr == nil && gi.MatchesPath(p)
}
pr, pw := io.Pipe()
Expand Down
Expand Up
@@ -327,6 +330,9 @@ func sourcesAsTarStream(f fn.Function) *io.PipeReader {
}
if ignored(relp) {
if fi.IsDir() {
return filepath.SkipDir
}
return nil
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -81,6 +81,54 @@ func TestSourcesAsTarStream(t *testing.T) {
}
}
// TestSourcesAsTarStream_ExcludesFuncDir ensures the local runtime directory
// (.func) is never uploaded to the cluster — most importantly the credential
// file .func/local.yaml — even when the function has NO .gitignore. The
// exclusion must come from the authoritative DefaultIgnored policy, not from a
// .gitignore happening to list it. Scaffolding under .func/build is regenerated
// on-cluster by the func-scaffold step, so it is not needed in the upload.
func TestSourcesAsTarStream_ExcludesFuncDir(t *testing.T) {
root := t.TempDir()
// deliberately NO .gitignore is written
mustWrite := func(rel, content string) {
p := filepath.Join(root, filepath.FromSlash(rel))
if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(p, []byte(content), 0600); err != nil {
t.Fatal(err)
}
}
mustWrite("app.js", "module.exports = () => {}\n") // a normal source file
mustWrite(".func/local.yaml", "auth:\n- cluster-url: https://secret\n user:\n token: SECRET\n")
mustWrite(".func/build/service/main.py", "# scaffolding\n")
mustWrite(".func/built-image", "example.com/img@sha256:deadbeef\n")
rc := sourcesAsTarStream(fn.Function{Root: root})
t.Cleanup(func() { _ = rc.Close() })
var appFound bool
tr := tar.NewReader(rc)
for {
hdr, err := tr.Next()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
t.Fatal(err)
}
if strings.HasPrefix(hdr.Name, "source/.func") {
t.Errorf(".func entry leaked into the upload stream: %q", hdr.Name)
}
if hdr.Name == "source/app.js" {
appFound = true
}
}
if !appFound {
t.Error("the app.js source file is missing from the stream")
}
}
func Test_createPipelinePersistentVolumeClaim(t *testing.T) {
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)
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.