Skip to content

Commit

Permalink
Merge pull request #67784 from cheftako/automated-cherry-pick-of-#674…
Browse files Browse the repository at this point in the history
…33-upstream-release-1.9

Automatic merge from submit-queue.

allow failed discovery on initial quota controller start

Cherry pick of #67433 on release-1.9.

#67433: allow failed discovery on initial quota controller start

kube-controller-manager can now start the quota controller when discovery results can only be partially determined.

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue authored Aug 31, 2018
2 parents d4e482c + 5e63f8b commit 5b936a4
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pkg/controller/resourcequota/resource_quota_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ func NewResourceQuotaController(options *ResourceQuotaControllerOptions) (*Resou
}
rq.quotaMonitor = qm

// do initial quota monitor setup
// do initial quota monitor setup. If we have a discovery failure here, it's ok. We'll discover more resources when a later sync happens.
resources, err := GetQuotableResources(options.DiscoveryFunc)
if err != nil {
if discovery.IsGroupDiscoveryFailedError(err) {
utilruntime.HandleError(fmt.Errorf("initial discovery check failure, continuing and counting on future sync update: %v", err))
} else if err != nil {
return nil, err
}
if err = qm.syncMonitors(resources); err != nil {
Expand Down Expand Up @@ -421,7 +423,16 @@ func (rq *ResourceQuotaController) Sync(discoveryFunc NamespacedResourcesFunc, p
newResources, err := GetQuotableResources(discoveryFunc)
if err != nil {
utilruntime.HandleError(err)
return

if discovery.IsGroupDiscoveryFailedError(err) && len(newResources) > 0 {
// In partial discovery cases, don't remove any existing informers, just add new ones
for k, v := range oldResources {
newResources[k] = v
}
} else {
// short circuit in non-discovery error cases or if discovery returned zero resources
return
}
}

// Decide whether discovery has reported a change.
Expand Down Expand Up @@ -462,15 +473,18 @@ func (rq *ResourceQuotaController) resyncMonitors(resources map[schema.GroupVers

// GetQuotableResources returns all resources that the quota system should recognize.
// It requires a resource supports the following verbs: 'create','list','delete'
// This function may return both results and an error. If that happens, it means that the discovery calls were only
// partially successful. A decision about whether to proceed or not is left to the caller.
func GetQuotableResources(discoveryFunc NamespacedResourcesFunc) (map[schema.GroupVersionResource]struct{}, error) {
possibleResources, err := discoveryFunc()
if err != nil {
return nil, fmt.Errorf("failed to discover resources: %v", err)
possibleResources, discoveryErr := discoveryFunc()
if discoveryErr != nil && len(possibleResources) == 0 {
return nil, fmt.Errorf("failed to discover resources: %v", discoveryErr)
}
quotableResources := discovery.FilteredBy(discovery.SupportsAllVerbs{Verbs: []string{"create", "list", "delete"}}, possibleResources)
quotableGroupVersionResources, err := discovery.GroupVersionResources(quotableResources)
if err != nil {
return nil, fmt.Errorf("Failed to parse resources: %v", err)
}
return quotableGroupVersionResources, nil
// return the original discovery error (if any) in addition to the list
return quotableGroupVersionResources, discoveryErr
}

0 comments on commit 5b936a4

Please sign in to comment.