Skip to content
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

Refactor Tekton interaction in webhook interceptor #359

Merged
merged 5 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ listed in the changelog.

## [Unreleased]

### Added

- Apply labels to pipelines allowing easier identification for cleanup ([#358](https://github.com/opendevstack/ods-pipeline/issues/358))

## [0.2.0] - 2021-12-22
### Added

Expand Down
49 changes: 26 additions & 23 deletions cmd/webhook-interceptor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"time"

"github.com/opendevstack/pipeline/internal/interceptor"
tektonClient "github.com/opendevstack/pipeline/internal/tekton"
"github.com/opendevstack/pipeline/pkg/bitbucket"
)

const (
namespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
namespaceSuffix = "-cd"
apiHostEnvVar = "API_HOST"
apiHostDefault = "openshift.default.svc.cluster.local"
repoBaseEnvVar = "REPO_BASE"
tokenEnvVar = "ACCESS_TOKEN"
taskKindEnvVar = "ODS_TASK_KIND"
Expand Down Expand Up @@ -69,37 +69,40 @@ func serve() error {
)
}

apiHost := os.Getenv(apiHostEnvVar)
if len(apiHost) == 0 {
apiHost = apiHostDefault
log.Println(
"INFO:",
apiHostEnvVar,
"not set, using default value:",
apiHostDefault,
)
}

namespace, err := getFileContent(namespaceFile)
if err != nil {
return fmt.Errorf("%w", err)
return err
}

project := strings.TrimSuffix(namespace, namespaceSuffix)

client, err := interceptor.NewClient(apiHost, namespace)
// Initialize Tekton client.
client, err := tektonClient.NewInClusterClient(&tektonClient.ClientConfig{
Namespace: namespace,
})
if err != nil {
return fmt.Errorf("%w", err)
return err
}

server := interceptor.NewServer(client, interceptor.ServerConfig{
Namespace: namespace,
Project: project,
RepoBase: repoBase,
Token: token,
TaskKind: taskKind,
TaskSuffix: taskSuffix,
// Initialize Bitbucket client.
bitbucketClient := bitbucket.NewClient(&bitbucket.ClientConfig{
APIToken: token,
BaseURL: strings.TrimSuffix(repoBase, "/scm"),
})

server, err := interceptor.NewServer(interceptor.ServerConfig{
Namespace: namespace,
Project: project,
RepoBase: repoBase,
Token: token,
TaskKind: taskKind,
TaskSuffix: taskSuffix,
BitbucketClient: bitbucketClient,
TektonClient: client,
})
if err != nil {
return err
}

log.Println("Ready to accept requests")

Expand Down
9 changes: 0 additions & 9 deletions internal/interceptor/REQUIREMENTS.md

This file was deleted.

185 changes: 0 additions & 185 deletions internal/interceptor/client.go

This file was deleted.

Loading