forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
33 lines (28 loc) · 1012 Bytes
/
client.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
package limit_range
import (
"github.com/pkg/errors"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
type ResourceQuotaClientInterface interface {
CreateResourceQuota(namespace string, resourceQuota *v1.ResourceQuota) error
DeleteResourceQuota(namespace string) error
}
type ResourceQuotaClient struct {
Clientset *kubernetes.Clientset
}
func (lr *ResourceQuotaClient) CreateResourceQuota(namespace string, resourceQuota *v1.ResourceQuota) error {
_, err := lr.Clientset.CoreV1().ResourceQuotas(namespace).Create(resourceQuota)
if err != nil {
return errors.Wrapf(err, "cannot create resource quota in namespace: %s", namespace)
}
return nil
}
func (lr *ResourceQuotaClient) DeleteResourceQuota(namespace string) error {
err := lr.Clientset.CoreV1().ResourceQuotas(namespace).Delete(namespace, &metav1.DeleteOptions{})
if err != nil {
return errors.Wrapf(err, "cannot delete resource quota from namespace: %s", namespace)
}
return nil
}