Skip to content

Commit

Permalink
hide namespaces via settings
Browse files Browse the repository at this point in the history
(cherry picked from commit 534a365efcf56aa7b3592b55e0885d021f97688c)
  • Loading branch information
avanish23 committed Oct 17, 2024
1 parent 1b58a29 commit 526683e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions charts/kubernetes-dashboard/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ app:
# resourceAutoRefreshTimeInterval: 10
# # Hide all access denied warnings in the notification panel
# disableAccessDeniedNotifications: false
# # Hide all namespaces option in namespace selection dropdown to avoid accidental selection in large clusters thus preventing OOM errors
# hideAllNamespaces: false
# # Namespace that should be selected by default after logging in.
# defaultNamespace: default
# # List of namespaces that should be presented to user without namespace list privileges.
Expand Down
2 changes: 2 additions & 0 deletions modules/web/pkg/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var defaultSettings = Settings{
LogsAutoRefreshTimeInterval: lo.ToPtr(5),
ResourceAutoRefreshTimeInterval: lo.ToPtr(10),
DisableAccessDeniedNotifications: lo.ToPtr(false),
HideAllNamespaces: lo.ToPtr(false),
DefaultNamespace: lo.ToPtr("default"),
NamespaceFallbackList: []string{"default"},
}
Expand All @@ -39,6 +40,7 @@ type Settings struct {
LogsAutoRefreshTimeInterval *int `json:"logsAutoRefreshTimeInterval,omitempty"`
ResourceAutoRefreshTimeInterval *int `json:"resourceAutoRefreshTimeInterval,omitempty"`
DisableAccessDeniedNotifications *bool `json:"disableAccessDeniedNotifications,omitempty"`
HideAllNamespaces *bool `json:"hideAllNamespaces,omitempty"`
DefaultNamespace *string `json:"defaultNamespace,omitempty"`
NamespaceFallbackList []string `json:"namespaceFallbackList,omitempty"`
}
Expand Down
4 changes: 4 additions & 0 deletions modules/web/src/common/components/namespace/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export class NamespaceSelectorComponent implements OnInit {
this.loadNamespaces_();
}

showAllNamespaces(): boolean {
return !this.settingsService_.getHideAllNamespaces().valueOf
}

selectNamespace(): void {
if (this.selectNamespaceInput.length === 0) {
return;
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/common/components/namespace/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/>
</div>
<mat-option
*ngIf="namespaces.length && !usingFallbackNamespaces"
*ngIf="showAllNamespaces() && namespaces.length && !usingFallbackNamespaces"
[value]="allNamespacesKey"
i18n
>All namespaces</mat-option
Expand Down
5 changes: 5 additions & 0 deletions modules/web/src/common/services/global/globalsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const DEFAULT_SETTINGS: GlobalSettings = {
logsAutoRefreshTimeInterval: 5,
resourceAutoRefreshTimeInterval: 5,
disableAccessDeniedNotifications: false,
hideAllNamespaces: false,
defaultNamespace: 'default',
namespaceFallbackList: ['default'],
};
Expand Down Expand Up @@ -130,6 +131,10 @@ export class GlobalSettingsService {
return this.settings_.disableAccessDeniedNotifications;
}

getHideAllNamespaces(): boolean {
return this.settings_.hideAllNamespaces
}

getDefaultNamespace(): string {
return this.settings_.defaultNamespace;
}
Expand Down
6 changes: 6 additions & 0 deletions modules/web/src/settings/global/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum Controls {
ResourceAutorefreshInterval = 'resourceAutorefreshInterval',
DisableAccessDeniedNotification = 'disableAccessDeniedNotification',
NamespaceSettings = 'namespaceSettings',
HideAllNamespaces = 'hideAllNamespaces'
}

@Component({
Expand Down Expand Up @@ -90,6 +91,7 @@ export class GlobalSettingsComponent implements OnInit {
[Controls.LogsAutorefreshInterval]: this.builder_.control(0),
[Controls.ResourceAutorefreshInterval]: this.builder_.control(0),
[Controls.DisableAccessDeniedNotification]: this.builder_.control(false),
[Controls.HideAllNamespaces]: this.builder_.control(false),
[Controls.NamespaceSettings]: this.builder_.control(''),
});

Expand Down Expand Up @@ -180,6 +182,9 @@ export class GlobalSettingsComponent implements OnInit {
this.form
.get(Controls.DisableAccessDeniedNotification)
.setValue(this.settings.disableAccessDeniedNotifications, {emitEvent: false});
this.form
.get(Controls.HideAllNamespaces)
.setValue(this.settings.hideAllNamespaces, {emitEvent: false});
}

private onLoadError_(): void {
Expand All @@ -191,6 +196,7 @@ export class GlobalSettingsComponent implements OnInit {
itemsPerPage: this.form.get(Controls.ItemsPerPage).value,
clusterName: this.form.get(Controls.ClusterName).value,
disableAccessDeniedNotifications: this.form.get(Controls.DisableAccessDeniedNotification).value,
hideAllNamespaces: this.form.get(Controls.HideAllNamespaces).value,
labelsLimit: this.form.get(Controls.LabelsLimit).value,
logsAutoRefreshTimeInterval: this.form.get(Controls.LogsAutorefreshInterval).value,
resourceAutoRefreshTimeInterval: this.form.get(Controls.ResourceAutorefreshInterval).value,
Expand Down
18 changes: 18 additions & 0 deletions modules/web/src/settings/global/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@
</mat-slide-toggle>
</div>
</kd-settings-entry>
<kd-settings-entry
key="Disable access denied notification"
i18n-key
desc="Hides all-namespaces option from the namespaces dropdown list in UI."
i18n-desc
>
<div
fxFlex
fxLayoutAlign=" center"
>
<mat-slide-toggle
color="primary"
name="hideAllNamespaces"
[formControlName]="Controls.HideAllNamespaces"
>
</mat-slide-toggle>
</div>
</kd-settings-entry>
<br /><br />
<button
[disabled]="!canSave()"
Expand Down
1 change: 1 addition & 0 deletions modules/web/src/typings/root.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ export interface GlobalSettings {
logsAutoRefreshTimeInterval: number;
resourceAutoRefreshTimeInterval: number;
disableAccessDeniedNotifications: boolean;
hideAllNamespaces: boolean;
defaultNamespace: string;
namespaceFallbackList: string[];
}
Expand Down

0 comments on commit 526683e

Please sign in to comment.