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

rootcacertpublisher: trigger resync on namespace add and update #71005

Merged
merged 1 commit into from
Nov 14, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/kube-controller-manager/app/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func startRootCACertPublisher(ctx ControllerContext) (http.Handler, bool, error)

sac, err := rootcacertpublisher.NewPublisher(
ctx.InformerFactory.Core().V1().ConfigMaps(),
ctx.InformerFactory.Core().V1().Namespaces(),
ctx.ClientBuilder.ClientOrDie("root-ca-cert-publisher"),
rootCA,
)
Expand Down
10 changes: 9 additions & 1 deletion pkg/controller/certificates/rootcacertpublisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const RootCACertCofigMapName = "kube-root-ca.crt"
// NewPublisher construct a new controller which would manage the configmap
// which stores certificates in each namespace. It will make sure certificate
// configmap exists in each namespace.
func NewPublisher(cmInformer coreinformers.ConfigMapInformer, cl clientset.Interface, rootCA []byte) (*Publisher, error) {
func NewPublisher(cmInformer coreinformers.ConfigMapInformer, nsInformer coreinformers.NamespaceInformer, cl clientset.Interface, rootCA []byte) (*Publisher, error) {
e := &Publisher{
client: cl,
rootCA: rootCA,
Expand All @@ -62,6 +62,12 @@ func NewPublisher(cmInformer coreinformers.ConfigMapInformer, cl clientset.Inter
e.cmLister = cmInformer.Lister()
e.cmListerSynced = cmInformer.Informer().HasSynced

nsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: e.namespaceAdded,
UpdateFunc: e.namespaceUpdated,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without registering these event handlers, namespaceAdded and namespaceUpdated are not called, so we don't resync the ca.crt config map on namespace changes.

})
e.nsListerSynced = nsInformer.Informer().HasSynced

e.syncHandler = e.syncNamespace

return e, nil
Expand All @@ -79,6 +85,8 @@ type Publisher struct {
cmLister corelisters.ConfigMapLister
cmListerSynced cache.InformerSynced

nsListerSynced cache.InformerSynced

queue workqueue.RateLimitingInterface
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func TestConfigMapCreation(t *testing.T) {
client := fake.NewSimpleClientset(caConfigMap, existNS)
informers := informers.NewSharedInformerFactory(fake.NewSimpleClientset(), controller.NoResyncPeriodFunc())
cmInformer := informers.Core().V1().ConfigMaps()
controller, err := NewPublisher(cmInformer, client, fakeRootCA)
nsInformer := informers.Core().V1().Namespaces()
controller, err := NewPublisher(cmInformer, nsInformer, client, fakeRootCA)
if err != nil {
t.Fatalf("error creating ServiceAccounts controller: %v", err)
}
Expand Down