Skip to content

Commit

Permalink
Introduce Kubecost aggregator (#2623)
Browse files Browse the repository at this point in the history
* Initial Waterfowl config based on QSR

Signed-off-by: Michael Dresser <[email protected]>

* Tune waterfowl PVs and bucket configs

* Move waterfowl values out of kubecostDeployment

* Add fullImageName override to waterfowl

* Fix waterfowl ports to 9004

* Fix secret mode, env vars, unset DB_ envs

* support asset endpoints

* add assets graph endpoint to proxy

* Add /savings/requestSizingV2 proxy to Waterfowl

* Add request sizing V2 topline to waterfowl proxy (#2541)

Signed-off-by: Michael Dresser <[email protected]>

* Add proxy rules for Cloud Cost api

* Cloud Cost pod templates

Signed-off-by: Sean Holcomb <[email protected]>

* setup waterfowl savings proxy on cfrontend config map

Signed-off-by: Alan Rodrigues <[email protected]>

* add /savings/abandonedWorkloads proxy for waterfowl (#2599)

* Added /model/reports proxy to Waterfowl.

* Added KUBECOST_NAMESPACE env to waterfowl-deployment.yaml.

* Added WATERFOWL_ENABLED to cost analyzer deployment.

* provide reasonable default

* Added /model/budget(s) proxies to Waterfowl.

* Fixed Waterfowl /reports proxies.

* rename all external naming/config to query handler

* rename to 'kubecost aggregator'

* fix missed rename targets

* rename files

* fix naming

* remove initContainer / add securityContexts (#2628)

* code review comments

* remove obsolete role/rolebinding

* statefulset

* first batch of code review fixes

* toss out role, update svc

* template rendering passing

* strip SA token, formatting fix

* punctuation, missing vals

* selector app name consistency

* Revert "toss out role, update svc"

This reverts commit bf2d082.

* re add svc template

* rm svc acct token unmount

* resolve outstanding code review items

* additional code review fixes

---------

Signed-off-by: Michael Dresser <[email protected]>
Signed-off-by: Sean Holcomb <[email protected]>
Signed-off-by: Alan Rodrigues <[email protected]>
Co-authored-by: Michael Dresser <[email protected]>
Co-authored-by: Sean Holcomb <[email protected]>
Co-authored-by: Alan Rodrigues <[email protected]>
Co-authored-by: Nik Willwerth <[email protected]>
Co-authored-by: nik-kc <[email protected]>
Co-authored-by: Jesse Goodier <[email protected]>
  • Loading branch information
7 people authored Oct 9, 2023
1 parent b4418c6 commit dba3f28
Show file tree
Hide file tree
Showing 12 changed files with 916 additions and 25 deletions.
109 changes: 84 additions & 25 deletions cost-analyzer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Expand the name of the chart.
{{- define "federator.name" -}}
{{- default "federator" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "aggregator.name" -}}
{{- default "aggregator" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "cloudCost.name" -}}
{{- default "cloud-cost" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
Expand Down Expand Up @@ -42,6 +48,14 @@ If release name contains chart name it will be used as a full name.
{{- printf "%s-%s" .Release.Name "federator" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "aggregator.fullname" -}}
{{- printf "%s-%s" .Release.Name "aggregator" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "cloudCost.fullname" -}}
{{- printf "%s-%s" .Release.Name (include "cloudCost.name" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the fully qualified name for Prometheus server service.
*/}}
Expand Down Expand Up @@ -88,6 +102,41 @@ Create the fully qualified name for Prometheus alertmanager service.
{{- printf "%s-%s" .Release.Name "query-service-load-balancer" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "aggregator.serviceName" -}}
{{- printf "%s-%s" .Release.Name "aggregator" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "cloudCost.serviceName" -}}
{{ include "cloudCost.fullname" . }}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "cost-analyzer.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "cost-analyzer.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{- define "query-service.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "query-service.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{- define "aggregator.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "aggregator.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{- define "cloudCost.serviceAccountName" -}}
{{ (include "cloudCost.fullname" .) }}
{{- end -}}

{{/*
Network Costs name used to tie autodiscovery of metrics to daemon set pods
*/}}
Expand All @@ -109,9 +158,20 @@ Network Costs name used to tie autodiscovery of metrics to daemon set pods
{{- end }}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "cost-analyzer.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the chart labels.
*/}}
{{- define "cost-analyzer.chartLabels" -}}
helm.sh/chart: {{ include "cost-analyzer.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
{{- define "kubecost.chartLabels" -}}
app.kubernetes.io/name: {{ include "cost-analyzer.name" . }}
helm.sh/chart: {{ include "cost-analyzer.chart" . }}
Expand All @@ -130,32 +190,13 @@ helm.sh/chart: {{ include "cost-analyzer.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}


{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "cost-analyzer.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- define "kubecost.aggregator.chartLabels" -}}
app.kubernetes.io/name: {{ include "aggregator.name" . }}
helm.sh/chart: {{ include "cost-analyzer.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "cost-analyzer.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "cost-analyzer.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{- define "query-service.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "query-service.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the common labels.
Expand All @@ -175,6 +216,14 @@ app: query-service
{{ include "kubecost.federator.chartLabels" . }}
app: federator
{{- end -}}
{{- define "aggregator.commonLabels" -}}
{{ include "cost-analyzer.chartLabels" . }}
app: kubecost-aggregator
{{- end -}}
{{- define "cloudCost.commonLabels" -}}
{{ include "cost-analyzer.chartLabels" . }}
{{ include "cloudCost.selectorLabels" . }}
{{- end -}}

{{/*
Create the selector labels.
Expand All @@ -194,6 +243,16 @@ app.kubernetes.io/name: {{ include "federator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: federator
{{- end -}}
{{- define "aggregator.selectorLabels" -}}
app.kubernetes.io/name: {{ include "aggregator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: kubecost-aggregator
{{- end -}}
{{- define "cloudCost.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cloudCost.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ include "cloudCost.name" . }}
{{- end -}}

{{/*
Return the appropriate apiVersion for daemonset.
Expand Down Expand Up @@ -307,4 +366,4 @@ requirements are met.
{{- else }}
{{- "" }}
{{- end }}
{{- end }}
{{- end }}
140 changes: 140 additions & 0 deletions cost-analyzer/templates/aggregator-cloud-cost-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{{- if .Values.kubecostAggregator.cloudCost.enabled }}

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "cloudCost.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "cloudCost.commonLabels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{ include "cloudCost.selectorLabels" . | nindent 6 }}
strategy:
type: Recreate
template:
metadata:
labels:
app.kubernetes.io/name: cloud-cost
app.kubernetes.io/instance: {{ .Release.Name }}
app: cloud-cost
spec:
restartPolicy: Always
serviceAccountName: {{ template "cloudCost.serviceAccountName" . }}
volumes:
{{- if .Values.kubecostModel.etlBucketConfigSecret }}
- name: etl-bucket-config
secret:
defaultMode: 420
secretName: {{ .Values.kubecostModel.etlBucketConfigSecret }}
{{- end }}
{{- if .Values.kubecostModel.federatedStorageConfigSecret }}
- name: federated-storage-config
secret:
defaultMode: 420
secretName: {{ .Values.kubecostModel.federatedStorageConfigSecret }}
{{- end }}
{{- if .Values.kubecostProductConfigs.cloudIntegrationSecret }}
- name: cloud-integration
secret:
secretName: {{ .Values.kubecostProductConfigs.cloudIntegrationSecret }}
items:
- key: cloud-integration.json
path: cloud-integration.json
{{- else }}
{{- fail "Cloud Cost requires configuration secret" }}
{{- end }}
containers:
- name: cloud-cost
{{- if .Values.kubecostModel }}
{{- if .Values.kubecostModel.openSourceOnly }}
{{- fail "Kubecost Aggregator cannot be used with open source only" }}
{{- else if .Values.kubecostAggregator.fullImageName }}
image: {{ .Values.kubecostAggregator.fullImageName }}
{{- else if .Values.kubecostModel.fullImageName }}
image: {{ .Values.kubecostModel.fullImageName }}
{{- else if .Values.imageVersion }}
image: {{ .Values.kubecostModel.image }}:{{ .Values.imageVersion }}
{{- else }}
image: {{ .Values.kubecostModel.image }}:prod-{{ $.Chart.AppVersion }}
{{ end }}
{{- else }}
image: gcr.io/kubecost1/cost-model:prod-{{ $.Chart.AppVersion }}
{{ end }}
readinessProbe:
httpGet:
path: /healthz
port: 9005
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 200
imagePullPolicy: Always
args: ["cloud-cost"]
ports:
- name: tcp-api
containerPort: 9005
protocol: TCP
resources:
{{- toYaml .Values.kubecostAggregator.cloudCost.resources | nindent 12 }}
volumeMounts:
{{- if .Values.kubecostModel.federatedStorageConfigSecret }}
- name: federated-storage-config
mountPath: /var/configs/etl/federated
readOnly: true
{{- end }}
{{- if .Values.kubecostModel.etlBucketConfigSecret }}
- name: etl-bucket-config
mountPath: /var/configs/etl
readOnly: true
{{- end }}
{{- if .Values.kubecostProductConfigs.cloudIntegrationSecret }}
- name: cloud-integration
mountPath: /var/configs/cloud-integration
{{- end }}
env:
- name: CONFIG_PATH
value: /var/configs/
{{- if .Values.kubecostModel.etlBucketConfigSecret }}
- name: ETL_BUCKET_CONFIG
value: "/var/configs/etl/object-store.yaml"
{{- end}}
{{- if .Values.kubecostModel.federatedStorageConfigSecret }}
- name: FEDERATED_STORE_CONFIG
value: "/var/configs/etl/federated/federated-store.yaml"
- name: FEDERATED_CLUSTER
value: "true"
{{- end}}
{{- range $key, $value := .Values.kubecostAggregator.cloudCost.env }}
- name: {{ $key | quote }}
value: {{ $value | quote }}
{{- end }}


{{- if .Values.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 2 }}
{{- end }}
{{- if .Values.kubecostAggregator.priority }}
{{- if .Values.kubecostAggregator.priority.enabled }}
{{- if .Values.kubecostAggregator.priority.name }}
priorityClassName: {{ .Values.kubecostAggregator.priority.name }}
{{- else }}
priorityClassName: {{ template "cost-analyzer.fullname" . }}-aggregator-priority
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.kubecostAggregator.cloudCost.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.kubecostAggregator.cloudCost.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.kubecostAggregator.cloudCost.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions cost-analyzer/templates/aggregator-cloud-cost-service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.kubecostAggregator.cloudCost.enabled }}

{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "cloudCost.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "cloudCost.commonLabels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions cost-analyzer/templates/aggregator-cloud-cost-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.kubecostAggregator.cloudCost.enabled }}

kind: Service
apiVersion: v1
metadata:
name: {{ template "cloudCost.serviceName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "cloudCost.commonLabels" . | nindent 4 }}
spec:
selector:
{{ include "cloudCost.selectorLabels" . | nindent 4 }}
type: "ClusterIP"
ports:
- name: tcp-api
port: 9005
targetPort: 9005
{{- end }}
Loading

0 comments on commit dba3f28

Please sign in to comment.