Skip to content

Commit

Permalink
feat: read only view for UI (#1628)
Browse files Browse the repository at this point in the history
Signed-off-by: veds-g <[email protected]>
  • Loading branch information
veds-g authored and yhl25 committed Apr 3, 2024
1 parent 45032fc commit a4c1d48
Show file tree
Hide file tree
Showing 28 changed files with 854 additions and 320 deletions.
3 changes: 3 additions & 0 deletions cmd/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewServerCommand() *cobra.Command {
namespaced bool
managedNamespace string
baseHref string
readOnly bool
disableAuth bool
serverAddr string
)
Expand All @@ -55,6 +56,7 @@ func NewServerCommand() *cobra.Command {
Namespaced: namespaced,
ManagedNamespace: managedNamespace,
BaseHref: baseHref,
ReadOnly: readOnly,
DisableAuth: disableAuth,
DexServerAddr: common.NumaflowDexServerAddr,
ServerAddr: serverAddr,
Expand All @@ -69,6 +71,7 @@ func NewServerCommand() *cobra.Command {
command.Flags().BoolVar(&namespaced, "namespaced", sharedutil.LookupEnvBoolOr("NUMAFLOW_SERVER_NAMESPACED", false), "Whether to run in namespaced scope, defaults to false.")
command.Flags().StringVar(&managedNamespace, "managed-namespace", sharedutil.LookupEnvStringOr("NUMAFLOW_SERVER_MANAGED_NAMESPACE", sharedutil.LookupEnvStringOr("NAMESPACE", "numaflow-system")), "The namespace that the server watches when \"--namespaced\" is \"true\".")
command.Flags().StringVar(&baseHref, "base-href", sharedutil.LookupEnvStringOr("NUMAFLOW_SERVER_BASE_HREF", "/"), "Base href for Numaflow server, defaults to '/'.")
command.Flags().BoolVar(&readOnly, "readonly", sharedutil.LookupEnvBoolOr("NUMAFLOW_SERVER_READONLY", true), "Whether to enable read only view for the UX server, defaults to false.")
command.Flags().BoolVar(&disableAuth, "disable-auth", sharedutil.LookupEnvBoolOr("NUMAFLOW_SERVER_DISABLE_AUTH", false), "Whether to disable authentication and authorization, defaults to false.")
command.Flags().StringVar(&serverAddr, "server-addr", sharedutil.LookupEnvStringOr("NUMAFLOW_SERVER_ADDRESS", "https://localhost:8443"), "The external address of the Numaflow server.")
return command
Expand Down
1 change: 1 addition & 0 deletions config/advanced-install/namespaced-controller-wo-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ apiVersion: v1
data:
namespaced: "true"
server.disable.auth: "true"
server.readonly: "false"
kind: ConfigMap
metadata:
name: numaflow-cmd-params-config
Expand Down
7 changes: 7 additions & 0 deletions config/advanced-install/namespaced-numaflow-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ apiVersion: v1
data:
namespaced: "true"
server.disable.auth: "true"
server.readonly: "false"
kind: ConfigMap
metadata:
name: numaflow-cmd-params-config
Expand Down Expand Up @@ -229,6 +230,12 @@ spec:
key: server.base.href
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_READONLY
valueFrom:
configMapKeyRef:
key: server.readonly
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_DISABLE_AUTH
valueFrom:
configMapKeyRef:
Expand Down
7 changes: 7 additions & 0 deletions config/advanced-install/numaflow-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ subjects:
apiVersion: v1
data:
server.disable.auth: "true"
server.readonly: "false"
kind: ConfigMap
metadata:
name: numaflow-cmd-params-config
Expand Down Expand Up @@ -240,6 +241,12 @@ spec:
key: server.base.href
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_READONLY
valueFrom:
configMapKeyRef:
key: server.readonly
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_DISABLE_AUTH
valueFrom:
configMapKeyRef:
Expand Down
6 changes: 6 additions & 0 deletions config/base/numaflow-server/numaflow-server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ spec:
name: numaflow-cmd-params-config
key: server.base.href
optional: true
- name: NUMAFLOW_SERVER_READONLY
valueFrom:
configMapKeyRef:
name: numaflow-cmd-params-config
key: server.readonly
optional: true
- name: NUMAFLOW_SERVER_DISABLE_AUTH
valueFrom:
configMapKeyRef:
Expand Down
3 changes: 3 additions & 0 deletions config/base/shared-config/numaflow-cmd-params-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ data:
### Base href for Numaflow UX server, defaults to '/'.
# server.base.href: "/"
#
### Whether to enable read only view for the UX server, defaults to false.
server.readonly: "false"
#
### Whether to disable authentication and authorization for the UX server, defaults to false.
server.disable.auth: "true"
#
Expand Down
7 changes: 7 additions & 0 deletions config/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17083,6 +17083,7 @@ subjects:
apiVersion: v1
data:
server.disable.auth: "true"
server.readonly: "false"
kind: ConfigMap
metadata:
name: numaflow-cmd-params-config
Expand Down Expand Up @@ -17564,6 +17565,12 @@ spec:
key: server.base.href
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_READONLY
valueFrom:
configMapKeyRef:
key: server.readonly
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_DISABLE_AUTH
valueFrom:
configMapKeyRef:
Expand Down
7 changes: 7 additions & 0 deletions config/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16987,6 +16987,7 @@ apiVersion: v1
data:
namespaced: "true"
server.disable.auth: "true"
server.readonly: "false"
kind: ConfigMap
metadata:
name: numaflow-cmd-params-config
Expand Down Expand Up @@ -17456,6 +17457,12 @@ spec:
key: server.base.href
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_READONLY
valueFrom:
configMapKeyRef:
key: server.readonly
name: numaflow-cmd-params-config
optional: true
- name: NUMAFLOW_SERVER_DISABLE_AUTH
valueFrom:
configMapKeyRef:
Expand Down
5 changes: 5 additions & 0 deletions server/cmd/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ServerOptions struct {
Namespaced bool
ManagedNamespace string
BaseHref string
ReadOnly bool
DisableAuth bool
DexServerAddr string
ServerAddr string
Expand Down Expand Up @@ -89,6 +90,9 @@ func (s *server) Start(ctx context.Context) {
DexServerAddr: s.options.DexServerAddr,
ServerAddr: s.options.ServerAddr,
},
routes.ReadOnlyInfo{
IsReadOnly: s.options.ReadOnly,
},
s.options.BaseHref,
authRouteMap,
)
Expand Down Expand Up @@ -152,6 +156,7 @@ func UrlRewrite(r *gin.Engine) gin.HandlerFunc {
func CreateAuthRouteMap(baseHref string) authz.RouteMap {
return authz.RouteMap{
"GET:" + baseHref + "api/v1/sysinfo": authz.NewRouteInfo(authz.ObjectPipeline, false),
"GET:" + baseHref + "api/v1/readonlyinfo": authz.NewRouteInfo(authz.ObjectEvents, false),
"GET:" + baseHref + "api/v1/authinfo": authz.NewRouteInfo(authz.ObjectEvents, false),
"GET:" + baseHref + "api/v1/namespaces": authz.NewRouteInfo(authz.ObjectEvents, false),
"GET:" + baseHref + "api/v1/cluster-summary": authz.NewRouteInfo(authz.ObjectPipeline, false),
Expand Down
9 changes: 8 additions & 1 deletion server/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ type AuthInfo struct {
ServerAddr string `json:"serverAddr"`
}

func Routes(ctx context.Context, r *gin.Engine, sysInfo SystemInfo, authInfo AuthInfo, baseHref string, authRouteMap authz.RouteMap) {
type ReadOnlyInfo struct {
IsReadOnly bool `json:"isReadOnly"`
}

func Routes(ctx context.Context, r *gin.Engine, sysInfo SystemInfo, authInfo AuthInfo, readOnlyInfo ReadOnlyInfo, baseHref string, authRouteMap authz.RouteMap) {
r.GET("/livez", func(c *gin.Context) {
c.Status(http.StatusOK)
})
Expand Down Expand Up @@ -74,6 +78,9 @@ func Routes(ctx context.Context, r *gin.Engine, sysInfo SystemInfo, authInfo Aut
} else {
v1Routes(ctx, r1Group, nil, nil)
}
r1Group.GET("/readonlyinfo", func(c *gin.Context) {
c.JSON(http.StatusOK, v1.NewNumaflowAPIResponse(nil, readOnlyInfo))
})
r1Group.GET("/sysinfo", func(c *gin.Context) {
c.JSON(http.StatusOK, v1.NewNumaflowAPIResponse(nil, sysInfo))
})
Expand Down
6 changes: 5 additions & 1 deletion server/routes/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ func TestRoutes(t *testing.T) {
DisableAuth: false,
DexServerAddr: "test-dex-server-addr",
}

readOnlyInfo := ReadOnlyInfo{
IsReadOnly: false,
}
authRouteMap := authz.RouteMap{}
Routes(logging.WithLogger(signals.SetupSignalHandler(), log), router, sysInfo, authInfo, "/", authRouteMap)
Routes(logging.WithLogger(signals.SetupSignalHandler(), log), router, sysInfo, authInfo, readOnlyInfo, "/", authRouteMap)
t.Run("/404", func(t *testing.T) {
w := httptest.NewRecorder()
req, err := http.NewRequest(http.MethodGet, "/404", nil)
Expand Down
Loading

0 comments on commit a4c1d48

Please sign in to comment.