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

salt: Use csc framework for UI configuration #3181

Merged
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ repos:
files: ^(salt/tests/unit/formulas/.*\.py)$
args: [--strict]
additional_dependencies:
- 'pyenchant~=2.0'
- pytest

- repo: https://github.com/warpnet/salt-lint
Expand Down
1 change: 1 addition & 0 deletions .pylint-dict
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
API
arg
basename
buildargs
Expand Down
22 changes: 18 additions & 4 deletions buildchain/buildchain/salt_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ def _get_parts(self) -> Iterator[str]:
Path("salt/metalk8s/addons/ui/deployed/dependencies.sls"),
Path("salt/metalk8s/addons/ui/deployed/ingress.sls"),
Path("salt/metalk8s/addons/ui/deployed/init.sls"),
Path("salt/metalk8s/addons/ui/config/metalk8s-shell-ui-config.yaml.j2"),
Path("salt/metalk8s/addons/ui/config/metalk8s-ui-config.yaml"),
targets.TemplateFile(
task_name="salt/metalk8s/addons/ui/config/metalk8s-theme.yaml",
source=constants.ROOT.joinpath(
"salt/metalk8s/addons/ui/config/metalk8s-theme.yaml.in"
),
destination=constants.ISO_ROOT.joinpath(
"salt/metalk8s/addons/ui/config/metalk8s-theme.yaml"
),
context={
"ThemeConfig": textwrap.indent(
UI_THEME_OPTIONS.read_text(encoding="utf-8"), 4 * " "
)
},
file_dep=[UI_THEME_OPTIONS],
),
Path("salt/metalk8s/addons/ui/deployed/ui-configuration.sls"),
Path("salt/metalk8s/addons/ui/deployed/files/metalk8s-ui-deployment.yaml.j2"),
Path("salt/metalk8s/addons/ui/deployed/namespace.sls"),
targets.TemplateFile(
Expand All @@ -348,12 +366,8 @@ def _get_parts(self) -> Iterator[str]:
"salt/metalk8s/addons/ui/deployed/ui.sls"
),
context={
"ThemeConfig": textwrap.indent(
UI_THEME_OPTIONS.read_text(encoding="utf-8"), 12 * " "
),
"ShellUIVersion": versions.SHELL_UI_VERSION,
},
file_dep=[UI_THEME_OPTIONS],
),
Path("salt/metalk8s/addons/solutions/deployed/configmap.sls"),
Path("salt/metalk8s/addons/solutions/deployed/init.sls"),
Expand Down
7 changes: 6 additions & 1 deletion buildchain/buildchain/shell_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from buildchain import types
from buildchain import utils
from buildchain import ui
from buildchain import versions


def task_shell_ui() -> types.TaskDict:
Expand Down Expand Up @@ -54,7 +55,11 @@ def clean() -> None:
"_shell_ui_mkdir_build_root",
],
"file_dep": list(utils.git_ls("shell-ui")),
"targets": [constants.SHELL_UI_BUILD_ROOT / "index.html"],
"targets": [
constants.SHELL_UI_BUILD_ROOT.joinpath(
f"solution-ui-navbar.{versions.SHELL_UI_VERSION}.js"
),
],
"clean": [clean],
}

Expand Down
4 changes: 4 additions & 0 deletions docs/developer/architecture/configurations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ customize on-site in order to match with my environment specificities:
- New Grafana dashboards or new Grafana datasources
- Number of replicas for the Prometheus, Alert Manager, Grafana or Dex
deployments
- Changing the path on which the MetalK8s UI is deployed
- Customizing the UI theme
- Modifying OIDC provider, client ID or scopes
- Adding custom menu entries

.. note::

Expand Down
221 changes: 219 additions & 2 deletions docs/operation/cluster_and_service_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ given Cluster and Services Configurations.
Default Service Configurations
------------------------------

MetalK8s addons (Alertmanager, Dex, Grafana and Prometheus) ships with default
runtime service configurations required for basic service deployment.
MetalK8s addons (Alertmanager, Dex, Grafana, Prometheus and UI) ships with
default runtime service configurations required for basic service deployment.
Find below an exhaustive list of available default Service Configurations
deployed in a MetalK8s cluster.

Expand Down Expand Up @@ -86,6 +86,53 @@ The default configuration values for Loki are specified below:
:language: yaml
:lines: 3-


UI Default Configuration
~~~~~~~~~~~~~~~~~~~~~~~~

MetalK8s UI simplifies management and monitoring of a MetalK8s cluster from a
centralized user interface.

