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

feat: use custom cache #545

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions controllers/release/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ func (a *adapter) createManagedPipelineRun(resources *loader.ProcessingResources
WithFinalizer(metadata.ReleaseFinalizer).
WithLabels(map[string]string{
metadata.ApplicationNameLabel: resources.ReleasePlan.Spec.Application,
metadata.ServiceNameLabel: metadata.ServiceName,
metadata.PipelinesTypeLabel: metadata.ManagedPipelineType,
metadata.ReleaseNameLabel: a.release.Name,
metadata.ReleaseNamespaceLabel: a.release.Namespace,
Expand Down Expand Up @@ -429,6 +430,7 @@ func (a *adapter) createTenantPipelineRun(releasePlan *v1alpha1.ReleasePlan, sna
WithFinalizer(metadata.ReleaseFinalizer).
WithLabels(map[string]string{
metadata.ApplicationNameLabel: releasePlan.Spec.Application,
metadata.ServiceNameLabel: metadata.ServiceName,
metadata.PipelinesTypeLabel: metadata.TenantPipelineType,
metadata.ReleaseNameLabel: a.release.Name,
metadata.ReleaseNamespaceLabel: a.release.Namespace,
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ package main
import (
"crypto/tls"
"flag"
"github.com/konflux-ci/release-service/metadata"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/rest"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/controller-runtime/pkg/metrics/server"
crwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
Expand All @@ -41,6 +45,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

Expand Down Expand Up @@ -93,6 +98,15 @@ func main() {
Metrics: server.Options{
BindAddress: metricsAddr,
},
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.ByObject = map[client.Object]cache.ByObject{
&tektonv1.PipelineRun{}: {
Label: labels.SelectorFromSet(labels.Set{metadata.ServiceNameLabel: metadata.ServiceName}),
},
}

return cache.New(config, opts)
},
WebhookServer: crwebhook.NewServer(crwebhook.Options{
Port: 9443,
TLSOpts: []func(*tls.Config){
Expand Down
5 changes: 5 additions & 0 deletions metadata/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (

// MaxLabelLength is the maximum allowed characters in a label value
MaxLabelLength = 63

ServiceName = "release"
)

// Labels used by the release api package
Expand All @@ -41,6 +43,9 @@ var (
// AutomatedLabel is the label name for marking a Release as automated
AutomatedLabel = fmt.Sprintf("release.%s/automated", rhtapDomain)

// ServiceNameLabel is the label used to specify the service associated with an object
ServiceNameLabel = fmt.Sprintf("%s/%s", rhtapDomain, "service")

// ReleasePlanAdmissionLabel is the ReleasePlan label for the name of the ReleasePlanAdmission to use
ReleasePlanAdmissionLabel = fmt.Sprintf("release.%s/releasePlanAdmission", rhtapDomain)
)
Expand Down
Loading