forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_quota_validate.go
37 lines (32 loc) · 970 Bytes
/
resource_quota_validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package resourcequota
import (
"fmt"
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
clientcache "k8s.io/client-go/tools/cache"
)
/*
reconcile controller listens on project updates, and enqueues the namespaces of the project
so they get a chance to reconcile the resource quotas
*/
type reconcileController struct {
namespaces v1.NamespaceInterface
nsIndexer clientcache.Indexer
}
func (r *reconcileController) reconcileNamespaces(key string, p *v3.Project) (runtime.Object, error) {
if p == nil || p.DeletionTimestamp != nil {
return nil, nil
}
projectID := fmt.Sprintf("%s:%s", p.Namespace, p.Name)
namespaces, err := r.nsIndexer.ByIndex(nsByProjectIndex, projectID)
if err != nil {
return nil, err
}
for _, n := range namespaces {
ns := n.(*corev1.Namespace)
r.namespaces.Controller().Enqueue("", ns.Name)
}
return nil, nil
}