Skip to content

Commit

Permalink
add stop cluster for debt
Browse files Browse the repository at this point in the history
  • Loading branch information
bxy4543 committed Aug 7, 2024
1 parent 7ac4ebc commit b2f61d6
Show file tree
Hide file tree
Showing 5 changed files with 1,016 additions and 71 deletions.
48 changes: 25 additions & 23 deletions controllers/account/controllers/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (

objectstoragev1 "github/labring/sealos/controllers/objectstorage/api/v1"

kbv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -132,7 +134,7 @@ func (r *NamespaceReconciler) SuspendUserResource(ctx context.Context, namespace
// suspend pod: deploy pod && clone unmanaged pod
// delete infra cr
pipelines := []func(context.Context, string) error{
//r.suspendKBCluster,
r.suspendKBCluster,
r.suspendOrphanPod,
r.limitResourceQuotaCreate,
r.deleteControlledPod,
Expand Down Expand Up @@ -190,28 +192,28 @@ func GetLimit0ResourceQuota(namespace string) *corev1.ResourceQuota {
return &quota
}

//func (r *NamespaceReconciler) suspendKBCluster(ctx context.Context, namespace string) error {
// kbClusterList := kbv1alpha1.ClusterList{}
// if err := r.Client.List(ctx, &kbClusterList, client.InNamespace(namespace)); err != nil {
// return err
// }
// for _, kbCluster := range kbClusterList.Items {
// if kbCluster.Status.Phase != kbv1alpha1.RunningClusterPhase {
// continue
// }
// ops := kbv1alpha1.OpsRequest{}
// ops.Namespace = kbCluster.Namespace
// ops.ObjectMeta.Name = "stop-" + kbCluster.Name + "-" + time.Now().Format("2006-01-02-15")
// ops.Spec.TTLSecondsAfterSucceed = 1
// ops.Spec.ClusterRef = kbCluster.Name
// ops.Spec.Type = "Stop"
// err := r.Client.Create(ctx, &ops)
// if err != nil {
// r.Log.Error(err, "create ops request failed", "ops", ops.Name, "namespace", ops.Namespace)
// }
// }
// return nil
//}
func (r *NamespaceReconciler) suspendKBCluster(ctx context.Context, namespace string) error {
kbClusterList := kbv1alpha1.ClusterList{}
if err := r.Client.List(ctx, &kbClusterList, client.InNamespace(namespace)); err != nil {
return err
}
for _, kbCluster := range kbClusterList.Items {
if kbCluster.Status.Phase == kbv1alpha1.StoppedClusterPhase || kbCluster.Status.Phase == kbv1alpha1.StoppingClusterPhase {
continue
}
ops := kbv1alpha1.OpsRequest{}
ops.Namespace = kbCluster.Namespace
ops.ObjectMeta.Name = "stop-" + kbCluster.Name + "-" + time.Now().Format("2006-01-02-15")
ops.Spec.TTLSecondsAfterSucceed = 1
ops.Spec.ClusterRef = kbCluster.Name
ops.Spec.Type = "Stop"
err := r.Client.Create(ctx, &ops)
if err != nil {
r.Log.Error(err, "create ops request failed", "ops", ops.Name, "namespace", ops.Namespace)
}
}
return nil
}

func (r *NamespaceReconciler) suspendOrphanPod(ctx context.Context, namespace string) error {
podList := corev1.PodList{}
Expand Down
41 changes: 25 additions & 16 deletions controllers/account/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/alibabacloud-go/dysmsapi-20170525/v3 v3.0.6
github.com/alibabacloud-go/tea v1.2.1
github.com/alibabacloud-go/tea-utils/v2 v2.0.4
github.com/apecloud/kubeblocks v0.8.4
github.com/astaxie/beego v1.12.3
github.com/go-gomail/gomail v0.0.0-20160411212932-81ebce5c23df
github.com/go-logr/logr v1.4.1
Expand All @@ -32,7 +33,7 @@ require (
gorm.io/gorm v1.25.5
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/client-go v12.0.0+incompatible
sigs.k8s.io/controller-runtime v0.17.2
)

Expand All @@ -48,7 +49,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/clbanning/mxj/v2 v2.5.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
Expand All @@ -58,43 +59,46 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/pgx/v5 v5.5.4 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/lufia/plan9stats v0.0.0-20230110061619-bbe2e5e100de // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.64 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/prom2json v1.3.3 // indirect
github.com/rs/xid v1.5.0 // indirect
Expand All @@ -103,8 +107,13 @@ require (
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/shirou/gopsutil/v3 v3.23.6 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/stripe/stripe-go/v74 v74.30.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
Expand All @@ -119,16 +128,16 @@ require (
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
Expand All @@ -143,7 +152,7 @@ require (
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
Loading

0 comments on commit b2f61d6

Please sign in to comment.