Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
82f1389
fix 2 bugs for incidents page
Fewwy Sep 18, 2025
9412d8b
upgrade perses plugins
jgbernalp Sep 18, 2025
8f0ed86
Merge pull request #539 from Fewwy/fix-alertschartbars
openshift-merge-bot[bot] Sep 19, 2025
32cb786
fix(cypress): Login validation for all session flows
DavidRajnoha Sep 19, 2025
41c52ce
Merge pull request #544 from DavidRajnoha/cypress-operator-session-lo…
openshift-merge-bot[bot] Sep 19, 2025
4bb286c
feat(RHINENG-20863): improved fetching logic for incidents
Fewwy Sep 19, 2025
f74ea2c
Merge pull request #546 from Fewwy/RHINENG-20863
openshift-merge-bot[bot] Sep 22, 2025
6102a5f
fix alerts chart empty state
Fewwy Sep 22, 2025
b1b4eed
fix: fix incidents timeline X domain
falox Sep 23, 2025
a995651
fix: reposition spinner
falox Sep 23, 2025
c1a4b3b
Merge pull request #549 from Fewwy/fix-alerts-chart-empty-state
PeterYurkovich Sep 23, 2025
a2cd9d8
add a 5 minute to the first alert timestamp
Fewwy Sep 23, 2025
9d3e929
Merge pull request #540 from jgbernalp/upgrade-perses-plugins
openshift-merge-bot[bot] Sep 23, 2025
b67b3e3
fix: immer dependency anr patternfly icons import
jgbernalp Sep 19, 2025
1084dd6
Merge pull request #551 from falox/fix-timelines-domain
jgbernalp Sep 24, 2025
60e7234
feat(Cypress): add Prometheus query mocking system for incident scena…
DavidRajnoha Sep 3, 2025
f613f4b
feat(test): add comprehensive data-test attributes and improve Cypres…
DavidRajnoha Sep 10, 2025
174bed2
virtualization installation and stabilization of monitoring tests
etmurasaki Sep 8, 2025
b75e34b
Merge pull request #543 from etmurasaki/automation-kubevirt
openshift-merge-bot[bot] Sep 24, 2025
ac52458
Merge pull request #542 from jgbernalp/fix-immer-dependency
openshift-merge-bot[bot] Sep 24, 2025
3f28645
fix(OU-1015): incidents dropdown stays open fix
Fewwy Sep 24, 2025
01fa17f
Merge pull request #545 from DavidRajnoha/incident-new-ui-and-data-te…
jgbernalp Sep 25, 2025
eace5b6
NO-JIRA: Update translations for incidents
falox Sep 25, 2025
6848bf6
Merge pull request #555 from falox/translations-incidents
openshift-merge-bot[bot] Sep 25, 2025
aba4abb
log and debug mode
etmurasaki Sep 25, 2025
e869813
Merge pull request #554 from Fewwy/OU-1015
openshift-merge-bot[bot] Sep 26, 2025
73b8366
fix(cypress): metric change workaround
DavidRajnoha Sep 24, 2025
0c616a1
fix(cypress): metric change workaround
DavidRajnoha Sep 24, 2025
b0d1bf6
fix(cypress): metric change workaround
DavidRajnoha Sep 24, 2025
91dc2bd
fix(cypress): Update Incident Traversal
DavidRajnoha Sep 25, 2025
c529383
chore: Update gitignore for cypress
DavidRajnoha Sep 26, 2025
4b012b3
Merge pull request #557 from etmurasaki/mp-injection
openshift-merge-bot[bot] Sep 26, 2025
f49d2c5
Merge pull request #550 from Fewwy/OU-1011
openshift-merge-bot[bot] Sep 26, 2025
b569c79
Revert "OU-1011: add a 5 minute to the first alert timestamp"
Fewwy Sep 26, 2025
0333ee1
Merge pull request #559 from Fewwy/revert-550-OU-1011
openshift-merge-bot[bot] Sep 27, 2025
a98aabb
Merge pull request #558 from DavidRajnoha/cypress-gitignore-screensho…
openshift-merge-bot[bot] Sep 29, 2025
bbe8153
fix: update vulnerable dependencies
jgbernalp Sep 29, 2025
cfdeaf3
Merge pull request #561 from jgbernalp/upgrade-vulnerable-dependencies
openshift-merge-bot[bot] Sep 30, 2025
eecf2c3
Merge pull request #553 from DavidRajnoha/cypress-incidents-mocking-m…
openshift-merge-bot[bot] Sep 30, 2025
ab59efc
fix hermetic builds
jgbernalp Sep 30, 2025
02a1942
Updating monitoring-plugin-container image to be consistent with ART …
Sep 30, 2025
25540fe
Merge pull request #556 from DavidRajnoha/cypress-incidents-incident-…
openshift-merge-bot[bot] Sep 30, 2025
15f15c1
Merge pull request #564 from jgbernalp/fix-hermetic-builds
openshift-merge-bot[bot] Sep 30, 2025
e9c1ad5
feat(cypress): Add env var to skip all install
DavidRajnoha Oct 1, 2025
9a93f49
refactor(cypress): move collect debug info inside sessions
DavidRajnoha Oct 1, 2025
f67e314
Merge pull request #568 from DavidRajnoha/cypress-add-skip-all-install
openshift-merge-bot[bot] Oct 1, 2025
6bc4115
fix: read alert silenced status from cluster_health_components_map me…
falox Oct 2, 2025
1a969b8
fix: read the correct start and end dates of the alert
falox Oct 2, 2025
959ae40
fix: correctly detect firing/resolved alert state
falox Oct 2, 2025
fbbcbca
fix: linting
falox Oct 2, 2025
54204c8
refactor: minor changes
falox Oct 2, 2025
b5f2178
chore: add unit test command and dependencies
jgbernalp Oct 2, 2025
bdcc928
fix: fix tooltip for intermittent alerts
falox Oct 2, 2025
ecc4e96
fix: fix tooltip for incidents with multiple severities
falox Oct 2, 2025
1033051
Merge pull request #571 from jgbernalp/add-unit-test-command
openshift-merge-bot[bot] Oct 2, 2025
699dba6
fix: keep alerts populated for the incident, when the graph is hidden…
tremes Oct 3, 2025
3cb0068
Merge pull request #572 from tremes/ou-1025
openshift-merge-bot[bot] Oct 3, 2025
f9d4a85
Merge pull request #569 from falox/fix-dates
openshift-merge-bot[bot] Oct 3, 2025
11367d1
fix: handle empty queries when removing incident filters
rioloc Oct 3, 2025
3af12d8
OU-986
etmurasaki Oct 6, 2025
c8e7339
fix: fix tooltip vertical position
falox Oct 6, 2025
00b5e5e
Merge pull request #575 from etmurasaki/ou-986
openshift-merge-bot[bot] Oct 6, 2025
80b4fef
fix: fix tooltip width
falox Oct 6, 2025
424d011
fix: sort alerts by start time
falox Oct 6, 2025
fef6a54
Merge pull request #576 from falox/fix-tooltip-position
openshift-merge-bot[bot] Oct 7, 2025
851b01e
Merge pull request #574 from rioloc/fix-unexpected-token-exception
openshift-merge-bot[bot] Oct 7, 2025
ff763a1
fix: avoid flickering when changing incidents
tremes Oct 3, 2025
6940d78
fix based on the review
tremes Oct 6, 2025
33cef00
fix the scenario when the incident is deselected by the filter
tremes Oct 7, 2025
ae93935
Merge pull request #577 from falox/fix-alert-timeline-sorting
openshift-merge-bot[bot] Oct 7, 2025
73b6198
OCPBUGS-62276: allow additional TLS config
jgbernalp Oct 7, 2025
f4f4c5a
handle the incident clearing logic in the incident page
tremes Oct 8, 2025
81cfc77
Merge pull request #573 from tremes/ou-1016-2
openshift-merge-bot[bot] Oct 8, 2025
5e0c1c0
fix: render short lived events
falox Oct 8, 2025
3477c9a
Merge pull request #581 from falox/render-short-events
openshift-merge-bot[bot] Oct 8, 2025
93319c8
Merge pull request #566 from openshift-bot/art-consistency-openshift-…
openshift-merge-bot[bot] Oct 8, 2025
e383fb1
fix: recalculate incident x values when filtering
tremes Oct 7, 2025
1ded62e
Merge pull request #580 from jgbernalp/add-additional-tls-configuration
openshift-merge-bot[bot] Oct 10, 2025
014f5b9
kubevirt installation cleanup working
etmurasaki Oct 10, 2025
815948b
Merge pull request #590 from etmurasaki/ou-999
openshift-merge-bot[bot] Oct 10, 2025
d2289d3
fix: use deterministic time ranges for incidents and alerts
falox Oct 10, 2025
da59937
Merge pull request #585 from falox/deterministic-time
openshift-merge-bot[bot] Oct 10, 2025
2884e56
Merge pull request #589 from tremes/ou-1022
openshift-merge-bot[bot] Oct 13, 2025
9f5a731
fix(Incidents): Add translations for all strings
DavidRajnoha Oct 2, 2025
369ef20
Merge pull request #570 from DavidRajnoha/OU-1024
openshift-merge-bot[bot] Oct 13, 2025
6dc5027
feat(cypress): improve incidents mocking
DavidRajnoha Oct 13, 2025
d6d9231
bvt monitoring namespace
etmurasaki Oct 6, 2025
c76f20e
fix: revert most of my previous changes & avoid flickering when chang…
tremes Oct 13, 2025
6e6c3d2
Merge pull request #594 from etmurasaki/ou-995
openshift-merge-bot[bot] Oct 14, 2025
a2df6b2
fix: resolve stale Redux state bug in incidents time range calculation
falox Oct 14, 2025
b704ae8
Merge pull request #596 from tremes/ou-1030
openshift-merge-bot[bot] Oct 14, 2025
55616dc
OCPBUGS-63056: Add favourites to Alerting page
logonoff Oct 14, 2025
6301772
OCPBUGS-63056: Add favourites to Dashboards page
logonoff Oct 14, 2025
5464e4f
OCPBUGS-63056: Add favourites to Metrics page
logonoff Oct 14, 2025
532bb5c
OCPBUGS-63061: Replace `react-helmet` with `DocumentTitle`
logonoff Oct 14, 2025
87cc403
Merge pull request #600 from logonoff/OCPBUGS-63056
openshift-merge-bot[bot] Oct 15, 2025
ff5509f
Merge pull request #598 from falox/fix-current-time
openshift-merge-bot[bot] Oct 15, 2025
0bba296
fix: close the first dropdown when deselecting incident
tremes Oct 14, 2025
4aa9dbe
Merge pull request #599 from tremes/ou-1033
openshift-merge-bot[bot] Oct 16, 2025
8f28ade
feat(cypress): add alert data collection to incidents page object
DavidRajnoha Oct 13, 2025
95aa9c6
Merge pull request #595 from DavidRajnoha/cypress-incidents-infrastru…
openshift-merge-bot[bot] Oct 20, 2025
c520eca
test(Incidents): Redux state management tests
DavidRajnoha Oct 17, 2025
45c3338
Merge pull request #606 from DavidRajnoha/ou-1033-test
openshift-merge-bot[bot] Oct 21, 2025
46dfe9c
Merge branch 'main' into release-coo-0.5
PeterYurkovich Oct 22, 2025
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
2 changes: 1 addition & 1 deletion .ci-operator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build_root_image:
name: release
namespace: openshift
tag: rhel-9-release-golang-1.24-openshift-4.20
tag: rhel-9-release-golang-1.24-openshift-4.21
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.devcontainer/dev.env
.DS_Store
web/cypress/screenshots/
web/cypress/export-env.sh
web/screenshots/
web/cypress/videos/
web/dist/
web/node_modules/
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.art
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/ocp/builder:rhel-9-base-nodejs-openshift-4.20 AS web-builder
FROM registry.ci.openshift.org/ocp/builder:rhel-9-base-nodejs-openshift-4.21 AS web-builder

