diff --git a/Makefile b/Makefile index b3b14b933..0f609107e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ install-frontend: .PHONY: install-frontend-ci install-frontend-ci: - cd web && npm ci + cd web && npm ci --ignore-scripts .PHONY: install-frontend-ci-clean install-frontend-ci-clean: install-frontend-ci @@ -40,6 +40,10 @@ install-backend: build-backend: go build $(BUILD_OPTS) -mod=readonly -o plugin-backend -mod=readonly cmd/plugin-backend.go +.PHONY: build-backend-dev +build-backend-dev: + GOARCH=amd64 GOOS=linux go build -mod=readonly -o plugin-backend -mod=readonly cmd/plugin-backend.go + .PHONY: test-unit-backend test-unit-backend: go test ./... diff --git a/config/clear-extensions.patch.json b/config/clear-extensions.patch.json new file mode 100644 index 000000000..bd9d60091 --- /dev/null +++ b/config/clear-extensions.patch.json @@ -0,0 +1,45 @@ +[ + { + "op": "replace", + "path": "/extensions", + "value": [ + { + "type": "console.page/route", + "properties": { + "exact": true, + "path": "/monitoring/logs", + "component": { + "$codeRef": "LogsPage" + } + } + }, + { + "type": "console.navigation/href", + "properties": { + "id": "monitoring-logs", + "name": "Logs", + "href": "/monitoring/logs", + "perspective": "admin", + "section": "observe" + } + }, + { + "type": "console.tab/horizontalNav", + "properties": { + "page": { + "name": "%plugin__logging-view-plugin~Aggregated Logs%", + "href": "aggregated-logs" + }, + "model": { + "group": "core", + "version": "v1", + "kind": "Pod" + }, + "component": { + "$codeRef": "LogsDetailPage" + } + } + } + ] + } +] diff --git a/config/plugin-manifest.json b/config/plugin-manifest.json deleted file mode 100644 index 8d25ae867..000000000 --- a/config/plugin-manifest.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "logging-view-plugin", - "version": "0.0.1", - "displayName": "Logging View Plugin", - "description": "This plugin adds the logs UI to OpenShift console", - "dependencies": { - "@console/pluginAPI": "*" - }, - "extensions": [ - { - "type": "console.page/route", - "properties": { - "exact": true, - "path": "/monitoring/logs", - "component": { - "$codeRef": "LogsPage" - } - } - }, - { - "type": "console.navigation/href", - "properties": { - "id": "monitoring-logs", - "name": "Logs", - "href": "/monitoring/logs", - "perspective": "admin", - "section": "observe" - } - }, - { - "type": "console.tab/horizontalNav", - "properties": { - "page": { - "name": "%plugin__logging-view-plugin~Aggregated Logs%", - "href": "aggregated-logs" - }, - "model": { - "group": "core", - "version": "v1", - "kind": "Pod" - }, - "component": { - "$codeRef": "LogsDetailPage" - } - } - } - ] -} diff --git a/logging-view-plugin-resources.yml b/logging-view-plugin-resources.yml index 34e4a4565..bc25838f0 100644 --- a/logging-view-plugin-resources.yml +++ b/logging-view-plugin-resources.yml @@ -51,6 +51,8 @@ spec: - "-cert=/var/serving-cert/tls.crt" - "-key=/var/serving-cert/tls.key" - "-plugin-config-path=/etc/plugin/config.yaml" + - "-static-path=/opt/app-root/web/dist" + - "-config-path=/opt/app-root/config" securityContext: allowPrivilegeEscalation: false capabilities: diff --git a/pkg/server/manifest_handler.go b/pkg/server/manifest_handler.go index f458a79cb..b12024364 100644 --- a/pkg/server/manifest_handler.go +++ b/pkg/server/manifest_handler.go @@ -13,7 +13,7 @@ import ( var mlog = logrus.WithField("module", "manifest") func manifestHandler(cfg *Config) http.HandlerFunc { - baseManifestData, err := os.ReadFile(filepath.Join(cfg.ConfigPath, "plugin-manifest.json")) + baseManifestData, err := os.ReadFile(filepath.Join(cfg.StaticPath, "plugin-manifest.json")) if err != nil { mlog.WithError(err).Error("cannot read base manifest file") return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -21,27 +21,38 @@ func manifestHandler(cfg *Config) http.HandlerFunc { }) } + patchedManifest := patchManifest(baseManifestData, cfg) + + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + w.Header().Set("Expires", "0") + + w.Write(patchedManifest) + }) +} + +func patchManifest(baseManifestData []byte, cfg *Config) []byte { + if len(cfg.Features) == 0 { + return baseManifestData + } + patchedManifest := baseManifestData + patchedManifest = performPatch(baseManifestData, filepath.Join(cfg.ConfigPath, "clear-extensions.patch.json")) // Add alert charts if any of the alert features are enabled if cfg.Features["alerts"] || cfg.Features["dev-alerts"] { - patchedManifest = patchManifest(patchedManifest, filepath.Join(cfg.ConfigPath, "alerts-charts.patch.json")) + patchedManifest = performPatch(patchedManifest, filepath.Join(cfg.ConfigPath, "alerts-charts.patch.json")) } for k := range cfg.Features { - patchedManifest = patchManifest(patchedManifest, filepath.Join(cfg.ConfigPath, fmt.Sprintf("%s.patch.json", k))) + patchedManifest = performPatch(patchedManifest, filepath.Join(cfg.ConfigPath, fmt.Sprintf("%s.patch.json", k))) } - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") - w.Header().Set("Expires", "0") - - w.Write(patchedManifest) - }) + return []byte(patchedManifest) } -func patchManifest(originalData []byte, patchFilePath string) []byte { +func performPatch(originalData []byte, patchFilePath string) []byte { patchData, err := os.ReadFile(patchFilePath) if err != nil { mlog.WithField("reason", err).Warnf("cannot read patch file %s", patchFilePath)