feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
|
||||
Copyright 2021 The KubeSphere Authors.
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
* Please refer to the LICENSE file in the root directory of the project.
|
||||
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package tenant
|
||||
|
||||
@@ -22,55 +9,55 @@ import (
|
||||
"context"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
quotav1alpha2 "kubesphere.io/api/quota/v1alpha2"
|
||||
tenantv1alpha1 "kubesphere.io/api/tenant/v1alpha1"
|
||||
tenantv1beta1 "kubesphere.io/api/tenant/v1beta1"
|
||||
)
|
||||
|
||||
func (t *tenantOperator) CreateWorkspaceResourceQuota(workspace string, quota *quotav1alpha2.ResourceQuota) (*quotav1alpha2.ResourceQuota, error) {
|
||||
if quota.Labels == nil {
|
||||
quota.Labels = make(map[string]string)
|
||||
}
|
||||
quota.Labels[tenantv1alpha1.WorkspaceLabel] = workspace
|
||||
quota.Spec.LabelSelector = labels.Set{tenantv1alpha1.WorkspaceLabel: workspace}
|
||||
return t.ksclient.QuotaV1alpha2().ResourceQuotas().Create(context.TODO(), quota, metav1.CreateOptions{})
|
||||
quota.Labels[tenantv1beta1.WorkspaceLabel] = workspace
|
||||
quota.Spec.LabelSelector = labels.Set{tenantv1beta1.WorkspaceLabel: workspace}
|
||||
return quota, t.client.Create(context.Background(), quota)
|
||||
}
|
||||
|
||||
func (t *tenantOperator) UpdateWorkspaceResourceQuota(workspace string, quota *quotav1alpha2.ResourceQuota) (*quotav1alpha2.ResourceQuota, error) {
|
||||
resourceQuota, err := t.ksclient.QuotaV1alpha2().ResourceQuotas().Get(context.TODO(), quota.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
resourceQuota := "av1alpha2.ResourceQuota{}
|
||||
if err := t.client.Get(context.Background(), types.NamespacedName{Name: quota.Name}, resourceQuota); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resourceQuota.Labels[tenantv1alpha1.WorkspaceLabel] != workspace {
|
||||
if resourceQuota.Labels[tenantv1beta1.WorkspaceLabel] != workspace {
|
||||
return nil, errors.NewNotFound(quotav1alpha2.Resource(quotav1alpha2.ResourcesSingularCluster), resourceQuota.Name)
|
||||
}
|
||||
quota = quota.DeepCopy()
|
||||
if quota.Labels == nil {
|
||||
quota.Labels = make(map[string]string)
|
||||
}
|
||||
quota.Labels[tenantv1alpha1.WorkspaceLabel] = workspace
|
||||
quota.Spec.LabelSelector = labels.Set{tenantv1alpha1.WorkspaceLabel: workspace}
|
||||
return t.ksclient.QuotaV1alpha2().ResourceQuotas().Update(context.TODO(), quota, metav1.UpdateOptions{})
|
||||
quota.Labels[tenantv1beta1.WorkspaceLabel] = workspace
|
||||
quota.Spec.LabelSelector = labels.Set{tenantv1beta1.WorkspaceLabel: workspace}
|
||||
return quota, t.client.Update(context.Background(), quota)
|
||||
}
|
||||
|
||||
func (t *tenantOperator) DeleteWorkspaceResourceQuota(workspace string, resourceQuotaName string) error {
|
||||
resourceQuota, err := t.ksclient.QuotaV1alpha2().ResourceQuotas().Get(context.TODO(), resourceQuotaName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
resourceQuota := "av1alpha2.ResourceQuota{}
|
||||
if err := t.client.Get(context.Background(), types.NamespacedName{Name: resourceQuotaName}, resourceQuota); err != nil {
|
||||
return err
|
||||
}
|
||||
if resourceQuota.Labels[tenantv1alpha1.WorkspaceLabel] != workspace {
|
||||
if resourceQuota.Labels[tenantv1beta1.WorkspaceLabel] != workspace {
|
||||
return errors.NewNotFound(quotav1alpha2.Resource(quotav1alpha2.ResourcesSingularCluster), resourceQuotaName)
|
||||
}
|
||||
return t.ksclient.QuotaV1alpha2().ResourceQuotas().Delete(context.TODO(), resourceQuotaName, metav1.DeleteOptions{})
|
||||
return t.client.Delete(context.Background(), resourceQuota)
|
||||
}
|
||||
|
||||
func (t *tenantOperator) DescribeWorkspaceResourceQuota(workspace string, resourceQuotaName string) (*quotav1alpha2.ResourceQuota, error) {
|
||||
resourceQuota, err := t.ksclient.QuotaV1alpha2().ResourceQuotas().Get(context.TODO(), resourceQuotaName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
resourceQuota := "av1alpha2.ResourceQuota{}
|
||||
if err := t.client.Get(context.Background(), types.NamespacedName{Name: resourceQuotaName}, resourceQuota); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resourceQuota.Labels[tenantv1alpha1.WorkspaceLabel] != workspace {
|
||||
if resourceQuota.Labels[tenantv1beta1.WorkspaceLabel] != workspace {
|
||||
return nil, errors.NewNotFound(quotav1alpha2.Resource(quotav1alpha2.ResourcesSingularCluster), resourceQuotaName)
|
||||
}
|
||||
return resourceQuota, nil
|
||||
|
||||
Reference in New Issue
Block a user