Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for configuring default namespace #3334

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions cmd/dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ var (
kubeConfigPath = flag.String("kube-config", "", "Path to kube config file")
portNumber = flag.Int("port", 8080, "Dashboard port number")
readOnly = flag.Bool("read-only", true, "Enable or disable read-only mode")
logoutURL = flag.String("logout-url", "", "If set, enables logout on the frontend and binds the logout button to this url")
logoutURL = flag.String("logout-url", "", "If set, enables logout on the frontend and binds the logout button to this URL")
defaultNamespace = flag.String("default-namespace", "", "If set, configures the default selected namespace to the provided namespace instead of 'All Namespaces'")
tenantNamespaces = flag.String("namespaces", "", "If set, limits the scope of resources displayed to this comma-separated list of namespaces only")
logLevel = flag.String("log-level", "info", "Minimum log level output by the logger")
logFormat = flag.String("log-format", "json", "Format for log output (json or console)")
streamLogs = flag.Bool("stream-logs", true, "Enable log streaming instead of polling")
externalLogs = flag.String("external-logs", "", "External logs provider url")
externalLogs = flag.String("external-logs", "", "External logs provider URL")
xFrameOptions = flag.String("x-frame-options", "DENY", "Value for the X-Frame-Options response header, set '' to omit it")
)

