Skip to content

Commit

Permalink
Fixes pacopts pointer usage in reconciler
Browse files Browse the repository at this point in the history
this updates reconciler to use same pacopts across the whole reconcilation
  • Loading branch information
sm43 authored and chmouel committed Apr 9, 2024
1 parent 6a90a1b commit b69cf31
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions cmd/pipelines-as-code-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func main() {
ctx := signals.NewContext()
ns := system.Namespace()
run := params.New()
run.Info.InitInfo()
rinfo := &run.Info
rinfo.Controller = info.GetControllerInfoFromEnvOrDefault()
err := run.Clients.NewClients(ctx, rinfo)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.uber.org/zap"
)

func (r *Reconciler) cleanupPipelineRuns(ctx context.Context, logger *zap.SugaredLogger, pacInfo info.PacOpts, repo *v1alpha1.Repository, pr *tektonv1.PipelineRun) error {
func (r *Reconciler) cleanupPipelineRuns(ctx context.Context, logger *zap.SugaredLogger, pacInfo *info.PacOpts, repo *v1alpha1.Repository, pr *tektonv1.PipelineRun) error {
keepMaxPipeline, ok := pr.Annotations[keys.MaxKeepRuns]
if ok {
max, err := strconv.Atoi(keepMaxPipeline)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestCleanupPipelineRuns(t *testing.T) {
kinteract: kint,
}

pacInfo := info.PacOpts{
pacInfo := &info.PacOpts{
Settings: settings.Settings{
MaxKeepRunsUpperLimit: tt.maxkeepruns,
DefaultMaxKeepRuns: tt.defaultmaxkeepruns,
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewController() func(context.Context, configmap.Watcher) *controller.Impl {

log := logging.FromContext(ctx)
run := params.New()
run.Info.InitInfo()
rinfo := &run.Info
rinfo.Controller = info.GetControllerInfoFromEnvOrDefault()
err := run.Clients.NewClients(ctx, rinfo)
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, pr *tektonv1.PipelineRun
}
detectedProvider.SetPacInfo(&pacInfo)

if repo, err := r.reportFinalStatus(ctx, logger, pacInfo, event, pr, detectedProvider); err != nil {
if repo, err := r.reportFinalStatus(ctx, logger, &pacInfo, event, pr, detectedProvider); err != nil {
msg := fmt.Sprintf("report status: %v", err)
r.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "RepositoryReportFinalStatus", msg)
return err
}
return nil
}

func (r *Reconciler) reportFinalStatus(ctx context.Context, logger *zap.SugaredLogger, pacInfo info.PacOpts, event *info.Event, pr *tektonv1.PipelineRun, provider provider.Interface) (*v1alpha1.Repository, error) {
func (r *Reconciler) reportFinalStatus(ctx context.Context, logger *zap.SugaredLogger, pacInfo *info.PacOpts, event *info.Event, pr *tektonv1.PipelineRun, provider provider.Interface) (*v1alpha1.Repository, error) {
repoName := pr.GetAnnotations()[keys.Repository]
repo, err := r.repoLister.Repositories(pr.Namespace).Get(repoName)
if err != nil {
Expand Down
10 changes: 2 additions & 8 deletions pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@ func TestReconciler_ReconcileKind(t *testing.T) {
Kube: stdata.Kube,
},
Info: info.Info{
Pac: &info.PacOpts{
Settings: settings.Settings{
ErrorLogSnippet: true,
SecretAutoCreation: true,
},
},
Controller: &info.ControllerInfo{
Secret: secretName,
},
Expand All @@ -216,13 +210,13 @@ func TestReconciler_ReconcileKind(t *testing.T) {
metrics: metrics,
}
r.run.Clients.SetConsoleUI(consoleui.FallBackConsole{})
pacInfo := info.PacOpts{
pacInfo := &info.PacOpts{
Settings: settings.Settings{
ErrorLogSnippet: true,
SecretAutoCreation: true,
},
}
vcx.SetPacInfo(&pacInfo)
vcx.SetPacInfo(pacInfo)

event := buildEventFromPipelineRun(pr)
testSetupGHReplies(t, mux, event, tt.checkRunID, tt.finalStatus)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *Reconciler) getFailureSnippet(ctx context.Context, pr *tektonv1.Pipelin
return fmt.Sprintf("task <b>%s</b> has the status <b>\"%s\"</b>:\n<pre>%s</pre>", name, sortedTaskInfos[0].Reason, text)
}

func (r *Reconciler) postFinalStatus(ctx context.Context, logger *zap.SugaredLogger, pacInfo info.PacOpts, vcx provider.Interface, event *info.Event, createdPR *tektonv1.PipelineRun) (*tektonv1.PipelineRun, error) {
func (r *Reconciler) postFinalStatus(ctx context.Context, logger *zap.SugaredLogger, pacInfo *info.PacOpts, vcx provider.Interface, event *info.Event, createdPR *tektonv1.PipelineRun) (*tektonv1.PipelineRun, error) {
pr, err := r.run.Clients.Tekton.TektonV1().PipelineRuns(createdPR.GetNamespace()).Get(
ctx, createdPR.GetName(), metav1.GetOptions{},
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestPostFinalStatus(t *testing.T) {
r := &Reconciler{
run: run,
}
pacInfo := info.PacOpts{
pacInfo := &info.PacOpts{
Settings: settings.Settings{
ErrorLogSnippet: false,
},
Expand Down

0 comments on commit b69cf31

Please sign in to comment.