2016-02-22 16:14:25 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2016-02-22 16:14:25 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2017-01-22 03:36:02 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2016-02-22 16:14:25 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2017-01-10 08:49:34 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
2016-02-22 16:14:25 +00:00
|
|
|
"k8s.io/kubernetes/pkg/quota"
|
|
|
|
"k8s.io/kubernetes/pkg/quota/generic"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewSecretEvaluator returns an evaluator that can evaluate secrets
|
|
|
|
func NewSecretEvaluator(kubeClient clientset.Interface) quota.Evaluator {
|
2016-12-07 20:44:16 +00:00
|
|
|
return &generic.ObjectCountEvaluator{
|
|
|
|
AllowCreateOnUpdate: false,
|
|
|
|
InternalGroupKind: api.Kind("Secret"),
|
|
|
|
ResourceName: api.ResourceSecrets,
|
2017-01-22 03:36:02 +00:00
|
|
|
ListFuncByNamespace: func(namespace string, options metav1.ListOptions) ([]runtime.Object, error) {
|
2016-10-14 17:44:20 +00:00
|
|
|
itemList, err := kubeClient.Core().Secrets(namespace).List(options)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
results := make([]runtime.Object, 0, len(itemList.Items))
|
|
|
|
for i := range itemList.Items {
|
|
|
|
results = append(results, &itemList.Items[i])
|
|
|
|
}
|
|
|
|
return results, nil
|
2016-02-22 16:14:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|