# Copy app sources
COPY $REMOTE_SOURCES $REMOTE_SOURCES_DIR
Expand All @@ -17,7 +17,7 @@ RUN test -d ${REMOTE_SOURCES_DIR}/cachito-gomod-with-deps || exit 1; \
&& make build-frontend


FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.20 AS go-builder
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.21 AS go-builder

COPY $REMOTE_SOURCES $REMOTE_SOURCES_DIR
WORKDIR $REMOTE_SOURCES_DIR/cachito-gomod-with-deps/app
Expand All @@ -28,7 +28,7 @@ ENV CGO_ENABLED=1
RUN source $REMOTE_SOURCES_DIR/cachito-gomod-with-deps/cachito.env \
&& make build-backend BUILD_OPTS="-tags strictfipsruntime"

FROM registry.ci.openshift.org/ocp/4.20:base-rhel9
FROM registry.ci.openshift.org/ocp/4.21:base-rhel9

USER 1001

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ build-backend:
start-backend:
go run ./cmd/plugin-backend.go -port='9001' -config-path='./config' -static-path='./web/dist'

.PHONY: test-backend
test-backend:
go test ./pkg/... -v

.PHONY: build-image
build-image:
./scripts/build-image.sh
Expand Down
89 changes: 88 additions & 1 deletion cmd/plugin-backend.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"context"
"crypto/tls"
"flag"
"os"
"strconv"
Expand All @@ -21,6 +23,9 @@ var (
logLevelArg = flag.String("log-level", logrus.InfoLevel.String(), "verbosity of logs\noptions: ['panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace']\n'trace' level will log all incoming requests\n(default 'error')")
alertmanagerUrlArg = flag.String("alertmanager", "", "alertmanager url to proxy to for acm mode")
thanosQuerierUrlArg = flag.String("thanos-querier", "", "thanos querier url to proxy to for acm mode")
tlsMinVersionArg = flag.String("tls-min-version", "", "minimum TLS version\noptions: ['VersionTLS10', 'VersionTLS11', 'VersionTLS12', 'VersionTLS13']\n(default 'VersionTLS12')")
tlsMaxVersionArg = flag.String("tls-max-version", "", "maximum TLS version\noptions: ['VersionTLS10', 'VersionTLS11', 'VersionTLS12', 'VersionTLS13']\n(default is the highest supported by Go)")
tlsCipherSuitesArg = flag.String("tls-cipher-suites", "", "comma-separated list of cipher suites for the server\nvalues are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants)")
log = logrus.WithField("module", "main")
)

