Skip to content

Commit

Permalink
Cleanup: remove obsolete code and fix test/lint
Browse files Browse the repository at this point in the history
Signed-off-by: Shivam Mukhade <smukhade@redhat.com>
  • Loading branch information
Shivam Mukhade committed May 18, 2022
1 parent e4cf92c commit b1b785d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 196 deletions.
6 changes: 3 additions & 3 deletions config/200-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ rules:
verbs: ["get", "list", "watch"]
# Required for the reconciler/watcher
# TODO: create separate role for reconciler
- apiGroups: [ "coordination.k8s.io" ]
resources: [ "leases" ]
verbs: [ "get", "list", "create", "update", "delete", "patch", "watch" ]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand Down
49 changes: 0 additions & 49 deletions pkg/pipelineascode/pipelineascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import (
"fmt"
"path/filepath"
"sync"
"time"

apipac "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode"
"github.com/openshift-pipelines/pipelines-as-code/pkg/formatting"
"github.com/openshift-pipelines/pipelines-as-code/pkg/kubeinteraction"
"github.com/openshift-pipelines/pipelines-as-code/pkg/matcher"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
Expand All @@ -20,7 +18,6 @@ import (

const (
tektonDir = ".tekton"
maxPipelineRunStatusRun = 5
startingPipelineRunText = `Starting Pipelinerun <b>%s</b> in namespace
<b>%s</b><br><br>You can follow the execution on the [OpenShift console](%s) pipelinerun viewer or via
the command line with :
Expand Down Expand Up @@ -118,51 +115,5 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) error {
if err := p.vcx.CreateStatus(ctx, p.event, p.run.Info.Pac, status); err != nil {
return fmt.Errorf("cannot create a in_progress status on the provider platform: %w", err)
}

var duration time.Duration
if p.run.Info.Pac.DefaultPipelineRunTimeout != nil {
duration = *p.run.Info.Pac.DefaultPipelineRunTimeout
} else {
// Tekton Pipeline controller should always set this value.
duration = pr.Spec.Timeout.Duration + 1*time.Minute
}
p.logger.Infof("Waiting for PipelineRun %s/%s to Succeed in a maximum time of %s minutes",
pr.Namespace, pr.Name, formatting.HumanDuration(duration))
//if err := p.k8int.WaitForPipelineRunSucceed(ctx, p.run.Clients.Tekton.TektonV1beta1(), pr, duration); err != nil {
// // if we have a timeout from the pipeline run, we would not know it. We would need to get the PR status to know.
// // maybe something to improve in the future.
// p.run.Clients.Log.Errorf("pipelinerun %s in namespace %s has failed: %s",
// match.PipelineRun.GetGenerateName(), match.Repo.GetNamespace(), err.Error())
//}
//
//// Cleanup old succeeded pipelineruns
//if keepMaxPipeline, ok := match.Config["max-keep-runs"]; ok {
// max, err := strconv.Atoi(keepMaxPipeline)
// if err != nil {
// return err
// }
//
// err = p.k8int.CleanupPipelines(ctx, p.logger, match.Repo, pr, max)
// if err != nil {
// return err
// }
//}
//
//// remove the generated secret after completion of pipelinerun
//if p.run.Info.Pac.SecretAutoCreation {
// err = p.k8int.DeleteBasicAuthSecret(ctx, p.logger, match.Repo.GetNamespace(), gitAuthSecretName)
// if err != nil {
// return fmt.Errorf("deleting basic auth secret has failed: %w ", err)
// }
//}
//
//// Post the final status to GitHub check status with a nice breakdown and
//// tekton cli describe output.
//newPr, err := p.postFinalStatus(ctx, pr)
//if err != nil {
// return err
//}
//
//return p.updateRepoRunStatus(ctx, newPr, match.Repo)
return nil
}
68 changes: 30 additions & 38 deletions pkg/pipelineascode/pipelinesascode_github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@ func TestRun(t *testing.T) {
Number: github.Int(666),
},
},
SHA: "fromwebhook",
Organization: "organizationes",
Repository: "lagaffe",
URL: "https://service/documentation",
HeadBranch: "press",
BaseBranch: "main",
Sender: "fantasio",
EventType: "pull_request",
TriggerTarget: "pull_request",
SHA: "fromwebhook",
Organization: "organizationes",
Repository: "lagaffe",
URL: "https://service/documentation",
HeadBranch: "press",
BaseBranch: "main",
Sender: "fantasio",
EventType: "pull_request",
TriggerTarget: "pull_request",
PullRequestNumber: 666,
},
tektondir: "testdata/pull_request",
finalStatus: "neutral",
Expand All @@ -155,15 +156,16 @@ func TestRun(t *testing.T) {
Number: github.Int(666),
},
},
SHA: "fromwebhook",
Organization: "organizationes",
Repository: "lagaffe",
URL: "https://service/documentation",
HeadBranch: "press",
BaseBranch: "main",
Sender: "fantasio",
EventType: "pull_request",
TriggerTarget: "pull_request",
SHA: "fromwebhook",
Organization: "organizationes",
Repository: "lagaffe",
URL: "https://service/documentation",
HeadBranch: "press",
BaseBranch: "main",
Sender: "fantasio",
EventType: "pull_request",
TriggerTarget: "pull_request",
PullRequestNumber: 666,
},
tektondir: "testdata/pull_request",
finalStatus: "skipped",
Expand All @@ -181,15 +183,16 @@ func TestRun(t *testing.T) {
Number: github.Int(666),
},
},
SHA: "fromwebhook",
Organization: "organizationes",
Repository: "lagaffe",
URL: "https://service/documentation",
HeadBranch: "press",
BaseBranch: "main",
Sender: "fantasio",
EventType: "pull_request",
TriggerTarget: "pull_request",
SHA: "fromwebhook",
Organization: "organizationes",
Repository: "lagaffe",
URL: "https://service/documentation",
HeadBranch: "press",
BaseBranch: "main",
Sender: "fantasio",
EventType: "pull_request",
TriggerTarget: "pull_request",
PullRequestNumber: 666,
},
tektondir: "testdata/pull_request",
finalStatus: "skipped",
Expand Down Expand Up @@ -473,17 +476,6 @@ func TestRun(t *testing.T) {
logmsg := log.FilterMessageSnippet(tt.expectedLogSnippet).TakeAll()
assert.Assert(t, len(logmsg) > 0, "log messages", logmsg, tt.expectedLogSnippet)
}

if tt.finalStatus != "skipped" {
got, err := stdata.PipelineAsCode.PipelinesascodeV1alpha1().Repositories("namespace").Get(
ctx, "test-run", metav1.GetOptions{})
assert.NilError(t, err)
assert.Assert(t, got.Status[len(got.Status)-1].PipelineRunName != "pipelinerun1", "'%s'!='%s'",
got.Status[len(got.Status)-1].PipelineRunName, "pipelinerun1")

lastbranchstatus := got.Status[len(got.Status)-1].TargetBranch
assert.Assert(t, !strings.HasPrefix(*lastbranchstatus, "refs-heads-"))
}
})
}
}
2 changes: 1 addition & 1 deletion pkg/pipelineascode/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestSecretFromRepository(t *testing.T) {
},
}
event := info.NewEvent()
err := secretFromRepository(ctx, cs, k8int, tt.providerconfig, event, tt.repo, logger)
err := SecretFromRepository(ctx, cs, k8int, tt.providerconfig, event, tt.repo, logger)
assert.NilError(t, err)
logs := log.TakeAll()
assert.Equal(t, len(tt.logmatch), len(logs), "we didn't get the number of logging message: %+v", logs)
Expand Down
89 changes: 0 additions & 89 deletions pkg/pipelineascode/status.go

This file was deleted.

11 changes: 6 additions & 5 deletions pkg/provider/github/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,12 @@ func TestGithubProviderCreateStatus(t *testing.T) {
func TestGithubProvidercreateStatusCommit(t *testing.T) {
issuenumber := 666
anevent := &info.Event{
Event: &github.PullRequestEvent{PullRequest: &github.PullRequest{Number: github.Int(issuenumber)}},
Organization: "owner",
Repository: "repository",
SHA: "createStatusCommitSHA",
EventType: "pull_request",
Event: &github.PullRequestEvent{PullRequest: &github.PullRequest{Number: github.Int(issuenumber)}},
Organization: "owner",
Repository: "repository",
SHA: "createStatusCommitSHA",
EventType: "pull_request",
PullRequestNumber: issuenumber,
}
tests := []struct {
name string
Expand Down
9 changes: 3 additions & 6 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
pipelinerunreconciler "github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1beta1/pipelinerun"
v1beta12 "github.com/tektoncd/pipeline/pkg/client/listers/pipeline/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/logging"
pkgreconciler "knative.dev/pkg/reconciler"
)
Expand All @@ -31,9 +30,7 @@ type Reconciler struct {
kinteract *kubeinteraction.Interaction
}

var (
_ pipelinerunreconciler.Interface = (*Reconciler)(nil)
)
var _ pipelinerunreconciler.Interface = (*Reconciler)(nil)

var gitAuthSecretAnnotation = "pipelinesascode.tekton.dev/git-auth-secret"

Expand All @@ -55,7 +52,7 @@ func (r *Reconciler) reportStatus(ctx context.Context, pr *v1beta1.PipelineRun)
// fetch repository CR for pipelineRun
repoName := prLabels[filepath.Join(pipelinesascode.GroupName, "repository")]
repo, err := r.run.Clients.PipelineAsCode.PipelinesascodeV1alpha1().
Repositories(pr.Namespace).Get(ctx, repoName, v1.GetOptions{})
Repositories(pr.Namespace).Get(ctx, repoName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -82,7 +79,7 @@ func (r *Reconciler) reportStatus(ctx context.Context, pr *v1beta1.PipelineRun)

event := eventFromPipelineRun(pr)

// if its a GH app pipelinerun then init client
// if its a GH app pipelineRun then init client
if event.InstallationID != 0 {
gh := &github.Provider{}
event.Provider.Token, err = gh.GetAppToken(ctx, r.run.Clients.Kube, event.GHEURL, event.InstallationID)
Expand Down
5 changes: 0 additions & 5 deletions pkg/reconciler/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import (
)

const (
tektonDir = ".tekton"
maxPipelineRunStatusRun = 5
startingPipelineRunText = `Starting Pipelinerun <b>%s</b> in namespace
<b>%s</b><br><br>You can follow the execution on the [OpenShift console](%s) pipelinerun viewer or via
the command line with :
<br><code>tkn pr logs -f -n %s %s</code>`
)

func (r *Reconciler) updateRepoRunStatus(ctx context.Context, logger *zap.SugaredLogger, pr *tektonv1beta1.PipelineRun, repo *pacv1a1.Repository, event *info.Event) error {
Expand Down

0 comments on commit b1b785d

Please sign in to comment.