Skip to content

Commit

Permalink
Remove unnecessary apiServiceURL from dashboard config (#1958)
Browse files Browse the repository at this point in the history
* Add kubeappsCluster and reduce clusters config to just names.

* Further reduce clusters config to string[]

* Update chart to send just cluster names.
  • Loading branch information
absoludity committed Aug 26, 2020
1 parent b7eb259 commit a6d2ce7
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 37 deletions.
5 changes: 3 additions & 2 deletions chart/kubeapps/templates/dashboard-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ data:
}
config.json: |-
{
"namespace": "{{ .Release.Namespace }}",
"kubeappsCluster": "default",
"kubeappsNamespace": "{{ .Release.Namespace }}",
"appVersion": "{{ .Chart.AppVersion }}",
"authProxyEnabled": {{ .Values.authProxy.enabled }},
"oauthLoginURI": {{ .Values.authProxy.oauthLoginURI | quote }},
"oauthLogoutURI": {{ .Values.authProxy.oauthLogoutURI | quote }},
"featureFlags": {{ .Values.featureFlags | toJson }},
{{- $sanitizedClusters := list }}
{{- range .Values.clusters }}
{{- $sanitizedClusters = append $sanitizedClusters (pick . "name" "apiServiceURL") }}
{{- $sanitizedClusters = append $sanitizedClusters .name }}
{{- end }}
"clusters": {{ $sanitizedClusters | toJson }}
}
3 changes: 2 additions & 1 deletion dashboard/public/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"namespace": "default",
"kubeapsCluster": "default",
"kubeappsNamespace": "kubeapps",
"appVersion": "DEVEL",
"authProxyEnabled": false,
"oauthLoginURI": "/oauth2/start",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/actions/repos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:

