Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from gitops-tools/bump-tekton-dependencies
Browse files Browse the repository at this point in the history
Bump to newest version of tektoncd/pipeline.
  • Loading branch information
bigkevmcd authored Dec 8, 2020
2 parents b90df42 + f407ece commit ffb214a
Show file tree
Hide file tree
Showing 19 changed files with 852 additions and 191 deletions.
36 changes: 18 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ go 1.14

require (
github.com/google/cel-go v0.5.1
github.com/google/go-cmp v0.5.0
github.com/jenkins-x/go-scm v1.5.146
github.com/prometheus/client_golang v1.5.0
github.com/spf13/cobra v0.0.6
github.com/spf13/viper v1.6.2
github.com/tektoncd/pipeline v0.14.1
github.com/google/go-cmp v0.5.2
github.com/jenkins-x/go-scm v1.5.196
github.com/prometheus/client_golang v1.6.0
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.0
github.com/tektoncd/pipeline v0.18.1
go.uber.org/zap v1.15.0
k8s.io/api v0.17.6
k8s.io/apimachinery v0.17.6
k8s.io/api v0.18.8
k8s.io/apimachinery v0.19.0
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
knative.dev/pkg v0.0.0-20200528142800-1c6815d7e4c9
knative.dev/pkg v0.0.0-20200922164940-4bf40ad82aab
sigs.k8s.io/yaml v1.2.0
)

// Knative deps (release-0.15)
// Knative deps (release-0.18)
replace (
contrib.go.opencensus.io/exporter/stackdriver => contrib.go.opencensus.io/exporter/stackdriver v0.12.9-0.20191108183826-59d068f8d8ff
github.com/Azure/azure-sdk-for-go => github.com/Azure/azure-sdk-for-go v38.2.0+incompatible
github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.4.0+incompatible
knative.dev/caching => knative.dev/caching v0.0.0-20200521155757-e78d17bc250e
knative.dev/pkg => knative.dev/pkg v0.0.0-20200528142800-1c6815d7e4c9
)

