Skip to content

Commit

Permalink
feat: Support running UX server with namespace scope. Fixes #248 (#249)
Browse files Browse the repository at this point in the history
Signed-off-by: David Seapy <[email protected]>
  • Loading branch information
dseapy authored and whynowy committed Oct 27, 2022
1 parent aba44f9 commit 979a3a3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
11 changes: 8 additions & 3 deletions cmd/commands/server.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package commands

import (
sharedutil "github.com/numaproj/numaflow/pkg/shared/util"
svrcmd "github.com/numaproj/numaflow/server/cmd"
"github.com/spf13/cobra"
)

func NewServerCommand() *cobra.Command {
var (
insecure bool
port int
insecure bool
port int
namespaced bool
managedNamespace string
)

command := &cobra.Command{
Expand All @@ -18,10 +21,12 @@ func NewServerCommand() *cobra.Command {
if !cmd.Flags().Changed("port") && insecure {
port = 8080
}
svrcmd.Start(insecure, port)
svrcmd.Start(insecure, port, namespaced, managedNamespace)
},
}
command.Flags().BoolVar(&insecure, "insecure", false, "Whether to disable TLS, defaults to false.")
command.Flags().IntVarP(&port, "port", "p", 8443, "Port to listen on, defaults to 8443 or 8080 if insecure is set")
command.Flags().BoolVar(&namespaced, "namespaced", false, "Whether to run in namespaced scope, defaults to false.")
command.Flags().StringVar(&managedNamespace, "managed-namespace", sharedutil.LookupEnvStringOr("NAMESPACE", "numaflow-system"), "The namespace that the server watches when \"--namespaced\" is \"true\".")
return command
}
1 change: 1 addition & 0 deletions config/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12916,6 +12916,7 @@ spec:
containers:
- args:
- server
- --namespaced
env:
- name: NAMESPACE
valueFrom:
Expand Down
7 changes: 7 additions & 0 deletions config/namespace-install/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ patches:
target:
kind: Deployment
name: numaflow-controller
- patch: |-
- op: add
path: /spec/template/spec/containers/0/args/-
value: --namespaced
target:
kind: Deployment
name: numaflow-server
3 changes: 2 additions & 1 deletion server/apis/v1/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func (h *handler) GetPipeline(c *gin.Context) {

// ListNamespaces is used to provide all the namespaces that have numaflow pipelines running
func (h *handler) ListNamespaces(c *gin.Context) {
l, err := h.numaflowClient.Pipelines("").List(context.Background(), metav1.ListOptions{})
ns := c.GetString("namespace")
l, err := h.numaflowClient.Pipelines(ns).List(context.Background(), metav1.ListOptions{})
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
Expand Down
12 changes: 11 additions & 1 deletion server/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ var (
}
)

func Start(insecure bool, port int) {
func Start(insecure bool, port int, namespaced bool, managedNamespace string) {
logger := logging.NewLogger().Named("server")
router := gin.New()
router.Use(gin.Logger())
router.RedirectTrailingSlash = true
router.Use(static.Serve("/", static.LocalFile("./ui/build", true)))
if namespaced {
router.Use(Namespace(managedNamespace))
}
routes.Routes(router)
router.Use(UrlRewrite(router))
server := http.Server{
Expand Down Expand Up @@ -70,3 +73,10 @@ func UrlRewrite(r *gin.Engine) gin.HandlerFunc {
c.Next()
}
}

func Namespace(ns string) gin.HandlerFunc {
return func(c *gin.Context) {
c.Set("namespace", ns)
c.Next()
}
}

0 comments on commit 979a3a3

Please sign in to comment.