beforeEach(() => {
store = mockStore({
config: { namespace: kubeappsNamespace },
config: { kubeappsNamespace },
clusters: {
currentCluster: "default",
clusters: {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/actions/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function parsePodTemplate(syncJobPodTemplate: string) {
function getTargetNS(getState: () => IStoreState, namespace: string) {
let target = namespace;
const {
config: { namespace: kubeappsNamespace },
config: { kubeappsNamespace },
} = getState();
if (namespace === definedNamespaces.all) {
target = kubeappsNamespace;
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/containers/AppNewContainer/AppNewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ function mapStateToProps(
) {
return {
chartID: `${params.repo}/${params.id}`,
chartNamespace: params.global === "global" ? config.namespace : params.namespace,
chartNamespace: params.global === "global" ? config.kubeappsNamespace : params.namespace,
cluster: params.cluster,
chartVersion: params.version,
error: apps.error,
kubeappsNamespace: config.namespace,
kubeappsNamespace: config.kubeappsNamespace,
namespace: params.namespace,
selected: charts.selected,
chartsIsFetching: charts.isFetching,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function mapStateToProps(
reposIsFetching: repos.isFetching,
appsError: apps.error,
chartsError: charts.selected.error,
kubeappsNamespace: config.namespace,
kubeappsNamespace: config.kubeappsNamespace,
namespace: params.namespace,
cluster: params.cluster,
releaseName: params.releaseName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function mapStateToProps(
csvs: operators.csvs,
cluster: params.cluster,
namespace: params.namespace,
kubeappsNamespace: config.namespace,
kubeappsNamespace: config.kubeappsNamespace,
featureFlags: config.featureFlags,
UI: config.featureFlags.ui,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface IRouteProps {
function mapStateToProps({ charts, config }: IStoreState, { match: { params } }: IRouteProps) {
return {
chartID: chartID(params),
chartNamespace: params.global === "global" ? config.namespace : params.namespace,
chartNamespace: params.global === "global" ? config.kubeappsNamespace : params.namespace,
isFetching: charts.isFetching,
cluster: params.cluster,
namespace: params.namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const makeStore = (
authProxyEnabled,
oauthLoginURI,
loaded: true,
namespace: "",
kubeappsCluster: "",
kubeappsNamespace: "",
appVersion: "",
oauthLogoutURI: "",
featureFlags: { operators: false, ui: "hex" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function mapStateToProps({ config, clusters: { currentCluster, clusters }, repos
repoSecrets: repos.repoSecrets,
validating: repos.validating,
imagePullSecrets: repos.imagePullSecrets,
kubeappsNamespace: config.namespace,
kubeappsNamespace: config.kubeappsNamespace,
UI: config.featureFlags.ui,
};
}
Expand Down
14 changes: 3 additions & 11 deletions dashboard/src/reducers/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,24 +309,16 @@ describe("clusterReducer", () => {

context("when RECEIVE_CONFIG", () => {
const config = {
namespace: "kubeapps",
kubeappsNamespace: "kubeapps",
appVersion: "dev",
authProxyEnabled: false,
oauthLoginURI: "",
oauthLogoutURI: "",
featureFlags: {
operators: false,
ui: "hex",
},
clusters: [
{
name: "additionalCluster1",
apiServiceURL: "https://not-used-by-dashboard.example.com/",
},
{
name: "additionalCluster2",
apiServiceURL: "https://not-used-by-dashboard.example.com/",
},
],
clusters: ["additionalCluster1", "additionalCluster2"],
} as IConfig;
it("adds the additional clusters to the clusters state", () => {
expect(
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/reducers/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const clusterReducer = (
};
const config = action.payload as IConfig;
config.clusters?.forEach(cluster => {
clusters[cluster.name] = {
clusters[cluster] = {
currentNamespace: "default",
namespaces: [],
};
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/reducers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export interface IConfigState extends IConfig {

const initialState: IConfigState = {
loaded: false,
namespace: "",
kubeappsCluster: "",
kubeappsNamespace: "",
appVersion: "",
authProxyEnabled: false,
oauthLoginURI: "",
Expand Down
6 changes: 4 additions & 2 deletions dashboard/src/shared/Auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ describe("Auth", () => {
oauthLoginURI: "",
authProxyEnabled: true,
oauthLogoutURI,
namespace: "ns",
kubeappsCluster: "default",
kubeappsNamespace: "ns",
appVersion: "2",
featureFlags: { operators: false, ui: "hex" },
clusters: [],
Expand All @@ -181,7 +182,8 @@ describe("Auth", () => {
oauthLoginURI: "",
authProxyEnabled: true,
oauthLogoutURI: "",
namespace: "ns",
kubeappsCluster: "default",
kubeappsNamespace: "ns",
appVersion: "2",
featureFlags: { operators: false, ui: "hex" },
clusters: [],
Expand Down
5 changes: 4 additions & 1 deletion dashboard/src/shared/Config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ describe("Config", () => {

it("returns the overriden namespace if env variable provided", async () => {
process.env.REACT_APP_KUBEAPPS_NS = "magic-playground";
expect(await Config.getConfig()).toEqual({ ...defaultJSON, namespace: "magic-playground" });
expect(await Config.getConfig()).toEqual({
...defaultJSON,
kubeappsNamespace: "magic-playground",
});
});

it("does not returns the overriden namespace if NODE_ENV=production", async () => {
Expand Down
13 changes: 4 additions & 9 deletions dashboard/src/shared/Config.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import axios from "axios";

interface ICluster {
name: string;
apiServiceURL: string;
certificateAuthorityData?: string;
}

export interface IFeatureFlags {
operators: boolean;
ui: string;
}

// IConfig is the configuration for Kubeapps
export interface IConfig {
namespace: string;
kubeappsCluster: string;
kubeappsNamespace: string;
appVersion: string;
authProxyEnabled: boolean;
oauthLoginURI: string;
oauthLogoutURI: string;
error?: Error;
featureFlags: IFeatureFlags;
clusters: ICluster[];
clusters: string[];
}

export default class Config {
Expand All @@ -35,7 +30,7 @@ export default class Config {
if (process.env.NODE_ENV !== "production") {
data.appVersion = "DEVEL";
if (process.env.REACT_APP_KUBEAPPS_NS) {
data.namespace = process.env.REACT_APP_KUBEAPPS_NS;
data.kubeappsNamespace = process.env.REACT_APP_KUBEAPPS_NS;
}
}

Expand Down

0 comments on commit a6d2ce7

Please sign in to comment.