Skip to content

Commit

Permalink
added configuration for instana metrics collection (#2249)
Browse files Browse the repository at this point in the history
* added enableInstanaMetricCollection to CommonService API

Signed-off-by: Henry Li <[email protected]>

* added instana enable configuration handling

Signed-off-by: Henry Li <[email protected]>

---------

Signed-off-by: Henry Li <[email protected]>
  • Loading branch information
bitscuit authored Oct 10, 2024
1 parent c835d0d commit 3083441
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/v3/commonservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
2 changes: 2 additions & 0 deletions bundle/manifests/operator.ibm.com_commonservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/operator.ibm.com_commonservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions controllers/constant/instanaEnable.go
Original file line number Diff line number Diff line change
@@ -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 }}
`
24 changes: 24 additions & 0 deletions controllers/render_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 3083441

Please sign in to comment.