Skip to content

Commit

Permalink
Added memory limit for obproxy and Fixed setup-obproxy scripts (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI authored Jun 6, 2024
1 parent a88bf21 commit 61dab4c
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 47 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3
github.com/vmihailenco/msgpack/v5 v5.4.1
go.uber.org/zap v1.24.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -138,7 +137,6 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/collector/featuregate v1.5.0 // indirect
go.opentelemetry.io/collector/pdata v1.5.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,6 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/vultr/govultr/v2 v2.17.2 h1:gej/rwr91Puc/tgh+j33p/BLR16UrIPnSr+AIwYWZQs=
github.com/vultr/govultr/v2 v2.17.2/go.mod h1:ZFOKGWmgjytfyjeyAdhQlSWwTjh2ig+X49cAp50dzXI=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
29 changes: 29 additions & 0 deletions internal/dashboard/business/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ import (
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/oceanbase/ob-operator/internal/dashboard/business/common"
"github.com/oceanbase/ob-operator/internal/dashboard/business/constant"
"github.com/oceanbase/ob-operator/internal/dashboard/business/obproxy"
"github.com/oceanbase/ob-operator/internal/dashboard/model/param"
"github.com/oceanbase/ob-operator/internal/dashboard/model/response"
"github.com/oceanbase/ob-operator/pkg/k8s/client"
"github.com/oceanbase/ob-operator/pkg/k8s/resource"
)

Expand Down Expand Up @@ -149,6 +152,8 @@ func ListEvents(ctx context.Context, queryEventParam *param.QueryEventParam) ([]
kind = "OBTenant"
case "OBBACKUPPOLICY":
kind = "OBTenantBackupPolicy"
case "OBPROXY":
kind = "Deployment"
default:
kind = queryEventParam.ObjectType
}
Expand All @@ -171,10 +176,34 @@ func ListEvents(ctx context.Context, queryEventParam *param.QueryEventParam) ([]
if len(selectors) > 0 {
listOptions.FieldSelector = strings.Join(selectors, ",")
}
var filterMap map[string]struct{}
if queryEventParam.ObjectType == "OBPROXY" {
// Filter events by obproxy deployments
filterMap = make(map[string]struct{})
deployments, err := client.GetClient().MetaClient.Resource(schema.GroupVersionResource{
Group: "apps",
Version: "v1",
Resource: "deployments",
}).Namespace(ns).List(ctx, metav1.ListOptions{
LabelSelector: obproxy.LabelOBProxy,
})
logger.Debugf("List deployments: %+v", deployments.Items)
if err != nil {
return nil, err
}
for _, deploy := range deployments.Items {
filterMap[deploy.Name] = struct{}{}
}
}
eventList, err := resource.ListEvents(ctx, ns, listOptions)
logger.Infof("Query events with param: %+v", queryEventParam)
if err == nil {
for _, event := range eventList.Items {
if filterMap != nil {
if _, ok := filterMap[event.InvolvedObject.Name]; !ok {
continue
}
}
events = append(events, response.K8sEvent{
Namespace: event.Namespace,
Type: event.Type,
Expand Down
3 changes: 3 additions & 0 deletions internal/dashboard/business/obproxy/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ func buildOBProxyDeployment(ctx context.Context, param *obproxy.CreateOBProxyPar
Key: "password",
},
},
}, {
Name: "ODP_PROXY_MEM_LIMITED",
Value: fmt.Sprintf("%dMB", quantMemory.Value()*95/100/(1<<20)),
}},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down
44 changes: 21 additions & 23 deletions internal/dashboard/generated/bindata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/dashboard/generated/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,8 @@ const docTemplate = `{
"enum": [
"OBCLUSTER",
"OBTENANT",
"OBBACKUPPOLICY"
"OBBACKUPPOLICY",
"OBPROXY"
],
"type": "string",
"description": "related object types",
Expand Down
3 changes: 2 additions & 1 deletion internal/dashboard/generated/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,8 @@
"enum": [
"OBCLUSTER",
"OBTENANT",
"OBBACKUPPOLICY"
"OBBACKUPPOLICY",
"OBPROXY"
],
"type": "string",
"description": "related object types",
Expand Down
1 change: 1 addition & 0 deletions internal/dashboard/generated/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,7 @@ paths:
- OBCLUSTER
- OBTENANT
- OBBACKUPPOLICY
- OBPROXY
in: query
name: objectType
type: string
Expand Down
2 changes: 1 addition & 1 deletion internal/dashboard/handler/k8s_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// @Tags Cluster
// @Accept application/json
// @Produce application/json
// @Param objectType query string false "related object types" Enums(OBCLUSTER, OBTENANT, OBBACKUPPOLICY)
// @Param objectType query string false "related object types" Enums(OBCLUSTER, OBTENANT, OBBACKUPPOLICY, OBPROXY)
// @Param type query string false "event level" Enums(NORMAL, WARNING)
// @Param name query string false "Object name" string
// @Param namespace query string false "Namespace" string
Expand Down
20 changes: 10 additions & 10 deletions pkg/k8s/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import (
"path/filepath"
"sync"

"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/metadata"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)

type Client struct {
ClientSet *kubernetes.Clientset
DynamicClient dynamic.Interface
DiscoveryClient *discovery.DiscoveryClient
config *rest.Config
ClientSet *kubernetes.Clientset
DynamicClient dynamic.Interface
MetaClient metadata.Interface
config *rest.Config
}

var client *Client
Expand Down Expand Up @@ -94,15 +94,15 @@ func MustGetClient(config *rest.Config) *Client {
if err != nil {
panic(err.Error())
}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
metaClient, err := metadata.NewForConfig(config)
if err != nil {
panic(err.Error())
}
return &Client{
ClientSet: clientset,
DynamicClient: dynamicClient,
DiscoveryClient: discoveryClient,
config: config,
ClientSet: clientset,
DynamicClient: dynamicClient,
MetaClient: metaClient,
config: config,
}
}

Expand Down
Loading

0 comments on commit 61dab4c

Please sign in to comment.