// Pin k8s deps to 1.16.5
// Pin k8s deps to v0.18.8
replace (
k8s.io/api => k8s.io/api v0.16.5
k8s.io/apimachinery => k8s.io/apimachinery v0.16.5
k8s.io/client-go => k8s.io/client-go v0.16.5
k8s.io/code-generator => k8s.io/code-generator v0.16.5
k8s.io/gengo => k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a
k8s.io/api => k8s.io/api v0.18.8
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.8
k8s.io/apimachinery => k8s.io/apimachinery v0.18.8
k8s.io/apiserver => k8s.io/apiserver v0.18.8
k8s.io/client-go => k8s.io/client-go v0.18.8
k8s.io/code-generator => k8s.io/code-generator v0.18.8
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29
)
713 changes: 660 additions & 53 deletions go.sum

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions pkg/dsl/dsl_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jenkins-x/go-scm/scm"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/gitops-tools/tekton-ci/pkg/cel"
"github.com/gitops-tools/tekton-ci/pkg/ci"
Expand Down Expand Up @@ -76,7 +77,12 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// NewDSLConverter creates and returns a converter.
func NewDSLConverter(scmClient git.SCM, pipelineClient pipelineclientset.Interface, volumeCreator volumes.Creator, m metrics.Interface, cfg *Configuration, namespace string, l logger.Logger) *DSLConverter {
func NewDSLConverter(
scmClient git.SCM,
pipelineClient pipelineclientset.Interface,
volumeCreator volumes.Creator,
m metrics.Interface, cfg *Configuration,
namespace string, l logger.Logger) *DSLConverter {
return &DSLConverter{
pipelineClient: pipelineClient,
volumeCreator: volumeCreator,
Expand Down Expand Up @@ -129,7 +135,7 @@ func (d *DSLConverter) convert(ctx context.Context, evt *scm.PushHook) (*pipelin
return nil, nil
}

vc, err := d.volumeCreator.Create(d.namespace, d.config.VolumeSize)
vc, err := d.volumeCreator.Create(ctx, d.namespace, d.config.VolumeSize)
if err != nil {
d.log.Errorf("error creating volume: %s", err)
return nil, nil
Expand All @@ -142,7 +148,7 @@ func (d *DSLConverter) convert(ctx context.Context, evt *scm.PushHook) (*pipelin
if pr == nil {
return nil, nil
}
created, err := d.pipelineClient.TektonV1beta1().PipelineRuns(d.namespace).Create(pr)
created, err := d.pipelineClient.TektonV1beta1().PipelineRuns(d.namespace).Create(ctx, pr, metav1.CreateOptions{})
if err != nil {
d.log.Errorf("error creating pipelinerun file: %s", err)
return nil, nil
Expand Down
12 changes: 7 additions & 5 deletions pkg/dsl/dsl_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dsl

import (
"context"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -51,7 +52,7 @@ func TestHandlePushEvent(t *testing.T) {
if w.StatusCode != http.StatusOK {
t.Fatalf("got %d, want %d: %s", w.StatusCode, http.StatusNotFound, mustReadBody(t, w))
}
claim, err := fakeClient.CoreV1().PersistentVolumeClaims(testNS).Get("", metav1.GetOptions{})
claim, err := fakeClient.CoreV1().PersistentVolumeClaims(testNS).Get(context.TODO(), "", metav1.GetOptions{})
if err != nil {
t.Fatal(err)
}
Expand All @@ -77,7 +78,8 @@ func TestHandlePushEvent(t *testing.T) {
if diff := cmp.Diff(wantClaim, claim, cmpopts.IgnoreFields(corev1.PersistentVolumeClaim{}, "TypeMeta")); diff != "" {
t.Fatalf("persistent volume claim incorrect, diff\n%s", diff)
}
pr, err := fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get("", metav1.GetOptions{})
pr, err := fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get(
context.TODO(), "", metav1.GetOptions{})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -125,7 +127,7 @@ func TestHandlePushEventNoPipeline(t *testing.T) {
if w.StatusCode != http.StatusOK {
t.Fatalf("got %d, want %d: %s", w.StatusCode, http.StatusOK, mustReadBody(t, w))
}
_, err = fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get("", metav1.GetOptions{})
_, err = fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get(context.TODO(), "", metav1.GetOptions{})
if !errors.IsNotFound(err) {
t.Fatal("pipelinerun was created when no pipeline definition exists")
}
Expand Down Expand Up @@ -154,7 +156,7 @@ func TestHandlePushEventNoMatchingRules(t *testing.T) {
if w.StatusCode != http.StatusOK {
t.Fatalf("got %d, want %d: %s", w.StatusCode, http.StatusOK, mustReadBody(t, w))
}
_, err = fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get("", metav1.GetOptions{})
_, err = fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get(context.TODO(), "", metav1.GetOptions{})
if !errors.IsNotFound(err) {
t.Fatal("pipelinerun was created with no matching rules")
}
Expand Down Expand Up @@ -185,7 +187,7 @@ func TestHandlePushEventWithSkippableMessage(t *testing.T) {
if w.StatusCode != http.StatusOK {
t.Fatalf("got %d, want %d: %s", w.StatusCode, http.StatusOK, mustReadBody(t, w))
}
_, err = fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get("", metav1.GetOptions{})
_, err = fakeTektonClient.TektonV1beta1().PipelineRuns(testNS).Get(context.TODO(), "", metav1.GetOptions{})
if !errors.IsNotFound(err) {
t.Fatalf("pipelinerun was created when the message indicated a skip")
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/dsl/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,16 @@ func workspacePipelineTaskBindings() []pipelinev1.WorkspacePipelineTaskBinding {
}
}

func makeTaskSpec(steps ...pipelinev1.Step) *pipelinev1.TaskSpec {
return &pipelinev1.TaskSpec{
Workspaces: []pipelinev1.WorkspaceDeclaration{
{
Name: workspaceBindingName,
func makeTaskSpec(steps ...pipelinev1.Step) *pipelinev1.EmbeddedTask {
return &pipelinev1.EmbeddedTask{
TaskSpec: pipelinev1.TaskSpec{
Workspaces: []pipelinev1.WorkspaceDeclaration{
{
Name: workspaceBindingName,
},
},
Steps: steps,
},
Steps: steps,
}
}

Expand Down
152 changes: 81 additions & 71 deletions pkg/dsl/scripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,28 @@ func TestMakeGitCloneTask(t *testing.T) {
Workspaces: []pipelinev1.WorkspacePipelineTaskBinding{
{Name: "source", Workspace: workspaceName},
},
TaskSpec: &pipelinev1.TaskSpec{
Workspaces: []pipelinev1.WorkspaceDeclaration{
{
Name: "source",
TaskSpec: &pipelinev1.EmbeddedTask{
TaskSpec: pipelinev1.TaskSpec{
Workspaces: []pipelinev1.WorkspaceDeclaration{
{
Name: "source",
},
},
},
Steps: []pipelinev1.Step{
{
Container: corev1.Container{
Name: "git-clone",
Image: "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init",
Command: []string{"/ko-app/git-init", "-url", testRepoURL, "-revision", "master", "-path", workspaceSourcePath},
Env: []corev1.EnvVar{
{
Name: "CI_PROJECT_DIR",
Value: "$(workspaces.source.path)",
},
{
Name: "TEKTON_RESOURCE_NAME",
Value: "tekton-ci-git-clone",
Steps: []pipelinev1.Step{
{
Container: corev1.Container{
Name: "git-clone",
Image: "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init",
Command: []string{"/ko-app/git-init", "-url", testRepoURL, "-revision", "master", "-path", workspaceSourcePath},
Env: []corev1.EnvVar{
{
Name: "CI_PROJECT_DIR",
Value: "$(workspaces.source.path)",
},
{
Name: "TEKTON_RESOURCE_NAME",
Value: "tekton-ci-git-clone",
},
},
},
},
Expand Down Expand Up @@ -91,21 +93,23 @@ func TestMakeScriptTask(t *testing.T) {
Workspaces: []pipelinev1.WorkspacePipelineTaskBinding{
{Name: "source", Workspace: workspaceName},
},
TaskSpec: &pipelinev1.TaskSpec{
Workspaces: []pipelinev1.WorkspaceDeclaration{
{
Name: "source",
},
},
Steps: []pipelinev1.Step{
{
Container: container("", "golang:latest", "sh", []string{"-c", "mkdir -p $GOPATH/src/$(dirname $REPO_NAME)"}, env, workspaceSourcePath),
},
{
Container: container("", "golang:latest", "sh", []string{"-c", "ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME"}, env, workspaceSourcePath),
TaskSpec: &pipelinev1.EmbeddedTask{
TaskSpec: pipelinev1.TaskSpec{
Workspaces: []pipelinev1.WorkspaceDeclaration{
{
Name: "source",
},
},
{
Container: container("", "golang:latest", "sh", []string{"-c", "cd $GOPATH/src/$REPO_NAME"}, env, workspaceSourcePath),
Steps: []pipelinev1.Step{
{
Container: container("", "golang:latest", "sh", []string{"-c", "mkdir -p $GOPATH/src/$(dirname $REPO_NAME)"}, env, workspaceSourcePath),
},
{
Container: container("", "golang:latest", "sh", []string{"-c", "ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME"}, env, workspaceSourcePath),
},
{
Container: container("", "golang:latest", "sh", []string{"-c", "cd $GOPATH/src/$REPO_NAME"}, env, workspaceSourcePath),
},
},
},
},
Expand Down Expand Up @@ -182,50 +186,54 @@ func TestConvert(t *testing.T) {
makeScriptTask(beforeStepTaskName, []string{gitCloneTaskName}, testEnv, p.Image, p.BeforeScript),
{
Name: "format-stage-test",
TaskSpec: &pipelinev1.TaskSpec{
Steps: []pipelinev1.Step{
{
Container: corev1.Container{
Image: "golang:latest",
Command: []string{"sh"},
Args: []string{"-c", "go fmt $(go list ./... | grep -v /vendor/)"},
WorkingDir: "$(workspaces.source.path)",
Env: testEnv,
TaskSpec: &pipelinev1.EmbeddedTask{
TaskSpec: pipelinev1.TaskSpec{
Steps: []pipelinev1.Step{
{
Container: corev1.Container{
Image: "golang:latest",
Command: []string{"sh"},
Args: []string{"-c", "go fmt $(go list ./... | grep -v /vendor/)"},
WorkingDir: "$(workspaces.source.path)",
Env: testEnv,
},
},
},
{
Container: corev1.Container{
Image: "golang:latest",
Command: []string{"sh"},
Args: []string{"-c", "go vet $(go list ./... | grep -v /vendor/)"},
WorkingDir: "$(workspaces.source.path)",
Env: testEnv,
{
Container: corev1.Container{
Image: "golang:latest",
Command: []string{"sh"},
Args: []string{"-c", "go vet $(go list ./... | grep -v /vendor/)"},
WorkingDir: "$(workspaces.source.path)",
Env: testEnv,
},
},
},
{
Container: corev1.Container{
Image: "golang:latest",
Command: []string{"sh"},
Args: []string{"-c", "go test -race $(go list ./... | grep -v /vendor/)"},
WorkingDir: "$(workspaces.source.path)",
Env: testEnv,
{
Container: corev1.Container{
Image: "golang:latest",
Command: []string{"sh"},
Args: []string{"-c", "go test -race $(go list ./... | grep -v /vendor/)"},
WorkingDir: "$(workspaces.source.path)",
Env: testEnv,
},
},
},
Workspaces: []pipelinev1.WorkspaceDeclaration{{Name: "source"}},
},
Workspaces: []pipelinev1.WorkspaceDeclaration{{Name: "source"}},
},
RunAfter: []string{beforeStepTaskName},
Workspaces: []pipelinev1.WorkspacePipelineTaskBinding{{Name: "source", Workspace: "git-checkout"}},
},
{
Name: "compile-stage-build",
TaskSpec: &pipelinev1.TaskSpec{
Steps: []pipelinev1.Step{
{
Container: container("", "test-compile-image", "sh", []string{"-c", `go build -race -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/mybinary`}, testEnv, workspaceSourcePath),
TaskSpec: &pipelinev1.EmbeddedTask{
TaskSpec: pipelinev1.TaskSpec{
Steps: []pipelinev1.Step{
{
Container: container("", "test-compile-image", "sh", []string{"-c", `go build -race -ldflags "-extldflags '-static'" -o $CI_PROJECT_DIR/mybinary`}, testEnv, workspaceSourcePath),
},
},
Workspaces: []pipelinev1.WorkspaceDeclaration{{Name: "source"}},
},
Workspaces: []pipelinev1.WorkspaceDeclaration{{Name: "source"}},
},
RunAfter: []string{"format-stage-test"},
Workspaces: []pipelinev1.WorkspacePipelineTaskBinding{{Name: "source", Workspace: "git-checkout"}},
Expand All @@ -234,15 +242,17 @@ func TestConvert(t *testing.T) {
Name: "compile-archiver",
RunAfter: []string{"format-stage-test"},
Workspaces: []pipelinev1.WorkspacePipelineTaskBinding{{Name: "source", Workspace: "git-checkout"}},
TaskSpec: &pipelinev1.TaskSpec{
Steps: []pipelinev1.Step{
{
Container: container("compile-archiver-archiver", testArchiverImage, "",
[]string{"archive", "--bucket-url",
testArchiveURL, "my-test-binary"}, testEnv, workspaceSourcePath),
TaskSpec: &pipelinev1.EmbeddedTask{
TaskSpec: pipelinev1.TaskSpec{
Steps: []pipelinev1.Step{
{
Container: container("compile-archiver-archiver", testArchiverImage, "",
[]string{"archive", "--bucket-url",
testArchiveURL, "my-test-binary"}, testEnv, workspaceSourcePath),
},
},
Workspaces: []pipelinev1.WorkspaceDeclaration{{Name: "source"}},
},
Workspaces: []pipelinev1.WorkspaceDeclaration{{Name: "source"}},
},
},
makeScriptTask(afterStepTaskName, []string{"compile-archiver"}, testEnv, p.Image, p.AfterScript),
Expand Down
4 changes: 3 additions & 1 deletion pkg/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ type SCMClient struct {
// ParseWebhookRequest parses an incoming hook request and returns a parsed
// hook response if one can be matched.
func (c *SCMClient) ParseWebhookRequest(req *http.Request) (scm.Webhook, error) {
hook, err := c.client.Webhooks.Parse(req, c.secrets.Secret)
hook, err := c.client.Webhooks.Parse(req, func(hook scm.Webhook) (string, error) {
return c.secrets.Secret(req.Context(), hook)
})
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/secrets/interface.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package secrets

import (
"context"

"github.com/jenkins-x/go-scm/scm"
)

// SecretGetter is provided by values that implement Secret, to look up the
// correct secret for a Webhook in order to validate the origin of the Webhook.
type SecretGetter interface {
Secret(hook scm.Webhook) (string, error)
Secret(ctx context.Context, hook scm.Webhook) (string, error)
}
Loading

0 comments on commit ffb214a

Please sign in to comment.