-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Merge place-tools and step-init together #4826
Merged
tekton-robot
merged 1 commit into
tektoncd:main
from
vdemeester:reduce-initcontainer-numbers
May 4, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: print-result | ||
spec: | ||
description: >- | ||
Prints a result from another task | ||
params: | ||
- name: TO_PRINT | ||
type: string | ||
steps: | ||
- name: print-result | ||
image: bash:latest | ||
env: | ||
- name: PARAM_TO_PRINT | ||
value: $(params.TO_PRINT) | ||
script: | | ||
#!/usr/bin/env bash | ||
set -e | ||
echo $PARAM_TO_PRINT | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: generate-result | ||
spec: | ||
description: >- | ||
Creates strings of length based on parameters and puts them into results fields | ||
params: | ||
- name: STRING_LENGTH | ||
description: Length of the string to create | ||
- name: STRING_CHAR | ||
description: Char to use when creating string | ||
type: string | ||
default: '.' | ||
results: | ||
- name: RESULT_STRING | ||
description: A result string | ||
steps: | ||
- name: gen-result | ||
image: bash:latest | ||
env: | ||
- name: PARAM_STRING_LENGTH | ||
value: $(params.STRING_LENGTH) | ||
- name: PARAM_STRING_CHAR | ||
value: $(params.STRING_CHAR) | ||
script: | | ||
#!/usr/bin/env bash | ||
set -e | ||
len=$PARAM_STRING_LENGTH | ||
ch=$PARAM_STRING_CHAR | ||
printf '%*s' "$len" | tr ' ' "$ch" >> $(results.RESULT_STRING.path) | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
name: result-test | ||
spec: | ||
description: >- | ||
Generate a result of a certain length in a task and print the result in another task | ||
params: | ||
- name: RESULT_STRING_LENGTH | ||
description: Length of string to generate for generate-result task | ||
- name: RESULT_STRING_CHAR | ||
description: Char to repeat in result string | ||
default: '.' | ||
tasks: | ||
- name: generate-result | ||
params: | ||
- name: STRING_LENGTH | ||
value: $(params.RESULT_STRING_LENGTH) | ||
- name: STRING_CHAR | ||
value: $(params.RESULT_STRING_CHAR) | ||
taskRef: | ||
kind: Task | ||
name: generate-result | ||
- name: print-result | ||
params: | ||
- name: TO_PRINT | ||
value: $(tasks.generate-result.results.RESULT_STRING) | ||
taskRef: | ||
kind: Task | ||
name: print-result | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: result-test-run | ||
spec: | ||
pipelineRef: | ||
name: result-test | ||
params: | ||
- name: RESULT_STRING_LENGTH | ||
value: "3000" |
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.
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.
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.
I'd rename this to just
initContainer
.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.
Renamed to
entrypointInitContainer
🙃