The default configuration values for MetalK8s UI are specified below:

.. literalinclude:: ../../salt/metalk8s/addons/ui/config/metalk8s-ui-config.yaml
:language: yaml
:lines: 3-

See :ref:`csc-ui-customization` to override these defaults.

UI Default Theme
~~~~~~~~~~~~~~~~

You can override theme colors used by MetalK8s UI.

The default theme for MetalK8s UI are specified below:

.. literalinclude:: ../../shell-ui/theme.json
:language: json
:lines: 3-

See :ref:`csc-ui-theme-customization` to override these defaults.

Shell UI Default Configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MetalK8s Shell UI provides a common set of features to MetalK8s UI and
any other UI (both control and workload plane) configured to include the
Shell UI component(s).
Features exposed include:
- user authentication using an OIDC provider
- navigation menu items, displayed according to user groups
(retrieved from OIDC)

The default Shell UI configuration values are specified below:

.. literalinclude:: ../../salt/metalk8s/addons/ui/config/metalk8s-shell-ui-config.yaml.j2
:language: yaml
:lines: 3-

See :ref:`csc-shell-ui-config-customization` to override these defaults.

Service Configurations Customization
------------------------------------

Expand Down Expand Up @@ -548,6 +595,176 @@ edited as follows:
Due to internal implementation, ``retention_period`` must be a multiple of
``24h`` in order to get the expected behavior

.. _csc-ui-customization:

Metalk8s UI Configuration Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Default configuration for MetalK8s UI can be overridden by editing its
Cluster and Service ConfigMap ``metalk8s-ui-config`` in namespace
``metalk8s-ui`` under the key ``data.config\.yaml``:

.. code-block:: shell

root@bootstrap $ kubectl --kubeconfig /etc/kubernetes/admin.conf \
edit configmap -n metalk8s-ui \
metalk8s-ui-config

Changing the MetalK8s UI Ingress Path
""""""""""""""""""""""""""""""""""""""""""""""""
Comment on lines +613 to +614
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not "critical" but still a bit ugly 😜

Suggested change
Changing the MetalK8s UI Ingress Path
""""""""""""""""""""""""""""""""""""""""""""""""
Changing the MetalK8s UI Ingress Path
"""""""""""""""""""""""""""""""""""""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took care of it in #3196


In order to expose another UI at the root path of the control plane,
in place of MetalK8s UI, you need to change the Ingress path from
which MetalK8s UI is served.

