Skip to content

Only cache pods and taskruns with the buildrun label #1869

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
48 changes: 37 additions & 11 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ package controller
import (
"context"

pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"

pipelineapi "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"

"github.com/shipwright-io/build/pkg/apis"
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
"github.com/shipwright-io/build/pkg/config"
"github.com/shipwright-io/build/pkg/ctxlog"
"github.com/shipwright-io/build/pkg/reconciler/build"
Expand All @@ -25,6 +31,35 @@ import (

// NewManager add all the controllers to the manager and register the required schemes
func NewManager(ctx context.Context, config *config.Config, cfg *rest.Config, options manager.Options) (manager.Manager, error) {
// Setup a scheme
options.Scheme = k8sruntime.NewScheme()
if err := corev1.AddToScheme(options.Scheme); err != nil {
return nil, err
}
if err := pipelineapi.AddToScheme(options.Scheme); err != nil {
return nil, err
}
if err := apis.AddToScheme(options.Scheme); err != nil {
return nil, err
}

// Configure the cache
buildRunLabelExistsSelector, err := labels.Parse(buildv1beta1.LabelBuildRun)
if err != nil {
return nil, err
}

options.Cache = cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Pod{}: {
Label: buildRunLabelExistsSelector,
},
&pipelineapi.TaskRun{}: {
Label: buildRunLabelExistsSelector,
},
},
}

mgr, err := manager.New(cfg, options)
if err != nil {
return nil, err
Expand All @@ -39,15 +74,6 @@ func NewManager(ctx context.Context, config *config.Config, cfg *rest.Config, op

ctxlog.Info(ctx, "Registering Components.")

if err := pipelineapi.AddToScheme(mgr.GetScheme()); err != nil {
return nil, err
}

// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
return nil, err
}

// Add Reconcilers.
if err := build.Add(ctx, config, mgr); err != nil {
return nil, err
Expand Down