Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PX Resource Gateway #1621

Open
wants to merge 13 commits into
base: release-24.2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ OPERATOR_IMG=$(DOCKER_HUB_REPO)/$(DOCKER_HUB_OPERATOR_IMG):$(DOCKER_HUB_OPERATOR
OPERATOR_TEST_IMG=$(DOCKER_HUB_REPO)/$(DOCKER_HUB_OPERATOR_TEST_IMG):$(DOCKER_HUB_OPERATOR_TEST_TAG)
BUNDLE_IMG=$(DOCKER_HUB_REPO)/$(DOCKER_HUB_BUNDLE_IMG):$(RELEASE_VER)
REGISTRY_IMG=$(DOCKER_HUB_REPO)/$(DOCKER_HUB_REGISTRY_IMG):$(RELEASE_VER)

PX_DOC_HOST ?= https://docs.portworx.com
PX_INSTALLER_HOST ?= https://install.portworx.com
PROMETHEUS_OPERATOR_HELM_CHARTS_TAG ?= kube-prometheus-stack-42.1.0
Expand All @@ -78,7 +79,8 @@ BUILD_OPTIONS := -ldflags=$(LDFLAGS)
.DEFAULT_GOAL=all
.PHONY: operator deploy clean vendor vendor-update test generate manifests tools-check

all: operator pretest downloads
all: operator px-resource-gateway pretest downloads
dev: operator px-resource-gateway container deploy

vendor-update:
go mod download
Expand Down Expand Up @@ -179,6 +181,11 @@ operator:
@cd cmd/operator && CGO_ENABLED=0 go build $(BUILD_OPTIONS) -o $(BIN)/operator
@cd cmd/dryrun && CGO_ENABLED=0 go build $(BUILD_OPTIONS) -o $(BIN)/dryrun

px-resource-gateway:
dgoel-px marked this conversation as resolved.
Show resolved Hide resolved
@echo "Building the px-resource-gateway binary"
@echo "CGO_ENABLED=0 go build $(BUILD_OPTIONS) -o $(BIN)/px-resource-gateway"
dgoel-px marked this conversation as resolved.
Show resolved Hide resolved
@cd cmd/px-resource-gateway && CGO_ENABLED=0 go build $(BUILD_OPTIONS) -o $(BIN)/px-resource-gateway

container:
@echo "Building operator image $(OPERATOR_IMG)"
docker build --pull --tag $(OPERATOR_IMG) -f build/Dockerfile .
Expand Down Expand Up @@ -298,3 +305,6 @@ clean: clean-release-manifest clean-bundle
@go clean -i $(PKGS)
@echo "Deleting image "$(OPERATOR_IMG)
@docker rmi -f $(OPERATOR_IMG) registry.access.redhat.com/ubi9-minimal:latest

px-resource-gateway-proto:
$(MAKE) -C proto px-resource-gateway-docker-proto
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ COPY manifests /manifests
COPY bin/configs /configs
COPY bin/operator /
COPY bin/dryrun /
COPY bin/px-resource-gateway /
111 changes: 111 additions & 0 deletions cmd/px-resource-gateway/px_resource_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package main

import (
"fmt"
"log"
_ "net/http/pprof"
"os"

"github.com/libopenstorage/grpc-framework/pkg/util"
grpcFramework "github.com/libopenstorage/grpc-framework/server"
pxResourceGateway "github.com/libopenstorage/operator/pkg/px-resource-gateway"
"github.com/libopenstorage/operator/pkg/version"
pb "github.com/libopenstorage/operator/proto"
"github.com/portworx/sched-ops/k8s/core"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"google.golang.org/grpc"
)

const (
// PxResourceGatewayString is the common string for px-resource-gateway components
PxResourceGatewayString = "px-resource-gateway"
// PxResourceGatewayServerName is the service name for px-resource-gateway
PxResourceGatewayServerName = PxResourceGatewayString
// PxResourceGatewayServerHost is the host for px-resource-gateway
PxResourceGatewayServerHost = "0.0.0.0"
// PxResourceGatewayServerPortEnv is the environment variable for px-resource-gateway service port
PxResourceGatewayServerPortEnv = "PX_RESOURCE_GATEWAY_PORT"
// PxResourceGatewayServerSocket is the socket for px-resource-gateway
PxResourceGatewayServerSocket = "/tmp/px-resource-gate.sock"
)

func main() {
app := cli.NewApp()
app.Name = "openstorage-operator"
app.Usage = "Operator to manage openstorage clusters"
app.Version = version.Version
app.Action = run

app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "Set log level to debug",
},
}