Expand Down Expand Up @@ -91,6 +92,7 @@ func main() {
PipelinesNamespace: *pipelinesNamespace,
TriggersNamespace: *triggersNamespace,
TenantNamespaces: tenants,
DefaultNamespace: *defaultNamespace,
ReadOnly: *readOnly,
LogoutURL: *logoutURL,
StreamLogs: *streamLogs,
Expand Down
3 changes: 2 additions & 1 deletion docs/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ These options are documented below:
| `--triggers-namespace` | Namespace where Tekton triggers is installed (assumes same namespace as dashboard if not set) | `string` | `""` |
| `--port` | Dashboard port number | `int` | `8080` |
| `--read-only` | Enable or disable read-only mode | `bool` | `true` |
| `--logout-url` | If set, enables logout on the frontend and binds the logout button to this url | `string` | `""` |
| `--logout-url` | If set, enables logout on the frontend and binds the logout button to this URL | `string` | `""` |
| `--default-namespace` | If set, configures the default selected namespace to the provided namespace instead of 'All Namespaces' | `string` | `""` |
| `--namespaces` | If set, limits the scope of resources displayed to this comma-separated list of namespaces only | `string` | `""` |
| `--log-level` | Minimum log level output by the logger | `string` | `"info"` |
| `--log-format` | Format for log output (json or console) | `string` | `"json"` |
Expand Down
4 changes: 4 additions & 0 deletions overlays/patches/installer/deployment-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
path: /spec/template/spec/containers/0/args/-
value:
--log-format=--log-format
- op: add
path: /spec/template/spec/containers/0/args/-
value:
--default-namespace=--default-namespace
- op: add
path: /spec/template/spec/containers/0/args/-
value:
Expand Down
4 changes: 3 additions & 1 deletion pkg/endpoints/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import (
type Properties struct {
DashboardNamespace string `json:"dashboardNamespace"`
DashboardVersion string `json:"dashboardVersion"`
DefaultNamespace string `json:"defaultNamespace,omitempty"`
ExternalLogsURL string `json:"externalLogsURL"`
LogoutURL string `json:"logoutURL,omitempty"`
PipelineNamespace string `json:"pipelinesNamespace"`
PipelineVersion string `json:"pipelinesVersion"`
ReadOnly bool `json:"isReadOnly"`
StreamLogs bool `json:"streamLogs"`
TenantNamespaces []string `json:"tenantNamespaces,omitEmpty"`
TenantNamespaces []string `json:"tenantNamespaces,omitempty"`
TriggersNamespace string `json:"triggersNamespace,omitempty"`
TriggersVersion string `json:"triggersVersion,omitempty"`
}
Expand All @@ -47,6 +48,7 @@ func (r Resource) GetProperties(response http.ResponseWriter, _ *http.Request) {
properties := Properties{
DashboardNamespace: r.Options.InstallNamespace,
DashboardVersion: dashboardVersion,
DefaultNamespace: r.Options.DefaultNamespace,
PipelineNamespace: pipelineNamespace,
PipelineVersion: pipelineVersion,
ReadOnly: r.Options.ReadOnly,
Expand Down
1 change: 1 addition & 0 deletions pkg/endpoints/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Options struct {
PipelinesNamespace string
TriggersNamespace string
TenantNamespaces []string
DefaultNamespace string
ReadOnly bool
LogoutURL string
StreamLogs bool
Expand Down
6 changes: 6 additions & 0 deletions scripts/installer
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ EXTENSIONS_RBAC="false"
LOGOUT_URL=""
LOG_LEVEL="info"
LOG_FORMAT="json"
DEFAULT_NAMESPACE=""
TENANT_NAMESPACES=""
STREAM_LOGS="true"
EXTERNAL_LOGS=""
Expand Down Expand Up @@ -172,6 +173,7 @@ patch() {
replace "--log-format=--log-format" "--log-format=$LOG_FORMAT"
replace "--logout-url=--logout-url" "--logout-url=$LOGOUT_URL"
replace "--read-only=--read-only" "--read-only=$READONLY"
replace "--default-namespace=--default-namespace" "--default-namespace=$DEFAULT_NAMESPACE"
replace "--namespaces=--tenant-namespaces" "--namespaces=$TENANT_NAMESPACES"
replace "--stream-logs=--stream-logs" "--stream-logs=$STREAM_LOGS"
replace "--external-logs=--external-logs" "--external-logs=$EXTERNAL_LOGS"
Expand Down Expand Up @@ -503,6 +505,10 @@ while [[ $# -gt 0 ]]; do
shift
OVERRIDE_TRIGGERS_NAMESPACE="${1}"
;;
'--default-namespace')
shift
DEFAULT_NAMESPACE="${1}"
;;
'--tenant-namespaces')
shift
TENANT_NAMESPACES="${1}"
Expand Down
5 changes: 5 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,8 @@ export function useTenantNamespaces() {
const { data } = useProperties();
return data.tenantNamespaces || [];
}

export function useDefaultNamespace() {
const { data } = useProperties();
return data.defaultNamespace;
}
23 changes: 23 additions & 0 deletions src/api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,26 @@ it('useTenantNamespaces', async () => {
);
expect(tenantNamespacesResult.current).toEqual(tenantNamespaces);
});

it('useDefaultNamespace', async () => {
const queryClient = getQueryClient();

const defaultNamespace = 'fake_defaultNamespace';

const properties = { defaultNamespace };
server.use(http.get(/\/properties$/, () => HttpResponse.json(properties)));
const { result, waitFor } = renderHook(() => API.useProperties(), {
wrapper: getAPIWrapper({ queryClient })
});
await waitFor(() => result.current.isFetching);
await waitFor(() => !result.current.isFetching);
expect(result.current.data).toEqual(properties);

const { result: defaultNamespacesResult } = renderHook(
() => API.useDefaultNamespace(),
{
wrapper: getAPIWrapper({ queryClient })
}
);
expect(defaultNamespacesResult.current).toEqual(defaultNamespace);
});
14 changes: 13 additions & 1 deletion src/containers/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {

import {
NamespaceContext,
useDefaultNamespace,
useExtensions,
useLogoutURL,
useNamespaces,
Expand Down Expand Up @@ -145,6 +146,7 @@ export function App({ lang }) {
} = useProperties();
const logoutURL = useLogoutURL();
const tenantNamespaces = useTenantNamespaces();
const defaultNamespace = useDefaultNamespace();

const [isSideNavExpanded, setIsSideNavExpanded] = useState(true);
const [selectedNamespace, setSelectedNamespace] = useState(
Expand Down Expand Up @@ -210,6 +212,13 @@ export function App({ lang }) {
</Header>
);

function HandleDefaultNamespace() {
if (defaultNamespace) {
setTimeout(() => setSelectedNamespace(defaultNamespace), 0);
}
return null;
}

return (
<NamespaceContext.Provider value={namespaceContext}>
<IntlProvider
Expand Down Expand Up @@ -241,7 +250,10 @@ export function App({ lang }) {
<PageErrorBoundary>
<Switch>
<CompatRoute path="/" exact>
<Redirect to={urls.about()} />
<>
<HandleDefaultNamespace />
<Redirect to={urls.about()} />
</>
</CompatRoute>
<CompatRoute path={paths.pipelines.all()} exact>
<NamespacedRoute>
Expand Down
Loading