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

fix issue44 with node cache #86

Closed
wants to merge 1 commit into from
Closed
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ vendor
Gopkg.toml
Gopkg.lock
**/*.pyc
.idea
.vscode
34 changes: 30 additions & 4 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ type ProvisionController struct {
volumes cache.Store
classInformer cache.SharedInformer
classes cache.Store
nodeInformer cache.SharedIndexInformer
nodes cache.Store

// To determine if the informer is internal or external
customClaimInformer, customVolumeInformer, customClassInformer bool
customClaimInformer, customVolumeInformer, customClassInformer, customNodeInformer bool

claimQueue workqueue.RateLimitingInterface
volumeQueue workqueue.RateLimitingInterface
Expand Down Expand Up @@ -483,6 +485,19 @@ func VolumesInformer(informer cache.SharedInformer) func(*ProvisionController) e
}
}

// NodeInformer sets the informer to use for accessing nodes.
// Defaults to using a internal informer.
func NodeInformer(informer cache.SharedInformer) func(*ProvisionController) error {
return func(c *ProvisionController) error {
if c.HasRun() {
return errRuntime
}
c.nodeInformer = informer
c.customNodeInformer = true
return nil
}
}

// ClassesInformer sets the informer to use for accessing StorageClasses.
// The informer must use the versioned resource appropriate for the Kubernetes cluster version
// (that is, v1.StorageClass for >= 1.6, and v1beta1.StorageClass for < 1.6).
Expand Down Expand Up @@ -754,6 +769,13 @@ func NewProvisionController(
controller.volumeStore = NewBackoffStore(client, controller.eventRecorder, controller.createProvisionedPVBackoff, controller)
}

// --------------
// Nodes
if controller.nodeInformer == nil {
controller.nodeInformer = informer.Core().V1().Nodes().Informer()
}
controller.nodes = controller.nodeInformer.GetStore()

return controller
}

Expand Down Expand Up @@ -856,8 +878,11 @@ func (ctrl *ProvisionController) Run(ctx context.Context) {
if !ctrl.customClassInformer {
go ctrl.classInformer.Run(ctx.Done())
}
if !ctrl.customNodeInformer {
go ctrl.nodeInformer.Run(ctx.Done())
}

if !cache.WaitForCacheSync(ctx.Done(), ctrl.claimInformer.HasSynced, ctrl.volumeInformer.HasSynced, ctrl.classInformer.HasSynced) {
if !cache.WaitForCacheSync(ctx.Done(), ctrl.claimInformer.HasSynced, ctrl.volumeInformer.HasSynced, ctrl.classInformer.HasSynced, ctrl.nodeInformer.HasSynced) {
return
}

Expand Down Expand Up @@ -1358,11 +1383,12 @@ func (ctrl *ProvisionController) provisionClaimOperation(ctx context.Context, cl
}

var selectedNode *v1.Node
var nodeExists bool
if ctrl.kubeVersion.AtLeast(utilversion.MustParseSemantic("v1.11.0")) {
// Get SelectedNode
if nodeName, ok := getString(claim.Annotations, annSelectedNode, annAlphaSelectedNode); ok {
selectedNode, err = ctrl.client.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{}) // TODO (verult) cache Nodes
if err != nil {
selectedNode, nodeExists, err = ctrl.nodes.GetByKey(nodeName) // TODO (verult) cache Nodes
if err != nil || !nodeExists {
err = fmt.Errorf("failed to get target node: %v", err)
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, "ProvisioningFailed", err.Error())
return ProvisioningNoChange, err
Expand Down
4 changes: 3 additions & 1 deletion controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ func newTestProvisionControllerSharedInformers(
}
return informerFactory.Storage().V1beta1().StorageClasses().Informer()
}()
nodeInformer := informerFactory.Core().V1().Nodes().Informer()

ctrl := NewProvisionController(
client,
Expand All @@ -1380,7 +1381,8 @@ func newTestProvisionControllerSharedInformers(
RetryPeriod(resyncPeriod/2),
ClaimsInformer(claimInformer),
VolumesInformer(volumeInformer),
ClassesInformer(classInformer))
ClassesInformer(classInformer),
NodeInformer(nodeInformer))

return ctrl, informerFactory
}
Expand Down