Skip to content

Commit

Permalink
fix(HACBS-2551): filter cached resources
Browse files Browse the repository at this point in the history
Too many resources were required to run this operator as we
were caching every single resources. This change filter
cached resources by using a new cache with custom selectors
for Tekton resources.

Signed-off-by: David Moreno García <[email protected]>
  • Loading branch information
davidmogar committed Sep 13, 2023
1 parent 2be5732 commit 35269d9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY loader/ loader/
COPY metadata/ metadata/
COPY metrics/ metrics/
COPY tekton/ tekton/

Expand Down
2 changes: 1 addition & 1 deletion controllers/internalrequest/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ var _ = Describe("PipelineRun", Ordered, func() {
pipelineRun, err := adapter.createInternalRequestPipelineRun()
Expect(pipelineRun).NotTo(BeNil())
Expect(err).To(BeNil())
Expect(pipelineRun.Labels).To(HaveLen(2))
Expect(pipelineRun.Labels).To(HaveLen(3))
Expect(pipelineRun.Spec.Params).To(HaveLen(len(adapter.internalRequest.Spec.Params)))
})

Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ package main

import (
"flag"
"github.com/redhat-appstudio/internal-services/metadata"
"github.com/redhat-appstudio/internal-services/tekton"
"github.com/redhat-appstudio/operator-toolkit/controller"
"go.uber.org/zap/zapcore"
"os"

tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/labels"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/manager"

Expand Down Expand Up @@ -87,6 +90,13 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "b548bb9d.redhat.com",
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&tektonv1beta1.PipelineRun{}: {
Label: labels.SelectorFromSet(labels.Set{metadata.PipelinesTypeLabel: tekton.PipelineTypeRelease}),
},
},
}),
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
18 changes: 18 additions & 0 deletions metadata/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package metadata

import "fmt"

const (
// rhtapDomain is the prefix of the application label
rhtapDomain = "appstudio.openshift.io"
)

var (
// pipelinesLabelPrefix is the prefix of the pipelines label
pipelinesLabelPrefix = fmt.Sprintf("pipelines.%s", rhtapDomain)
)

var (
// PipelinesTypeLabel is the label used to describe the type of pipeline
PipelinesTypeLabel = fmt.Sprintf("%s/%s", pipelinesLabelPrefix, "type")
)
5 changes: 5 additions & 0 deletions tekton/pipeline_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
libhandler "github.com/operator-framework/operator-lib/handler"
"github.com/redhat-appstudio/internal-services/api/v1alpha1"
"github.com/redhat-appstudio/internal-services/metadata"
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -31,6 +32,9 @@ import (
const (
// internalRequestLabelPrefix is the prefix of the internal request labels
internalRequestLabelPrefix = "internal-services.appstudio.openshift.io"

// PipelineTypeRelease is the type for PipelineRuns created to run a release Pipeline
PipelineTypeRelease = "release"
)

var (
Expand Down Expand Up @@ -81,6 +85,7 @@ func (i *InternalRequestPipelineRun) WithInternalRequest(internalRequest *v1alph
i.ObjectMeta.Labels = map[string]string{
InternalRequestNameLabel: internalRequest.Name,
InternalRequestNamespaceLabel: internalRequest.Namespace,
metadata.PipelinesTypeLabel: PipelineTypeRelease,
}

return i
Expand Down

0 comments on commit 35269d9

Please sign in to comment.