mirror of
https://github.com/labring/sealos.git
synced 2026-10-31 02:11:58 +08:00
* feat:design metering、podresource、resource api type * metering watch user ns and create * feat:add e2e test about metering watch ns * feat:metering watch extensionResourcePrice * feat:pod-controller create resurce CR logic * feat:metering watch Resource create by resource-Controller and update Metering * feat:metering create AccountBalance and account will watch it and deduction balancde * feat:add infra calculate test * feat:add deploy.yaml and temporary ci * feat:change account ns to sealos-system * fix:update resourceName * feat:add deduction info to account chargelist * fix:payment error * fix:update resource name * Modify inappropriate places in the code by github Comment Signed-off-by: 晓杰 <2561589453@qq.com>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// Copyright © 2022 sealos.
|
|
//
|
|
// 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 api
|
|
|
|
import (
|
|
"context"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func EnsureNamespace(name string) *v1.Namespace {
|
|
client := GetDefaultKubernetesClient()
|
|
ns, err := client.CoreV1().Namespaces().Get(context.TODO(), name, metav1.GetOptions{})
|
|
if err != nil {
|
|
return CreateNamespace(client, name)
|
|
}
|
|
return ns
|
|
}
|
|
|
|
func DeleteNamespace(name string) error {
|
|
client := GetDefaultKubernetesClient()
|
|
err := client.CoreV1().Namespaces().Delete(context.TODO(), name, metav1.DeleteOptions{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|