-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge place-tools and step-init together
This is part of an effort to reduce the number of init container to the minimum. Both place-tools and step-init are using the same image and can be easily and safely merged together. This has few benefits, but the main one is that it reduces the number of container to run, and thus doesn't reduce the max size of a Result. Signed-off-by: Andrew Bayer <[email protected]> Signed-off-by: Vincent Demeester <[email protected]>
- Loading branch information
1 parent
2ffa9a5
commit 2b67426
Showing
7 changed files
with
234 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package subcommands | ||
|
||
// InitCommand is the name of main initialization command | ||
const InitCommand = "init" | ||
|
||
// init copies the entrypoint to the right place and sets up /tekton/steps directory for the pod. | ||
// This expects the list of steps (in order matching the Task spec). | ||
func entrypointInit(src, dst string, steps []string) error { | ||
if err := cp(src, dst); err != nil { | ||
return err | ||
} | ||
return stepInit(steps) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package subcommands | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestEntrypointInit(t *testing.T) { | ||
tmp := t.TempDir() | ||
src := filepath.Join(tmp, "foo.txt") | ||
dst := filepath.Join(tmp, "bar.txt") | ||
if err := ioutil.WriteFile(src, []byte("hello world"), 0700); err != nil { | ||
t.Fatalf("error writing source file: %v", err) | ||
} | ||
|
||
// Override tektonRoot for testing. | ||
tektonRoot = tmp | ||
|
||
// Create step directory so that symlinks can be successfully created. | ||
// This is typically done by volume mounts, so it needs to be done manually | ||
// in tests. | ||
stepDir := filepath.Join(tmp, "steps") | ||
if err := os.Mkdir(stepDir, os.ModePerm); err != nil { | ||
t.Fatalf("error creating step directory: %v", err) | ||
} | ||
|
||
steps := []string{"a", "b"} | ||
if err := entrypointInit(src, dst, steps); err != nil { | ||
t.Fatalf("stepInit: %v", err) | ||
} | ||
|
||
info, err := os.Lstat(dst) | ||
if err != nil { | ||
t.Fatalf("error statting destination file: %v", err) | ||
} | ||
|
||
// os.OpenFile is subject to umasks, so the created permissions of the | ||
// created dst file might be more restrictive than dstPermissions. | ||
// excludePerm represents the value of permissions we do not want in the | ||
// resulting file - e.g. if dstPermissions is 0311, excludePerm should be | ||
// 0466. | ||
// This is done instead of trying to look up the system umask, since this | ||
// relies on syscalls that we are not sure will be portable across | ||
// environments. | ||
excludePerm := os.ModePerm ^ dstPermissions | ||
if p := info.Mode().Perm(); p&excludePerm != 0 { | ||
t.Errorf("expected permissions <= %#o for destination file but found %#o", dstPermissions, p) | ||
} | ||
|
||
// Map of symlinks to expected /tekton/run folders. | ||
// Expected format: | ||
// Key: /tekton/steps/<key> | ||
// Value: /tekton/run/<value>/status | ||
wantLinks := map[string]string{ | ||
"a": "0", | ||
"0": "0", | ||
"b": "1", | ||
"1": "1", | ||
} | ||
|
||
direntry, err := os.ReadDir(stepDir) | ||
if err != nil { | ||
t.Fatalf("os.ReadDir: %v", err) | ||
} | ||
for _, de := range direntry { | ||
t.Run(de.Name(), func(t *testing.T) { | ||
l, err := os.Readlink(filepath.Join(stepDir, de.Name())) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
want, ok := wantLinks[de.Name()] | ||
if !ok { | ||
t.Fatalf("unexpected symlink: %s", de.Name()) | ||
} | ||
if wantDir := filepath.Join(tmp, "run", want, "status"); l != wantDir { | ||
t.Errorf("want %s, got %s", wantDir, l) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.