if err := app.Run(os.Args); err != nil {
log.Fatalf("Error starting openstorage operator: %v", err)
}
}

func run(c *cli.Context) {
if c.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}

// TODO: expose method to initialize k8s client in sched-ops
// initialize k8s client
version, err := core.Instance().GetVersion()
if err != nil {
logrus.Fatalf("Failed to get k8s version: %v", err)
}
logrus.Debugf("Running on k8s version: %s", version.String())

pxResourceGatewayServerPort := os.Getenv(PxResourceGatewayServerPortEnv)

// TODO: add security
pxResourceGatewayServerConfig := &grpcFramework.ServerConfig{
Name: PxResourceGatewayServerName,
Address: fmt.Sprintf("%s:%s", PxResourceGatewayServerHost, pxResourceGatewayServerPort),
Socket: PxResourceGatewayServerSocket,
AuditOutput: os.Stdout,
AccessOutput: os.Stdout,
}

semaphoreServer := pxResourceGateway.NewSemaphoreServer()
pxResourceGatewayServerConfig.
RegisterGrpcServers(func(gs *grpc.Server) {
pb.RegisterSemaphoreServiceServer(gs, semaphoreServer)
}).
WithDefaultGenericRoleManager()

pxResourceGatewayServer, err := grpcFramework.New(pxResourceGatewayServerConfig)
if err != nil {
fmt.Printf("Unable to create server: %v", err)
os.Exit(1)
}

// Setup a signal handler
signal_handler := util.NewSigIntManager(func() {
pxResourceGatewayServer.Stop()
os.Remove(PxResourceGatewayServerSocket)
os.Exit(0)
})
err = signal_handler.Start()
if err != nil {
fmt.Printf("Unable to start signal handler: %v", err)
os.Exit(1)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also setup memory and cpu profiling, and then you can add a signal handler for SIGUSR1 to dump the heap and stack profile -

log.Infof("pprof profiling is enabled, creating profiling server at port %v", defaultPprofPort)


// start server
err = pxResourceGatewayServer.Start()
if err != nil {
fmt.Printf("Unable to start server: %v", err)
os.Exit(1)
}

// Wait. The signal handler will exit cleanly
logrus.Info("Px gRPC server running")
select {}
}
39 changes: 39 additions & 0 deletions deploy/crds/core_v1_storagecluster_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,45 @@ spec:
cpu:
type: string
description: CPU limit.
pxResourceGateway:
dgoel-px marked this conversation as resolved.
Show resolved Hide resolved
type: object
description: Contains spec of px-resource-gateway component for storage driver.
properties:
enabled:
type: boolean
description: Flag indicating whether px-resource-gateway needs to be enabled.
image:
dgoel-px marked this conversation as resolved.
Show resolved Hide resolved
type: string
description: Docker image of the px-resource-gateway container.
args:
type: object
x-kubernetes-preserve-unknown-fields: true
description: >-
It is a map of arguments provided to px-resource-gateway. Example: log-level: debug
resources:
type: object
description: Specifies the resource requirements for the px-resource-gateway pod.
properties:
requests:
type: object
description: Requested resources.
properties:
memory:
type: string
description: Requested memory.
cpu:
type: string
description: Requested cpu.
limits:
type: object
description: Resource limit.
properties:
memory:
type: string
description: Memory limit.
cpu:
type: string
description: CPU limit.
monitoring:
type: object
description: Contains monitoring configuration for the storage cluster.
Expand Down
Loading
Loading