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 all 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
  •  
  •  
  •  
14 changes: 12 additions & 2 deletions 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 resource-gateway pretest downloads
dev: operator resource-gateway container deploy

vendor-update:
go mod download
Expand Down Expand Up @@ -174,11 +176,16 @@ codegen:
@echo "Generating CRD"
(GOFLAGS="" hack/update-codegen.sh)

operator:
resource-gateway:
@echo "Building the resource-gateway binary"
@cd cmd/resource-gateway && CGO_ENABLED=0 go build $(BUILD_OPTIONS) -o $(BIN)/resource-gateway

operator: resource-gateway
@echo "Building the cluster operator binary"
@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


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

resource-gateway-proto:
$(MAKE) -C proto 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/resource-gateway /
153 changes: 153 additions & 0 deletions cmd/resource-gateway/resource_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package main

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

"github.com/libopenstorage/grpc-framework/pkg/auth"
grpcFramework "github.com/libopenstorage/grpc-framework/server"

pxutil "github.com/libopenstorage/operator/drivers/storage/portworx/util"
resourceGateway "github.com/libopenstorage/operator/pkg/resource-gateway"
"github.com/libopenstorage/operator/pkg/version"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

func main() {
app := cli.NewApp()
app.Name = "resource-gateway"
app.Usage = "gRPC service for managing resources"
app.Version = version.Version
app.Action = run

app.Flags = []cli.Flag{
cli.StringFlag{
Name: "serverHost",
Usage: "Host for resource-gateway gRPC server",
},
cli.StringFlag{
Name: "serverPort",
Usage: "Port for resource-gateway gRPC server",
},
cli.StringFlag{
Name: "namespace",
Usage: "Name of the configmap to use for semaphore",
},
cli.StringFlag{
Name: "configMapName",
Usage: "Name of the configmap to use for semaphore",
},
cli.StringFlag{
Name: "configMapLabels",
Usage: "Labels to use for the configmap",
},
cli.DurationFlag{
Name: "configMapUpdatePeriod",
Usage: "Time period between configmap updates",
},
cli.DurationFlag{
Name: "deadClientTimeout",
Usage: "Time period after which a node is considered dead",
},
cli.BoolFlag{
Name: "debug",
Usage: "Set log level to debug",
},
}

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

// run is the main function for resource-gateway gRPC server
// it initializes the k8s client, creates the gRPC server, and runs the server...
func run(c *cli.Context) {
if c.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}

resourceGatewayServer := resourceGateway.NewResourceGatewayServer(
newResourceGatewayServerConfig(c),
newSemaphoreConfig(c))
err := resourceGatewayServer.SetupSigIntHandler()
if err != nil {
logrus.Fatalf("Failed to setup signal handler: %v", err)
}
err = resourceGatewayServer.Start()
if err != nil {
logrus.Fatalf("Failed to start resource-gateway server: %v", err)
}
}

// newResourceGatewayServerConfig creates the config for resource-gateway gRPC server
func newResourceGatewayServerConfig(c *cli.Context) *grpcFramework.ServerConfig {
resourceGatewayServerConfig := resourceGateway.NewResourceGatewayServerConfig()

serverName := c.String("serverName")
if serverName == "" {
resourceGatewayServerConfig.Name = serverName
}

serverHost := c.String("serverHost")
serverPort := c.String("serverPort")
if serverHost != "" && serverPort != "" {
serverAddress := fmt.Sprintf("%s:%s", serverHost, serverPort)
resourceGatewayServerConfig.Address = serverAddress
}

// if Px security is enabled, then Issuer and SharedSecret will be set in the environment
authIssuer := os.Getenv(pxutil.EnvKeyPortworxAuthJwtIssuer)
authSharedSecret := os.Getenv(pxutil.EnvKeyPortworxAuthJwtSharedSecret)
if authIssuer != "" && authSharedSecret != "" {
security := &grpcFramework.SecurityConfig{}
authenticator, err := auth.NewJwtAuthenticator(
&auth.JwtAuthConfig{
SharedSecret: []byte(authSharedSecret),
})
if err != nil {
log.Fatalf("unable to create shared key authenticator")
}
security.Authenticators = map[string]auth.Authenticator{
authIssuer: authenticator,
}
resourceGatewayServerConfig.Security = security
}

return resourceGatewayServerConfig
}

// newSemaphoreConfig creates a SemaphoreConfig object with provided
// cli arguments to initialize a new semaphore server
func newSemaphoreConfig(c *cli.Context) *resourceGateway.SemaphoreConfig {
semaphoreConfig := resourceGateway.NewSemaphoreConfig()
if c.String("configMapName") != "" {
semaphoreConfig.ConfigMapName = c.String("configMapName")
}
if c.String("namespace") != "" {
semaphoreConfig.ConfigMapNamespace = c.String("namespace")
}
if c.String("configMapLabels") != "" {
configMapLabels := make(map[string]string)
for _, kv := range strings.Split(c.String("configMapLabels"), ",") {
kvSplit := strings.Split(kv, "=")
if len(kvSplit) != 2 {
logrus.Errorf("Invalid configMapLabels: %s", kvSplit)
continue
}
configMapLabels[kvSplit[0]] = kvSplit[1]
}
semaphoreConfig.ConfigMapLabels = configMapLabels
}
if c.Duration("configMapUpdatePeriod") != 0 {
semaphoreConfig.ConfigMapUpdatePeriod = c.Duration("configMapUpdatePeriod")
}
if c.Duration("deadClientTimeout") != 0 {
semaphoreConfig.DeadClientTimeout = c.Duration("deadClientTimeout")
}
return semaphoreConfig
}
42 changes: 42 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.
resourceGateway:
type: object
description: Contains spec of resource-gateway component for storage driver.
properties:
enabled:
type: boolean
description: Flag indicating whether 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 resource-gateway container.
args:
type: object
x-kubernetes-preserve-unknown-fields: true
description: >-
It is a map of arguments provided to resource-gateway. Example: log-level: debug
resources:
type: object
description: Specifies the resource requirements for the 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 Expand Up @@ -3902,6 +3941,9 @@ spec:
dynamicPluginProxy:
type: string
description: Desired image for nginx proxy image.
resourceGateway:
type: string
description: Desired image for px resource gateway.
conditions:
type: array
description: Contains details for the current condition of this cluster.
Expand Down
1 change: 1 addition & 0 deletions drivers/storage/portworx/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func Register(name string, c PortworxComponent) {
registerLock.Lock()
defer registerLock.Unlock()
components[name] = c

}

// Get returns a PortworxComponent if present else returns (nil, false)
Expand Down
Loading
Loading