Expand All @@ -37,6 +42,9 @@ func main() {
logLevel := mergeEnvValue("MONITORING_PLUGIN_LOG_LEVEL", *logLevelArg, logrus.InfoLevel.String())
alertmanagerUrl := mergeEnvValue("MONITORING_PLUGIN_ALERTMANAGER", *alertmanagerUrlArg, "")
thanosQuerierUrl := mergeEnvValue("MONITORING_PLUGIN_THANOS_QUERIER", *thanosQuerierUrlArg, "")
tlsMinVersion := mergeEnvValue("TLS_MIN_VERSION", *tlsMinVersionArg, "")
tlsMaxVersion := mergeEnvValue("TLS_MAX_VERSION", *tlsMaxVersionArg, "")
tlsCipherSuites := mergeEnvValue("TLS_CIPHER_SUITES", *tlsCipherSuitesArg, "")

featuresList := strings.Fields(strings.Join(strings.Split(strings.ToLower(features), ","), " "))

Expand All @@ -54,7 +62,12 @@ func main() {

log.Infof("enabled features: %+q\n", featuresList)

server.Start(&server.Config{
// Parse TLS configuration
tlsMinVer := parseTLSVersion(tlsMinVersion)
tlsMaxVer := parseTLSVersion(tlsMaxVersion)
tlsCiphers := parseCipherSuites(tlsCipherSuites)

srv, err := server.CreateServer(context.Background(), &server.Config{
Port: port,
CertFile: cert,
PrivateKeyFile: key,
Expand All @@ -64,7 +77,18 @@ func main() {
PluginConfigPath: pluginConfigPath,
AlertmanagerUrl: alertmanagerUrl,
ThanosQuerierUrl: thanosQuerierUrl,
TLSMinVersion: tlsMinVer,
TLSMaxVersion: tlsMaxVer,
TLSCipherSuites: tlsCiphers,
})

if err != nil {
panic(err)
}

if err = srv.StartHTTPServer(); err != nil {
panic(err)
}
}

func mergeEnvValue(key string, arg string, defaultValue string) string {
Expand Down Expand Up @@ -95,3 +119,66 @@ func mergeEnvValueInt(key string, arg int, defaultValue int) int {

return defaultValue
}

func getCipherSuitesMap() map[string]uint16 {
result := make(map[string]uint16)

for _, suite := range tls.CipherSuites() {
result[suite.Name] = suite.ID
}

return result
}

func getTLSVersionsMap() map[string]uint16 {
versions := make(map[string]uint16)

versions["VersionTLS12"] = tls.VersionTLS12
versions["VersionTLS13"] = tls.VersionTLS13

return versions
}

func parseTLSVersion(version string) uint16 {
if version == "" {
return tls.VersionTLS12
}

tlsVersions := getTLSVersionsMap()

if v, ok := tlsVersions[version]; ok {
return v
}

log.Warnf("Invalid TLS version %q, using default VersionTLS12", version)
return tls.VersionTLS12
}

func parseCipherSuites(ciphers string) []uint16 {
if ciphers == "" {
return nil
}

cipherMap := getCipherSuitesMap()

cipherNames := strings.Split(strings.ReplaceAll(ciphers, " ", ""), ",")
var result []uint16

for _, name := range cipherNames {
if name == "" {
continue
}
if cipher, ok := cipherMap[name]; ok {
result = append(result, cipher)
} else {
log.Warnf("Unknown cipher suite %q, skipping", name)
}
}

if len(result) == 0 {
log.Warn("No valid cipher suites provided, using Go defaults")
return nil
}

return result
}
121 changes: 92 additions & 29 deletions pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ type Config struct {
PluginConfigPath string
AlertmanagerUrl string
ThanosQuerierUrl string
TLSMinVersion uint16
TLSMaxVersion uint16
TLSCipherSuites []uint16
}

func (c *Config) IsTLSEnabled() bool {
return c.CertFile != "" && c.PrivateKeyFile != ""
}

type PluginServer struct {
*http.Server
Config *Config
}

type PluginConfig struct {
Expand All @@ -61,19 +73,47 @@ func (pluginConfig *PluginConfig) MarshalJSON() ([]byte, error) {
})
}

func Start(cfg *Config) {
func CreateServer(ctx context.Context, cfg *Config) (*PluginServer, error) {
httpServer, err := createHTTPServer(ctx, cfg)
if err != nil {
return nil, err
}

return &PluginServer{
Config: cfg,
Server: httpServer,
}, nil
}

func (s *PluginServer) StartHTTPServer() error {
if s.Config.IsTLSEnabled() {
log.Infof("listening for https on %s", s.Server.Addr)
return s.Server.ListenAndServeTLS(s.Config.CertFile, s.Config.PrivateKeyFile)
}
log.Infof("listening for http on %s", s.Server.Addr)
return s.Server.ListenAndServe()
}

func (s *PluginServer) Shutdown(ctx context.Context) error {
if s.Server != nil {
return s.Server.Shutdown(ctx)
}
return nil
}

func createHTTPServer(ctx context.Context, cfg *Config) (*http.Server, error) {
acmMode := cfg.Features[AcmAlerting]
acmLocationsLength := len(cfg.AlertmanagerUrl) + len(cfg.ThanosQuerierUrl)

if acmLocationsLength > 0 && !acmMode {
log.Panic("alertmanager and thanos-querier cannot be set without the 'acm-alerting' feature flag")
return nil, fmt.Errorf("alertmanager and thanos-querier cannot be set without the 'acm-alerting' feature flag")
}
if acmLocationsLength == 0 && acmMode {
log.Panic("alertmanager and thanos-querier must be set to use the 'acm-alerting' feature flag")
return nil, fmt.Errorf("alertmanager and thanos-querier must be set to use the 'acm-alerting' feature flag")
}

if cfg.Port == int(proxy.AlertmanagerPort) || cfg.Port == int(proxy.ThanosQuerierPort) {
log.Panic(fmt.Printf("Cannot set default port to reserved port %d", cfg.Port))
return nil, fmt.Errorf("cannot set default port to reserved port %d", cfg.Port)
}

// Uncomment the following line for local development:
Expand All @@ -86,12 +126,12 @@ func Start(cfg *Config) {
k8sconfig, err := rest.InClusterConfig()

if err != nil {
panic(fmt.Errorf("cannot get in cluster config: %w", err))
return nil, fmt.Errorf("cannot get in cluster config: %w", err)
}

k8sclient, err = dynamic.NewForConfig(k8sconfig)
if err != nil {
panic(fmt.Errorf("error creating dynamicClient: %w", err))
return nil, fmt.Errorf("error creating dynamicClient: %w", err)
}
} else {
k8sclient = nil
Expand All @@ -100,15 +140,27 @@ func Start(cfg *Config) {
router, pluginConfig := setupRoutes(cfg)
router.Use(corsHeaderMiddleware())

tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
}
tlsEnabled := cfg.CertFile != "" && cfg.PrivateKeyFile != ""
tlsConfig := &tls.Config{}

tlsEnabled := cfg.IsTLSEnabled()
if tlsEnabled {
// Set MinVersion - default to TLS 1.2 if not specified
if cfg.TLSMinVersion != 0 {
tlsConfig.MinVersion = cfg.TLSMinVersion
} else {
tlsConfig.MinVersion = tls.VersionTLS12
}

if cfg.TLSMaxVersion != 0 {
tlsConfig.MaxVersion = cfg.TLSMaxVersion
}

if len(cfg.TLSCipherSuites) > 0 {
tlsConfig.CipherSuites = cfg.TLSCipherSuites
}

// Build and run the controller which reloads the certificate and key
// files whenever they change.
ctx := context.Background()

certKeyPair, err := dynamiccertificates.NewDynamicServingContentFromFiles("serving-cert", cfg.CertFile, cfg.PrivateKeyFile)
if err != nil {
log.WithError(err).Fatal("unable to create TLS controller")
Expand Down Expand Up @@ -138,6 +190,7 @@ func Start(cfg *Config) {
// Notify cert/key file changes to the controller.
certKeyPair.AddListener(ctrl)

// Start certificate controllers in background
go ctrl.Run(1, ctx.Done())
go certKeyPair.Run(ctx, 1)
}
Expand All @@ -160,18 +213,13 @@ func Start(cfg *Config) {
httpServer.Handler = loggedRouter
}

if tlsEnabled {
if acmMode {
startProxy(cfg, k8sclient, tlsConfig, timeout, proxy.AlertManagerKind, proxy.AlertmanagerPort)
startProxy(cfg, k8sclient, tlsConfig, timeout, proxy.ThanosQuerierKind, proxy.ThanosQuerierPort)
}

log.Infof("listening for https on %s", httpServer.Addr)
panic(httpServer.ListenAndServeTLS(cfg.CertFile, cfg.PrivateKeyFile))
} else {
log.Infof("listening for http on %s", httpServer.Addr)
panic(httpServer.ListenAndServe())
// Start proxy servers if in ACM mode
if tlsEnabled && acmMode {
startProxy(cfg, k8sclient, tlsConfig, timeout, proxy.AlertManagerKind, proxy.AlertmanagerPort)
startProxy(cfg, k8sclient, tlsConfig, timeout, proxy.ThanosQuerierKind, proxy.ThanosQuerierPort)
}

return httpServer, nil
}

func setupRoutes(cfg *Config) (*mux.Router, *PluginConfig) {
Expand Down Expand Up @@ -210,17 +258,32 @@ func setupProxyRoutes(cfg *Config, k8sclient *dynamic.DynamicClient, kind proxy.
return router
}

func filesHandler(root http.FileSystem) http.Handler {
fileServer := http.FileServer(root)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
filePath := r.URL.Path
type headerPreservingWriter struct {
http.ResponseWriter
wroteHeader bool
}

// disable caching for plugin entry point
if strings.HasPrefix(filePath, "/plugin-entry.js") {
func (w *headerPreservingWriter) WriteHeader(statusCode int) {
if !w.wroteHeader {
if w.Header().Get("Cache-Control") == "" {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
}
if w.Header().Get("Expires") == "" {
w.Header().Set("Expires", "0")
}
w.wroteHeader = true
}
w.ResponseWriter.WriteHeader(statusCode)
}

func filesHandler(root http.FileSystem) http.Handler {
fileServer := http.FileServer(root)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// disable caching for plugin entry point
if strings.HasPrefix(r.URL.Path, "/plugin-entry.js") {
fileServer.ServeHTTP(&headerPreservingWriter{ResponseWriter: w}, r)
return
}
fileServer.ServeHTTP(w, r)
})
}
Expand Down
Loading