For example, to serve MetalK8s UI at **/platform** instead of **/**, follow
these steps:

#. Change the value of ``spec.basePath`` in the ConfigMap:

.. code-block:: yaml

apiVersion: v1
kind: ConfigMap
data:
config.yaml: |-
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: UIConfig
spec:
basePath: /platform

#. Apply your changes by running:

.. parsed-literal::

root\@bootstrap $ kubectl exec -n kube-system -c salt-master \\
--kubeconfig /etc/kubernetes/admin.conf \\
salt-master-bootstrap -- salt-run state.sls \\
metalk8s.addons.ui.deployed saltenv=metalk8s-|version|

.. _csc-ui-theme-customization:

MetalK8s UI Theme Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment on lines +647 to +648
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MetalK8s UI Theme Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MetalK8s UI Theme Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Default configuration for MetalK8s UI Theme can be overridden by editing its
Cluster and Service ConfigMap ``metalk8s-theme`` in namespace
``metalk8s-ui`` under the key ``data.config\.yaml``:

.. code-block:: shell

root@bootstrap $ kubectl --kubeconfig /etc/kubernetes/admin.conf \
edit configmap -n metalk8s-ui \
metalk8s-theme

Once the theme is edited, apply your changes by running:


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line, to remove

.. parsed-literal::

root\@bootstrap $ kubectl exec -n kube-system -c salt-master \\
--kubeconfig /etc/kubernetes/admin.conf \\
salt-master-bootstrap -- salt-run state.sls \\
metalk8s.addons.ui.deployed saltenv=metalk8s-|version|

.. _csc-shell-ui-config-customization:

MetalK8s Shell UI Configuration Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Default configuration for MetalK8s Shell UI can be overridden by editing its
Cluster and Service ConfigMap ``metalk8s-shell-ui-config`` in namespace
``metalk8s-ui`` under the key ``data.config\.yaml``.

Changing UI OIDC Configuration
""""""""""""""""""""""""""""""

In order to adapt the OIDC configuration (e.g. the provider URL or
the client ID) used by the UI shareable navigation bar (called Shell UI),
you need to modify its ConfigMap.

For example, in order to replace the default client ID with "ui",
follow these steps:

#. Edit the ConfigMap:

.. code-block:: shell

root@bootstrap $ kubectl --kubeconfig /etc/kubernetes/admin.conf \
edit configmap -n metalk8s-ui \
metalk8s-shell-ui-config

#. Add the following entry:

.. code-block:: yaml

apiVersion: v1
kind: ConfigMap
data:
config.yaml: |-
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ShellUIConfig
spec:
# [...]
oidc:
# [...]
clientId: "ui"

#. Apply your changes by running:

.. parsed-literal::

root\@bootstrap $ kubectl exec -n kube-system -c salt-master \\
--kubeconfig /etc/kubernetes/admin.conf \\
salt-master-bootstrap -- salt-run state.sls \\
metalk8s.addons.ui.deployed saltenv=metalk8s-|version|

You can similarly edit the requested scopes through the "scopes" attribute or
the OIDC provider URL through the "providerUrl" attribute.

Changing UI Menu Entries
""""""""""""""""""""""""

To change the UI navigation menu entries, follow these steps:

#. Edit the ConfigMap:

.. code-block:: shell

root@bootstrap $ kubectl --kubeconfig /etc/kubernetes/admin.conf \
edit configmap -n metalk8s-ui \
metalk8s-shell-ui-config

#. Edit the ``options`` field. As an example, we add an entry to
the ``main`` section (there is also a ``subLogin`` section):

.. code-block:: yaml

apiVersion: v1
kind: ConfigMap
data:
config.yaml: |-
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ShellUIConfig
spec:
# [...]
options:
# [...]
main:
# [...]
https://www.scality.com/:
en: "Scality"
fr: "Scality"

#. Apply your changes by running:

.. parsed-literal::

root\@bootstrap $ kubectl exec -n kube-system -c salt-master \\
--kubeconfig /etc/kubernetes/admin.conf \\
salt-master-bootstrap -- salt-run state.sls \\
metalk8s.addons.ui.deployed saltenv=metalk8s-|version|

Replicas Count Customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
28 changes: 28 additions & 0 deletions salt/metalk8s/addons/ui/config/metalk8s-shell-ui-config.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!jinja|yaml

# Defaults for shell UI configuration
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ShellUIConfig
spec:
oidc:
providerUrl: "/oidc"
redirectUrl: "https://{{ grains.metalk8s.control_plane_ip }}:8443/"
clientId: "metalk8s-ui"
responseType: "id_token"
scopes: "openid profile email groups offline_access audience:server:client_id:oidc-auth-client"
userGroupsMapping:
"admin@metalk8s.invalid":
- admin
options:
main:
"https://{{ grains.metalk8s.control_plane_ip }}:8443/":
en: "Platform"
fr: "Plateforme"
"https://{{ grains.metalk8s.control_plane_ip }}:8443/alerts":
en: "Alerts"
fr: "Alertes"
subLogin:
"https://{{ grains.metalk8s.control_plane_ip }}:8443/docs":
en: "Documentation"
fr: "Documentation"

8 changes: 8 additions & 0 deletions salt/metalk8s/addons/ui/config/metalk8s-theme.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!yaml

# Defaults for configuration of MetalK8s UI
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: ThemeConfig
spec:
theme: |-
@@ThemeConfig
7 changes: 7 additions & 0 deletions salt/metalk8s/addons/ui/config/metalk8s-ui-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!yaml

# Defaults for configuration of MetalK8s UI
apiVersion: addons.metalk8s.scality.com/v1alpha1
kind: UIConfig
spec:
basePath: /
14 changes: 12 additions & 2 deletions salt/metalk8s/addons/ui/deployed/ingress.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#! metalk8s_kubernetes
#!jinja | metalk8s_kubernetes

{%- set metalk8s_ui_defaults = salt.slsutil.renderer(
'salt://metalk8s/addons/ui/config/metalk8s-ui-config.yaml', saltenv=saltenv
)
%}

{%- set metalk8s_ui_config = salt.metalk8s_service_configuration.get_service_conf(
'metalk8s-ui', 'metalk8s-ui-config', metalk8s_ui_defaults
)
%}

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
Expand Down Expand Up @@ -76,7 +86,7 @@ spec:
rules:
- http:
paths:
- path: /
- path: {{ metalk8s_ui_config.spec.basePath }}
backend:
serviceName: metalk8s-ui
servicePort: 80
Loading