K8s: expose namespace in frontend_settings (#78090)

Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com>
pull/77978/head
Ryan McKinley 2 years ago committed by GitHub
parent 1be1432926
commit ea37a116f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      packages/grafana-data/src/types/config.ts
  2. 1
      packages/grafana-runtime/src/config.ts
  3. 3
      pkg/api/dtos/frontend_settings.go
  4. 3
      pkg/api/frontendsettings.go
  5. 2
      pkg/api/frontendsettings_test.go
  6. 3
      pkg/api/http_server.go
  7. 4
      public/app/features/playlist/api.ts

@ -221,6 +221,9 @@ export interface GrafanaConfig {
rudderstackConfigUrl: string | undefined;
rudderstackIntegrationsUrl: string | undefined;
sqlConnectionLimits: SqlConnectionLimits;
// The namespace to use for kubernetes apiserver requests
namespace: string;
}
export interface SqlConnectionLimits {

@ -44,6 +44,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
minRefreshInterval = '';
appUrl = '';
appSubUrl = '';
namespace = 'default';
windowTitlePrefix = '';
buildInfo: BuildInfo;
newPanelTitle = '';

@ -230,6 +230,9 @@ type FrontendSettingsDTO struct {
LoginError string `json:"loginError,omitempty"`
// The K8s namespace to use for this user
Namespace string `json:"namespace,omitempty"`
PluginsCDNBaseURL string `json:"pluginsCDNBaseURL,omitempty"`
SqlConnectionLimits FrontendSettingsSqlConnectionLimitsDTO `json:"sqlConnectionLimits"`

@ -274,6 +274,9 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
frontendSettings.GeomapDisableCustomBaseLayer = true
}
// Set the kubernetes namespace
frontendSettings.Namespace = hs.namespacer(c.SignedInUser.OrgID)
return frontendSettings, nil
}

@ -20,6 +20,7 @@ import (
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/grafana-apiserver/endpoints/request"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
@ -75,6 +76,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg, features *featuremgmt.
PluginsCDNURLTemplate: cfg.PluginsCDNURLTemplate,
PluginSettings: cfg.PluginSettings,
}),
namespacer: request.GetNamespaceMapper(cfg),
SocialService: social.ProvideService(cfg, features, &usagestats.UsageStatsMock{}, supportbundlestest.NewFakeBundleService(), remotecache.NewFakeCacheStorage()),
}

@ -17,6 +17,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
grafanaapiserver "github.com/grafana/grafana/pkg/services/grafana-apiserver"
"github.com/grafana/grafana/pkg/services/grafana-apiserver/endpoints/request"
"github.com/grafana/grafana/pkg/api/avatar"
"github.com/grafana/grafana/pkg/api/routing"
@ -206,6 +207,7 @@ type HTTPServer struct {
starApi *starApi.API
promRegister prometheus.Registerer
clientConfigProvider grafanaapiserver.DirectRestConfigProvider
namespacer request.NamespaceMapper
}
type ServerOptions struct {
@ -348,6 +350,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
starApi: starApi,
promRegister: promRegister,
clientConfigProvider: clientConfigProvider,
namespacer: request.GetNamespaceMapper(cfg),
}
if hs.Listener != nil {
hs.log.Debug("Using provided listener")

@ -4,7 +4,6 @@ import { DataQueryRequest, DataFrameView } from '@grafana/data';
import { getBackendSrv, config } from '@grafana/runtime';
import { notifyApp } from 'app/core/actions';
import { createErrorNotification, createSuccessNotification } from 'app/core/copy/appNotification';
import { contextSrv } from 'app/core/services/context_srv';
import { getGrafanaDatasource } from 'app/plugins/datasource/grafana/datasource';
import { GrafanaQuery, GrafanaQueryType } from 'app/plugins/datasource/grafana/types';
import { dispatch } from 'app/store/store';
@ -59,8 +58,7 @@ class K8sAPI implements PlaylistAPI {
readonly url: string;
constructor() {
const ns = contextSrv.user.orgId === 1 ? 'default' : `org-${contextSrv.user.orgId}`;
this.url = `/apis/${this.apiVersion}/namespaces/${ns}/playlists`;
this.url = `/apis/${this.apiVersion}/namespaces/${config.namespace}/playlists`;
}
async getAllPlaylist(): Promise<Playlist[]> {

Loading…
Cancel
Save