From dfbfd7c412cc4d94f755357db7ad4d7bc7fa957d Mon Sep 17 00:00:00 2001 From: Henry Li Date: Fri, 4 Oct 2024 16:04:43 -0400 Subject: [PATCH 1/2] added enableInstanaMetricCollection to CommonService API Signed-off-by: Henry Li --- api/v3/commonservice_types.go | 2 ++ .../ibm-common-service-operator.clusterserviceversion.yaml | 2 +- bundle/manifests/operator.ibm.com_commonservices.yaml | 2 ++ config/crd/bases/operator.ibm.com_commonservices.yaml | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/v3/commonservice_types.go b/api/v3/commonservice_types.go index 018c0e697..529b545be 100644 --- a/api/v3/commonservice_types.go +++ b/api/v3/commonservice_types.go @@ -119,6 +119,8 @@ type CommonServiceSpec struct { OperatorConfigs []OperatorConfig `json:"operatorConfigs,omitempty"` // +optional License LicenseList `json:"license"` + // +optional + EnableInstanaMetricCollection bool `json:"enableInstanaMetricCollection,omitempty"` } // OperatorConfig is configuration composed of key-value pairs to be injected into specified CSVs diff --git a/bundle/manifests/ibm-common-service-operator.clusterserviceversion.yaml b/bundle/manifests/ibm-common-service-operator.clusterserviceversion.yaml index b05eab354..e8611a770 100644 --- a/bundle/manifests/ibm-common-service-operator.clusterserviceversion.yaml +++ b/bundle/manifests/ibm-common-service-operator.clusterserviceversion.yaml @@ -23,7 +23,7 @@ metadata: capabilities: Seamless Upgrades cloudPakThemesVersion: styles4100.css containerImage: icr.io/cpopen/common-service-operator:latest - createdAt: "2024-09-09T21:00:30Z" + createdAt: "2024-10-04T20:02:10Z" description: The IBM Cloud Pak foundational services operator is used to deploy IBM foundational services. nss.operator.ibm.com/managed-operators: ibm-common-service-operator nss.operator.ibm.com/managed-webhooks: "" diff --git a/bundle/manifests/operator.ibm.com_commonservices.yaml b/bundle/manifests/operator.ibm.com_commonservices.yaml index acccabc54..cddf9fe13 100644 --- a/bundle/manifests/operator.ibm.com_commonservices.yaml +++ b/bundle/manifests/operator.ibm.com_commonservices.yaml @@ -71,6 +71,8 @@ spec: DefalutAdminUser is the name of the default admin user for foundational services IM, default is cpadmin type: string + enableInstanaMetricCollection: + type: boolean features: description: Features defines the configurations of Cloud Pak Services properties: diff --git a/config/crd/bases/operator.ibm.com_commonservices.yaml b/config/crd/bases/operator.ibm.com_commonservices.yaml index a22e401e0..a3722bda1 100644 --- a/config/crd/bases/operator.ibm.com_commonservices.yaml +++ b/config/crd/bases/operator.ibm.com_commonservices.yaml @@ -68,6 +68,8 @@ spec: DefalutAdminUser is the name of the default admin user for foundational services IM, default is cpadmin type: string + enableInstanaMetricCollection: + type: boolean features: description: Features defines the configurations of Cloud Pak Services properties: From 8cf8ec1e28eec3a57ca652713dece5c4dbf89b4f Mon Sep 17 00:00:00 2001 From: Henry Li Date: Wed, 9 Oct 2024 16:14:57 -0400 Subject: [PATCH 2/2] added instana enable configuration handling Signed-off-by: Henry Li --- controllers/constant/instanaEnable.go | 28 +++++++++++++++++++++++++++ controllers/render_template.go | 24 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 controllers/constant/instanaEnable.go diff --git a/controllers/constant/instanaEnable.go b/controllers/constant/instanaEnable.go new file mode 100644 index 000000000..7fbed82d6 --- /dev/null +++ b/controllers/constant/instanaEnable.go @@ -0,0 +1,28 @@ +// +// Copyright 2024 IBM Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package constant + +const InstanaEnableTemplate = ` +- name: ibm-im-operator + spec: + authentication: + enableInstanaMetricCollection: {{ .InstanaEnable }} +- name: ibm-idp-config-ui-operator + spec: + commonWebUI: + enableInstanaMetricCollection: {{ .InstanaEnable }} +` diff --git a/controllers/render_template.go b/controllers/render_template.go index af4a6cef8..3860cb7e5 100644 --- a/controllers/render_template.go +++ b/controllers/render_template.go @@ -17,11 +17,13 @@ package controllers import ( + "bytes" "context" "encoding/json" "fmt" "strconv" "strings" + "text/template" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" @@ -52,6 +54,28 @@ func (r *CommonServiceReconciler) getNewConfigs(cs *unstructured.Unstructured) ( newConfigs = append(newConfigs, storageConfig...) } + // Update EnableInstanaMetricCollection in OperandConfig + if cs.Object["spec"].(map[string]interface{})["enableInstanaMetricCollection"] != nil { + klog.Info("Applying enableInstanaMetricCollection configuration") + + t := template.Must(template.New("template InstanaEnable").Parse(constant.InstanaEnableTemplate)) + var tmplWriter bytes.Buffer + instanaEnable := struct { + InstanaEnable bool + }{ + InstanaEnable: cs.Object["spec"].(map[string]interface{})["enableInstanaMetricCollection"].(bool), + } + if err := t.Execute(&tmplWriter, instanaEnable); err != nil { + return nil, nil, err + } + s := tmplWriter.String() + instanaConfig, err := convertStringToSlice(s) + if err != nil { + return nil, nil, err + } + newConfigs = append(newConfigs, instanaConfig...) + } + // Update routeHost if cs.Object["spec"].(map[string]interface{})["routeHost"] != nil { klog.Info("Applying routeHost configuration")