Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .mk/static.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
##@ Static

.PHONY: build-frontend-static
build-frontend-static: install-frontend fmt-frontend ## Run npm install, format and build static frontend
@echo "### Building static frontend"
cd web && npm run build:static
1 change: 1 addition & 0 deletions Dockerfile.cypress
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ COPY mocks mocks
WORKDIR /opt/app-root/web
RUN npm run format-all
RUN npm run build$BUILDSCRIPT
RUN npm run build:static

FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.24 as go-builder

Expand Down
1 change: 1 addition & 0 deletions Dockerfile.downstream
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY --chown=default mocks mocks
WORKDIR /opt/app-root/web
RUN npm run format-all
RUN npm run build
RUN npm run build:static

FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:v1.24 as go-builder

Expand Down
1 change: 1 addition & 0 deletions Dockerfile.front
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY mocks mocks
WORKDIR /opt/app-root/web
RUN npm run format-all
RUN npm run build$BUILDSCRIPT
RUN npm run build:static

FROM scratch

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ endif
include .mk/cypress.mk
include .mk/shortcuts.mk
include .mk/standalone.mk
include .mk/static.mk
12 changes: 9 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,15 @@ type Config struct {
Frontend Frontend `yaml:"frontend" json:"frontend"`
Server Server `yaml:"server,omitempty" json:"server,omitempty"`
Path string `yaml:"-" json:"-"`
Static bool
}

func ReadFile(version, date, filename string) (*Config, error) {
isStatic := len(filename) == 0
// set default values
cfg := Config{
Path: filename,
Path: filename,
Static: isStatic,
Server: Server{
Port: 9001,
MetricsPort: 9002,
Expand Down Expand Up @@ -191,7 +194,10 @@ func ReadFile(version, date, filename string) (*Config, error) {
PromLabels: []string{},
},
}
if len(filename) == 0 {
if isStatic {
// Force TLS
cfg.Server.CertPath = "/var/serving-cert/tls.crt"
cfg.Server.KeyPath = "/var/serving-cert/tls.key"
return &cfg, nil
}
yamlFile, err := os.ReadFile(filename)
Expand Down Expand Up @@ -241,7 +247,7 @@ func (c *Config) IsPromEnabled() bool {
}

func (c *Config) Validate() error {
if !c.IsLokiEnabled() && !c.IsPromEnabled() {
if !c.Static && !c.IsLokiEnabled() && !c.IsPromEnabled() {
return errors.New("neither Loki nor Prometheus is configured; at least one of them should have a URL defined")
}

Expand Down
46 changes: 26 additions & 20 deletions pkg/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,37 @@ func setupRoutes(ctx context.Context, cfg *config.Config, authChecker auth.Check
})
})

// Server status
// Server status and config
api.HandleFunc("/status", h.Status(ctx))
api.HandleFunc("/frontend-config", h.GetFrontendConfig())

// Loki endpoints
api.HandleFunc("/loki/ready", h.LokiReady())
api.HandleFunc("/loki/metrics", forceCheckAdmin(authChecker, h.LokiMetrics()))
api.HandleFunc("/loki/buildinfo", forceCheckAdmin(authChecker, h.LokiBuildInfos()))
api.HandleFunc("/loki/config/limits", forceCheckAdmin(authChecker, h.LokiLimits()))
api.HandleFunc("/loki/flow/records", h.GetFlows(ctx))
api.HandleFunc("/loki/export", h.ExportFlows(ctx))
if cfg.Static {
// Expose static files only
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/dist/static")))
} else {
// Loki endpoints
api.HandleFunc("/loki/ready", h.LokiReady())
api.HandleFunc("/loki/metrics", forceCheckAdmin(authChecker, h.LokiMetrics()))
api.HandleFunc("/loki/buildinfo", forceCheckAdmin(authChecker, h.LokiBuildInfos()))
api.HandleFunc("/loki/config/limits", forceCheckAdmin(authChecker, h.LokiLimits()))
api.HandleFunc("/loki/flow/records", h.GetFlows(ctx))
api.HandleFunc("/loki/export", h.ExportFlows(ctx))

// Common endpoints
api.HandleFunc("/flow/metrics", h.GetTopology(ctx))
api.HandleFunc("/resources/clusters", h.GetClusters(ctx))
api.HandleFunc("/resources/udns", h.GetUDNs(ctx))
api.HandleFunc("/resources/zones", h.GetZones(ctx))
api.HandleFunc("/resources/namespaces", h.GetNamespaces(ctx))
api.HandleFunc("/resources/names", h.GetNames(ctx))
// Common endpoints
api.HandleFunc("/flow/metrics", h.GetTopology(ctx))
api.HandleFunc("/resources/clusters", h.GetClusters(ctx))
api.HandleFunc("/resources/udns", h.GetUDNs(ctx))
api.HandleFunc("/resources/zones", h.GetZones(ctx))
api.HandleFunc("/resources/namespaces", h.GetNamespaces(ctx))
api.HandleFunc("/resources/names", h.GetNames(ctx))

// K8S endpoints
api.HandleFunc("/k8s/resources/udnIds", h.GetUDNIdss(ctx))
// K8S endpoints
api.HandleFunc("/k8s/resources/udnIds", h.GetUDNIdss(ctx))

// Frontend files
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/dist/")))
}

// Frontend files
api.HandleFunc("/frontend-config", h.GetFrontendConfig())
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./web/dist/")))
return r
}

Expand Down
Loading