From f39890d7e185c3a2158a3695cdc91733b2c6b17f Mon Sep 17 00:00:00 2001 From: Marek Hornak Date: Mon, 5 Feb 2024 13:59:01 +0100 Subject: [PATCH] Bump chart --- README.md | 6 +++++ .../samples/kibana.eck_v1alpha1_dataview.yaml | 15 ++++++------ docs/cr_data_view.md | 14 ++++++----- utils/kibana/dataview_utils.go | 24 +++++++------------ 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 6a6e94a..dae34cd 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,12 @@ Configuration options are documented in [chart README file](charts/eck-custom-re ## Upgrade guide +### From 0.7.0 to 0.8.0 +The CRD for Kibana DataView was changed - the `defaultView` field was added, to flag if the Data View should be configured as default in target instance Kibana. To update the CRD manually, run: +``` +kubectl apply --server-side -f https://raw.githubusercontent.com/xco-sk/eck-custom-resources/v0.8.0/config/crd/bases/kibana.eck.github.com_dataviews.yaml +``` + ### From 0.6.0 to 0.7.0 There is a new `ComponentTemplate` CRD present. To apply the CRD, run: ``` diff --git a/config/samples/kibana.eck_v1alpha1_dataview.yaml b/config/samples/kibana.eck_v1alpha1_dataview.yaml index 47ba104..66bde70 100644 --- a/config/samples/kibana.eck_v1alpha1_dataview.yaml +++ b/config/samples/kibana.eck_v1alpha1_dataview.yaml @@ -1,18 +1,19 @@ apiVersion: kibana.eck.github.com/v1alpha1 kind: DataView metadata: - name: dataview-sample + name: dataview-test2 spec: targetInstance: name: kibana-quickstart - space: space-sample - dependencies: - - type: lens - name: lens-sample - defaultView: true + # space: space-sample + # dependencies: + # - type: lens + + # name: lens-sample + defaultView: false body: | { - "title": "sample-index-*", + "title": "sample-test2-*", "type": "rollup", "typeMeta": { "params": { diff --git a/docs/cr_data_view.md b/docs/cr_data_view.md index b4917e8..8a2fea9 100644 --- a/docs/cr_data_view.md +++ b/docs/cr_data_view.md @@ -15,12 +15,13 @@ See [Data Views APIs](https://www.elastic.co/guide/en/kibana/current/data-views- ## Fields | Key | Type | Description | Default | -|-----------------------------|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------| -| `metadata.name` | string | Name of the Data View visualization, used also as its ID in Kibana | No default | -| `spec.space` | string | Name of the Kibana namespace to which the Data View is deployed to | No default (will be deployed to "default" namespace) | -| `spec.targetInstance.name` | string | Name of the [Kibana Instance](cr_kibana_instance.md) to which this DataView will be deployed to | The operator configuration | -| `spec.body` | string | Data View definition (the inner part of the requests) json | No default | -| `spec.dependencies` | List of objects | List of dependencies - the reconciler will wait for all resources from the list to be present in Kibana before deploying/updating this resource | - | | +| --------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | +| `metadata.name` | string | Name of the Data View visualization, used also as its ID in Kibana | No default | +| `spec.space` | string | Name of the Kibana namespace to which the Data View is deployed to | No default (will be deployed to "default" namespace) | +| `spec.targetInstance.name` | string | Name of the [Kibana Instance](cr_kibana_instance.md) to which this DataView will be deployed to | The operator configuration | +| `spec.body` | string | Data View definition (the inner part of the requests) json | No default | +| `spec.defaultView` | boolean | Flag if the Data View should be configured as default in target instance Kibana | false | +| `spec.dependencies` | List of objects | List of dependencies - the reconciler will wait for all resources from the list to be present in Kibana before deploying/updating this resource | - | | | `spec.dependencies[].space` | string | Kibana Space where to look for given resource | - | | `spec.dependencies[].type` | string | Type of resource - one of `visualization, dashboard, search, index-pattern, lens` | - | | `spec.dependencies[].name` | string | Name of resource | - | @@ -39,6 +40,7 @@ spec: dependencies: - type: lens name: lens-sample + defaultView: true body: | { "title": "sample-index-*", diff --git a/utils/kibana/dataview_utils.go b/utils/kibana/dataview_utils.go index c79d6af..bf8b6a2 100644 --- a/utils/kibana/dataview_utils.go +++ b/utils/kibana/dataview_utils.go @@ -17,13 +17,7 @@ const REFRESH_FIELDS = true func DeleteDataView(kClient Client, dataView kibanaeckv1alpha1.DataView) (ctrl.Result, error) { _, deleteErr := kClient.DoDelete(formatExistingDataViewUrl(dataView.Name, dataView.Spec.Space)) - if deleteErr != nil { - return ctrl.Result{}, deleteErr - } - - defaultFlagErr := handleDefaultFlagOnDelete(dataView, kClient) - - return ctrl.Result{}, defaultFlagErr + return ctrl.Result{}, deleteErr } func UpsertDataView(kClient Client, dataView kibanaeckv1alpha1.DataView) (ctrl.Result, error) { @@ -142,21 +136,14 @@ func removeName(objectJson string, id string) (*string, error) { } func handleDefaultFlagOnUpsert(dataview kibanaeckv1alpha1.DataView, kClient Client) error { - if *dataview.Spec.DefaultView { + if dataview.Spec.DefaultView != nil && *dataview.Spec.DefaultView { saveDefaultView(&dataview.Name, dataview.Spec.Space, kClient) } return nil } -func handleDefaultFlagOnDelete(dataview kibanaeckv1alpha1.DataView, kClient Client) error { - if *dataview.Spec.DefaultView { - return saveDefaultView(nil, dataview.Spec.Space, kClient) - } - return nil -} - func saveDefaultView(dataViewName *string, space *string, kClient Client) error { - var body map[string]interface{} + body := make(map[string]interface{}) body["data_view_id"] = dataViewName body["force"] = true @@ -168,6 +155,11 @@ func saveDefaultView(dataViewName *string, space *string, kClient Client) error return err } +func getDefaultDataView(space *string, kClient Client) (*string, error) { + _, err = kClient.DoGet(formatDefaultDataViewUrl(space), string(marshalledBody)) + +} + func formatDefaultDataViewUrl(space *string) string { if space == nil { return "/api/data_views/default"