From 828499bd313aa14e4569d21ac766e36222fe5e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Tue, 13 Apr 2021 14:59:46 +0200 Subject: [PATCH] UPSTREAM: : Set informer for openstack Set informer for the openstack cloud provider to ensure it is properly initialized when reading config from a secret. Upstream 89885 was closed in favor of 96750. Co-authored-by: Hemant Kumar --- .../persistentvolume/label/admission.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin/pkg/admission/storage/persistentvolume/label/admission.go b/plugin/pkg/admission/storage/persistentvolume/label/admission.go index 36235e21792f0..940fdd92cd6ed 100644 --- a/plugin/pkg/admission/storage/persistentvolume/label/admission.go +++ b/plugin/pkg/admission/storage/persistentvolume/label/admission.go @@ -24,9 +24,12 @@ import ( "io" "sync" + genericadmissioninitializer "k8s.io/apiserver/pkg/admission/initializer" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apiserver/pkg/admission" + "k8s.io/client-go/informers" cloudprovider "k8s.io/cloud-provider" cloudvolume "k8s.io/cloud-provider/volume" volumehelpers "k8s.io/cloud-provider/volume/helpers" @@ -51,12 +54,14 @@ func Register(plugins *admission.Plugins) { } var _ = admission.Interface(&persistentVolumeLabel{}) +var _ = genericadmissioninitializer.WantsExternalKubeInformerFactory(&persistentVolumeLabel{}) type persistentVolumeLabel struct { *admission.Handler mutex sync.Mutex cloudConfig []byte + sharedInformer informers.SharedInformerFactory awsPVLabeler cloudprovider.PVLabeler gcePVLabeler cloudprovider.PVLabeler azurePVLabeler cloudprovider.PVLabeler @@ -86,6 +91,20 @@ func (l *persistentVolumeLabel) SetCloudConfig(cloudConfig []byte) { l.cloudConfig = cloudConfig } +func (l *persistentVolumeLabel) SetExternalKubeInformerFactory(f informers.SharedInformerFactory) { + secretInformer := f.Core().V1().Secrets() + l.sharedInformer = f + l.SetReadyFunc(secretInformer.Informer().HasSynced) +} + +// ValidateInitialization ensures lister is set. +func (l *persistentVolumeLabel) ValidateInitialization() error { + if l.sharedInformer == nil { + return fmt.Errorf("missing shared informer") + } + return nil +} + func nodeSelectorRequirementKeysExistInNodeSelectorTerms(reqs []api.NodeSelectorRequirement, terms []api.NodeSelectorTerm) bool { for _, req := range reqs { for _, term := range terms { @@ -380,6 +399,11 @@ func (l *persistentVolumeLabel) getOpenStackPVLabeler() (cloudprovider.PVLabeler return nil, err } + cloudProviderWithInformer, ok := cloudProvider.(cloudprovider.InformerUser) + if ok { + cloudProviderWithInformer.SetInformers(l.sharedInformer) + } + openStackPVLabeler, ok := cloudProvider.(cloudprovider.PVLabeler) if !ok { return nil, errors.New("OpenStack cloud provider does not implement PV labeling")