Skip to content

Commit de6e766

Browse files
committed
feat: support hiding Astarte Dashboard sidebar via annotation
PR astarte-platform/astarte-dashboard#521 introduced the ability to hide the Astarte Dashboard sidebar by tweaking its configuration. This allows the dashboard to be more easily used as an embedded component. This commit adds an annotation to the Astarte Custom Resource (CR) that acts as a feature flag to enable or disable the sidebar display. This annotation is a temporary solution to support the feature until it is officially added to the Astarte CR specification under the Dashboard component section. If the annotation is not set, it defaults to false (the sidebar remains visible). No defaulting webhook has been configured to automatically populate this annotation on the Astarte CR. To hide the Dashboard sidebar, set the following on the Astarte CR: ```yaml annotations: api.astarte-platform.org/hide-dashboard-sidebar: "true" ``` Signed-off-by: Luca Marchiori <luca.marchiori@secomind.com>
1 parent 076b31f commit de6e766

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2121
endpoints, pods and services.
2222
- Add experimental support for FIDO Device Onboard (FDO) in Astarte Pairing. The feature
2323
can be enabled and configured through the `features.fdo` field in the Astarte CR.
24+
- Add experimental support to hidden sidebar feature in the Astarte Dashboard.
2425

2526
### Changed
2627
- Forward port changes from release-24.5

api/api/v2alpha1/astarte_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
)
2929

30+
// Supported custom annotations in Astarte CR.
31+
const (
32+
// AnnotationHideDashboardSidebar allows to hide the Dashboard sidebar.
33+
// It is propagated to the Astarte Dashboard configmap
34+
// Value: "true" or "false"
35+
AnnotationHideDashboardSidebar = "api.astarte-platform.org/hide-dashboard-sidebar"
36+
)
37+
3038
// AstarteSpec defines the desired state of Astarte
3139
type AstarteSpec struct {
3240
// The Astarte Version for this Resource

docs/documentation/pages/crds/001-intro_crds.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
The Astarte Operator extends the Kubernetes API through the definition of Custom Resources.
44

55
To browse the CRD documentation, [follow this link](./crds/index.html).
6+
7+
## Custom Annotations
8+
Astarte and ADI CRs support a set of custom annotations that can be used to toggle custom behaviors that are not directly supported by the CRD schema. This is often the case for features that are still experimental, or that are not expected to be widely used, and that would therefore add unnecessary complexity to the CRD schema.
9+
10+
### Astarte CR
11+
12+
**Enable or disable the Astarte Dashboard sidebar**
13+
- Annotation: `api.astarte-platform.org/hide-dashboard-sidebar`
14+
- Values: `"true"` or `"false"`

internal/reconcile/astarte_dashboard.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func getAstarteDashboardPodSpec(cr *apiv2alpha1.Astarte, dashboard apiv2alpha1.A
174174

175175
func getAstarteDashboardConfigMapData(cr *apiv2alpha1.Astarte, dashboard apiv2alpha1.AstarteDashboardSpec) map[string]string {
176176
dashboardConfig := make(map[string]interface{})
177+
dashboardConfigUi := make(map[string]interface{})
177178

178179
dashboardConfig["astarte_api_url"] = getBaseAstarteAPIURL(cr)
179180
dashboardConfig["enable_flow_preview"] = misc.IsAstarteComponentDeployed(cr, apiv2alpha1.FlowComponent)
@@ -210,6 +211,12 @@ func getAstarteDashboardConfigMapData(cr *apiv2alpha1.Astarte, dashboard apiv2al
210211
dashboardConfig["auth"] = []apiv2alpha1.AstarteDashboardConfigAuthSpec{{Type: "token"}}
211212
}
212213

214+
dashboardConfigUi["hideSidebar"] = false
215+
if b, ok := cr.GetAnnotations()[apiv2alpha1.AnnotationHideDashboardSidebar]; ok && b == "true" { // nolint:goconst
216+
dashboardConfigUi["hideSidebar"] = true
217+
}
218+
dashboardConfig["ui"] = dashboardConfigUi
219+
213220
configJSON, _ := json.Marshal(dashboardConfig)
214221

215222
return map[string]string{

0 commit comments

Comments
 (0)