Skip to content

Commit

Permalink
feat(metrics-operator): add helm value to disable APIService installa…
Browse files Browse the repository at this point in the history
…tion (#2607)

Signed-off-by: Geoffrey Israel <israelgeoffrey13@gmail.com>
Co-authored-by: Florian Bacher <florian.bacher@dynatrace.com>
Co-authored-by: Moritz Wiesinger <moritz.wiesinger@dynatrace.com>
Co-authored-by: odubajDT <93584209+odubajDT@users.noreply.github.com>
  • Loading branch information
4 people committed Dec 5, 2023
1 parent 3d1c442 commit ec40ce8
Show file tree
Hide file tree
Showing 14 changed files with 2,475 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ annadreal
apicommon
apierr
apierrors
apiservice
APIURL
apk
appcreationrequest
Expand Down
2 changes: 2 additions & 0 deletions .github/scripts/.helm-tests/default/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9265,6 +9265,8 @@ spec:
fieldPath: metadata.name
- name: EXPOSE_KEPTN_METRICS
value: "true"
- name: ENABLE_CUSTOM_METRICS_API_SERVICE
value: "true"
- name: METRICS_CONTROLLER_LOG_LEVEL
value: "0"
- name: ANALYSIS_CONTROLLER_LOG_LEVEL
Expand Down
2,431 changes: 2,431 additions & 0 deletions .github/scripts/.helm-tests/metrics-only-with-apiservice-disabled/result.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
certManager:
enabled: false
lifecycleOperator:
enabled: false
metricsOperator:
enabled: true
image:
tag: v0.0.0
customMetricsAPIService:
enabled: "false"

global:
commonLabels:
app.kubernetes.io/version: vmyversion
2 changes: 2 additions & 0 deletions .github/scripts/.helm-tests/metrics-only/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,8 @@ spec:
fieldPath: metadata.name
- name: EXPOSE_KEPTN_METRICS
value: "true"
- name: ENABLE_CUSTOM_METRICS_API_SERVICE
value: "true"
- name: METRICS_CONTROLLER_LOG_LEVEL
value: "0"
- name: ANALYSIS_CONTROLLER_LOG_LEVEL
Expand Down
2 changes: 2 additions & 0 deletions .github/scripts/.helm-tests/metrics-with-certs/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,8 @@ spec:
fieldPath: metadata.name
- name: EXPOSE_KEPTN_METRICS
value: "true"
- name: ENABLE_CUSTOM_METRICS_API_SERVICE
value: "true"
- name: METRICS_CONTROLLER_LOG_LEVEL
value: "0"
- name: ANALYSIS_CONTROLLER_LOG_LEVEL
Expand Down
1 change: 1 addition & 0 deletions metrics-operator/chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Prometheus, Dynatrace, DataDog and K8s metric server...
| `annotations` | add deployment level annotations | `{}` |
| `podAnnotations` | adds pod level annotations | `{}` |
| `kubernetesClusterDomain` | overrides cluster.local | `cluster.local` |
| `customMetricsAPIService.enabled` | enable/disable the K8s APIService installation | `true` |

### Keptn Metrics Operator controller

Expand Down
2 changes: 2 additions & 0 deletions metrics-operator/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ spec:
fieldPath: metadata.name
- name: EXPOSE_KEPTN_METRICS
value: {{ .Values.env.exposeKeptnMetrics | quote }}
- name: ENABLE_CUSTOM_METRICS_API_SERVICE
value: {{ .Values.customMetricsAPIService.enabled | quote }}
- name: METRICS_CONTROLLER_LOG_LEVEL
value: {{ .Values.env.metricsControllerLogLevel | quote
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.customMetricsAPIService.enabled "true" }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
Expand All @@ -13,4 +14,5 @@ roleRef:
subjects:
- kind: ServiceAccount
name: horizontal-pod-autoscaler
namespace: '{{ .Release.Namespace }}'
namespace: '{{ .Release.Namespace }}'
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.customMetricsAPIService.enabled "true" }}
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
Expand All @@ -14,4 +15,5 @@ spec:
name: 'metrics-operator-service'
namespace: '{{ .Release.Namespace }}'
version: v1beta1
versionPriority: 100
versionPriority: 100
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if eq .Values.customMetricsAPIService.enabled "true" }}
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
Expand All @@ -14,4 +15,5 @@ spec:
name: 'metrics-operator-service'
namespace: '{{ .Release.Namespace }}'
version: v1beta2
versionPriority: 200
versionPriority: 200
{{- end }}
3 changes: 3 additions & 0 deletions metrics-operator/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ annotations: {}
podAnnotations: {}
## @param kubernetesClusterDomain overrides cluster.local
kubernetesClusterDomain: cluster.local
customMetricsAPIService:
## @param customMetricsAPIService.enabled enable/disable the K8s APIService installation
enabled: "true"

## @section Keptn Metrics Operator controller
## @extra containerSecurityContext Sets security context privileges
Expand Down
2 changes: 2 additions & 0 deletions metrics-operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ spec:
fieldPath: metadata.name
- name: EXPOSE_KEPTN_METRICS
value: "true"
- name: ENABLE_CUSTOM_METRICS_API_SERVICE
value: "true"
- name: ENABLE_ANALYSIS
value: "true"
- name: METRICS_CONTROLLER_LOG_LEVEL
Expand Down
9 changes: 6 additions & 3 deletions metrics-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type envConfig struct {
KeptnMetricControllerLogLevel int `envconfig:"METRICS_CONTROLLER_LOG_LEVEL" default:"0"`
AnalysisControllerLogLevel int `envconfig:"ANALYSIS_CONTROLLER_LOG_LEVEL" default:"0"`
ExposeKeptnMetrics bool `envconfig:"EXPOSE_KEPTN_METRICS" default:"true"`
EnableCustomMetricsAPIService bool `envconfig:"ENABLE_CUSTOM_METRICS_API_SERVICE" default:"true"`
}

//nolint:gocyclo,funlen
Expand Down Expand Up @@ -133,9 +134,10 @@ func main() {
return
}

// Start the custom metrics adapter
go startCustomMetricsAdapter(env.PodNamespace)

if env.EnableCustomMetricsAPIService {
// Start the custom metrics adapter
go startCustomMetricsAdapter(env.PodNamespace)
}
disableCacheFor := []ctrlclient.Object{&corev1.Secret{}}

opt := ctrl.Options{
Expand Down Expand Up @@ -182,6 +184,7 @@ func main() {

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

keptnserver.StartServerManager(ctx, mgr.GetClient(), openfeature.NewClient("keptn"), env.ExposeKeptnMetrics, metricServerTickerInterval)

metricsLogger := ctrl.Log.WithName("KeptnMetric Controller")
Expand Down

0 comments on commit ec40ce8

Please sign in to comment.