Skip to content

Commit

Permalink
Print Build finished instead of sucessful in nop
Browse files Browse the repository at this point in the history
`nop` image/step used to be executed *only* when all the previous step
were done sucessfully. As we are not using init containers anymore,
this is not true, `nop` will always be executed even in case of
previous failure (after the others though).

Saying build successful is misleading, let's changed that to `finished`.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Apr 10, 2019
1 parent 395bc32 commit 5c04904
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 72 deletions.
2 changes: 1 addition & 1 deletion cmd/nop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ package main
import "fmt"

func main() {
fmt.Println("Build successful")
fmt.Println("Build finished")
}
137 changes: 66 additions & 71 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,75 +41,8 @@ const (
kanikoTaskName = "kanikotask"
kanikoTaskRunName = "kanikotask-run"
kanikoResourceName = "go-example-git"
kanikoBuildOutput = "Build successful"
)

func getGitResource(namespace string) *v1alpha1.PipelineResource {
return tb.PipelineResource(kanikoResourceName, namespace, tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeGit,
tb.PipelineResourceSpecParam("Url", "https://github.com/pivotal-nader-ziada/gohelloworld"),
))
}

func createSecret(c *knativetest.KubeClient, namespace string) (bool, error) {
// when running e2e in cluster, this will not be set so just hop out early
file := os.Getenv("GCP_SERVICE_ACCOUNT_KEY_PATH")
if file == "" {
return false, nil
}

sec := &corev1.Secret{}
sec.Name = "kaniko-secret"
sec.Namespace = namespace

bs, err := ioutil.ReadFile(file)
if err != nil {
return false, fmt.Errorf("couldn't read kaniko secret json: %v", err)
}

sec.Data = map[string][]byte{
"config.json": bs,
}
_, err = c.Kube.CoreV1().Secrets(namespace).Create(sec)
return true, err
}

func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
taskSpecOps := []tb.TaskSpecOp{
tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
}
stepOps := []tb.ContainerOp{
tb.Args(
"--dockerfile=/workspace/gitsource/Dockerfile",
fmt.Sprintf("--destination=%s", repo),
"--context=/workspace/gitsource",
),
}
if withSecretConfig {
stepOps = append(stepOps,
tb.VolumeMount("kaniko-secret", "/secrets"),
tb.EnvVar("GOOGLE_APPLICATION_CREDENTIALS", "/secrets/config.json"),
)
taskSpecOps = append(taskSpecOps, tb.TaskVolume("kaniko-secret", tb.VolumeSource(corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "kaniko-secret",
},
})))
}
step := tb.Step("kaniko", "gcr.io/kaniko-project/executor", stepOps...)
taskSpecOps = append(taskSpecOps, step)

return tb.Task(kanikoTaskName, namespace, tb.TaskSpec(taskSpecOps...))
}

func getTaskRun(namespace string) *v1alpha1.TaskRun {
return tb.TaskRun(kanikoTaskRunName, namespace, tb.TaskRunSpec(
tb.TaskRunTaskRef(kanikoTaskName),
tb.TaskRunTimeout(2*time.Minute),
tb.TaskRunInputs(tb.TaskRunInputsResource("gitsource", tb.TaskResourceBindingRef(kanikoResourceName))),
))
}

// TestTaskRun is an integration test that will verify a TaskRun using kaniko
func TestKanikoTaskRun(t *testing.T) {
repo := ensureDockerRepo(t)
Expand Down Expand Up @@ -162,10 +95,6 @@ func TestKanikoTaskRun(t *testing.T) {
if err != nil {
t.Fatalf("Expected to get logs from pod %s: %v", podName, err)
}
// check the logs contain our success criteria
if !strings.Contains(logs, kanikoBuildOutput) {
t.Fatalf("Expected output %s from pod %s but got %s", kanikoBuildOutput, podName, logs)
}
// make sure the pushed digest matches the one we pushed
re := regexp.MustCompile("digest: (sha256:\\w+)")
match := re.FindStringSubmatch(logs)
Expand Down Expand Up @@ -233,3 +162,69 @@ func getRemoteDigest(image string) (string, error) {
}
return digest.String(), nil
}

func getGitResource(namespace string) *v1alpha1.PipelineResource {
return tb.PipelineResource(kanikoResourceName, namespace, tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeGit,
tb.PipelineResourceSpecParam("Url", "https://github.com/pivotal-nader-ziada/gohelloworld"),
))
}

func createSecret(c *knativetest.KubeClient, namespace string) (bool, error) {
// when running e2e in cluster, this will not be set so just hop out early
file := os.Getenv("GCP_SERVICE_ACCOUNT_KEY_PATH")
if file == "" {
return false, nil
}

sec := &corev1.Secret{}
sec.Name = "kaniko-secret"
sec.Namespace = namespace

bs, err := ioutil.ReadFile(file)
if err != nil {
return false, fmt.Errorf("couldn't read kaniko secret json: %v", err)
}

sec.Data = map[string][]byte{
"config.json": bs,
}
_, err = c.Kube.CoreV1().Secrets(namespace).Create(sec)
return true, err
}

func getTask(repo, namespace string, withSecretConfig bool) *v1alpha1.Task {
taskSpecOps := []tb.TaskSpecOp{
tb.TaskInputs(tb.InputsResource("gitsource", v1alpha1.PipelineResourceTypeGit)),
}
stepOps := []tb.ContainerOp{
tb.Args(
"--dockerfile=/workspace/gitsource/Dockerfile",
fmt.Sprintf("--destination=%s", repo),
"--context=/workspace/gitsource",
),
}
if withSecretConfig {
stepOps = append(stepOps,
tb.VolumeMount("kaniko-secret", "/secrets"),
tb.EnvVar("GOOGLE_APPLICATION_CREDENTIALS", "/secrets/config.json"),
)
taskSpecOps = append(taskSpecOps, tb.TaskVolume("kaniko-secret", tb.VolumeSource(corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "kaniko-secret",
},
})))
}
step := tb.Step("kaniko", "gcr.io/kaniko-project/executor", stepOps...)
taskSpecOps = append(taskSpecOps, step)

return tb.Task(kanikoTaskName, namespace, tb.TaskSpec(taskSpecOps...))
}

func getTaskRun(namespace string) *v1alpha1.TaskRun {
return tb.TaskRun(kanikoTaskRunName, namespace, tb.TaskRunSpec(
tb.TaskRunTaskRef(kanikoTaskName),
tb.TaskRunTimeout(2*time.Minute),
tb.TaskRunInputs(tb.TaskRunInputsResource("gitsource", tb.TaskResourceBindingRef(kanikoResourceName))),
))
}

0 comments on commit 5c04904

Please sign in to comment.