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

Use latest knative/pkg's configmap informer #1615

Merged
merged 5 commits into from
Mar 16, 2022
Merged
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
k8s.io/apimachinery v0.23.4
k8s.io/client-go v0.23.4
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
knative.dev/pkg v0.0.0-20220314165618-a637a96a1bd9
knative.dev/pkg v0.0.0-20220316002959-3a4cc56708b9
sigs.k8s.io/release-utils v0.4.1-0.20220207182343-6dadf2228617
sigs.k8s.io/yaml v1.3.0
)
Expand Down Expand Up @@ -238,7 +238,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1764,8 +1764,9 @@ github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O
github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.10.0/go.mod h1:WJM3cc3yu7XKBKa/I8WeZm+V3eltZnBwfENSU7mdogU=
github.com/prometheus/client_golang v1.11.0 h1:HNkLOAEQMIDv/K+04rukrLx6ch7msSRwf3/SASFAGtQ=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.11.1 h1:+4eQaD7vAZ6DsfsxB15hbE0odUjGI5ARs9yskGu1v4s=
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
Expand Down Expand Up @@ -3128,8 +3129,8 @@ knative.dev/hack v0.0.0-20220224013837-e1785985d364 h1:wOysRDkzacHlM2OEQoM5ayNT+
knative.dev/hack v0.0.0-20220224013837-e1785985d364/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack/schema v0.0.0-20220224013837-e1785985d364 h1:iuM9VFi9cjSNuVc3x5gUbPQn4zndXfjWDYCJ1fYpk18=
knative.dev/hack/schema v0.0.0-20220224013837-e1785985d364/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
knative.dev/pkg v0.0.0-20220314165618-a637a96a1bd9 h1:a7VjID6wqPki2oMvXkisNqnhcNJN4H4ARWLa8ULyOng=
knative.dev/pkg v0.0.0-20220314165618-a637a96a1bd9/go.mod h1:SsH9J6Gz+CvrHmoL0TELJXmMmohqKSQ5bpJvCv+1+ZI=
knative.dev/pkg v0.0.0-20220316002959-3a4cc56708b9 h1:+l2JdQ5m9Pz8jVHq/dv74L8YR2nM1vr7CR5BiMP5fEs=
knative.dev/pkg v0.0.0-20220316002959-3a4cc56708b9/go.mod h1:3r6srDeiuiG5DXSGfIe12r2U3Tj5JeeHnQaIXPe/4Zc=
mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48=
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
Expand Down
22 changes: 8 additions & 14 deletions pkg/reconciler/clusterimagepolicy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import (
// Use the informer factory that restricts only to our namespace. This way
// we won't have to grant too broad RBAC rights, nor have trouble starting
// up if we don't have them.
nsinformerfactory "knative.dev/pkg/injection/clients/namespacedkube/informers/factory"

pkgreconciler "knative.dev/pkg/reconciler"
"knative.dev/pkg/system"

"github.com/sigstore/cosign/pkg/apis/config"
clusterimagepolicyinformer "github.com/sigstore/cosign/pkg/client/injection/informers/cosigned/v1alpha1/clusterimagepolicy"
clusterimagepolicyreconciler "github.com/sigstore/cosign/pkg/client/injection/reconciler/cosigned/v1alpha1/clusterimagepolicy"
cminformer "knative.dev/pkg/injection/clients/namespacedkube/informers/core/v1/configmap"
secretinformer "knative.dev/pkg/injection/clients/namespacedkube/informers/core/v1/secret"
)

// This is what the default finalizer name is, but make it explicit so we can
Expand All @@ -47,19 +48,12 @@ func NewController(
cmw configmap.Watcher,
) *controller.Impl {
clusterimagepolicyInformer := clusterimagepolicyinformer.Get(ctx)
nsSecretInformer := nsinformerfactory.Get(ctx).Core().V1().Secrets()
nsConfigMapInformer := nsinformerfactory.Get(ctx).Core().V1().ConfigMaps()

// Start the informers we got from the SharedInformerFactory above because
// injection doesn't do that for us since we're injecting the Factory and
// not the informers.
if err := controller.StartInformers(ctx.Done(), nsSecretInformer.Informer(), nsConfigMapInformer.Informer()); err != nil {
logging.FromContext(ctx).Fatalf("Failed to start informers: %w", err)
}
secretInformer := secretinformer.Get(ctx)
configMapInformer := cminformer.Get(ctx)

r := &Reconciler{
secretlister: nsSecretInformer.Lister(),
configmaplister: nsConfigMapInformer.Lister(),
secretlister: secretInformer.Lister(),
configmaplister: configMapInformer.Lister(),
kubeclient: kubeclient.Get(ctx),
}
impl := clusterimagepolicyreconciler.NewImpl(ctx, r, func(impl *controller.Impl) controller.Options {
Expand All @@ -69,7 +63,7 @@ func NewController(

clusterimagepolicyInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))

nsSecretInformer.Informer().AddEventHandler(controller.HandleAll(
secretInformer.Informer().AddEventHandler(controller.HandleAll(
// Call the tracker's OnChanged method, but we've seen the objects
// coming through this path missing TypeMeta, so ensure it is properly
// populated.
Expand All @@ -93,7 +87,7 @@ func NewController(
// We could also fetch/construct the store and use CM watcher for it, but
// since we need a lister for it anyways in the reconciler, just set up
// the watch here.
nsConfigMapInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
configMapInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: pkgreconciler.ChainFilterFuncs(
pkgreconciler.NamespaceFilterFunc(system.Namespace()),
pkgreconciler.NameFilterFunc(config.ImagePoliciesConfigName)),
Expand Down
6 changes: 4 additions & 2 deletions pkg/reconciler/clusterimagepolicy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import (
"testing"

"knative.dev/pkg/configmap"
. "knative.dev/pkg/reconciler/testing"
rtesting "knative.dev/pkg/reconciler/testing"

// Fake injection informers
_ "github.com/sigstore/cosign/pkg/client/injection/informers/cosigned/v1alpha1/clusterimagepolicy/fake"
_ "knative.dev/pkg/client/injection/kube/informers/core/v1/configmap/fake"
_ "knative.dev/pkg/injection/clients/namespacedkube/informers/core/v1/configmap/fake"
_ "knative.dev/pkg/injection/clients/namespacedkube/informers/core/v1/secret/fake"
_ "knative.dev/pkg/injection/clients/namespacedkube/informers/factory/fake"
)

func TestNew(t *testing.T) {
ctx, _ := SetupFakeContext(t)
ctx, _ := rtesting.SetupFakeContext(t)

c := NewController(ctx, &configmap.ManualWatcher{})

Expand Down