Skip to content

Commit

Permalink
UPSTREAM: <carry>: Set informer for openstack
Browse files Browse the repository at this point in the history
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 <hekumar@redhat.com>
  • Loading branch information
2 people authored and soltysh committed Sep 8, 2021
1 parent df3b20d commit 828499b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions plugin/pkg/admission/storage/persistentvolume/label/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 828499b

Please sign in to comment.