Skip to content

Commit

Permalink
Ajay tripathy multins support (kubecost#1999)
Browse files Browse the repository at this point in the history
* commit removal of budget controller file

* fix namespace scoping issue, use unexpiring cert

* add NS rules back

* add script for multi namespace support
  • Loading branch information
AjayTripathy authored Mar 2, 2023
1 parent 4f09d7f commit 8207a31
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
24 changes: 24 additions & 0 deletions cost-analyzer/scripts/create-admission-controller-tls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

namespace=$1
if [ "$namespace" == "" ]; then
namespace=kubecost
fi

DIRECTORY=$(cd `dirname $0` && pwd)

echo "Creating certificates"
mkdir certs
openssl genrsa -out certs/tls.key 2048
openssl req -new -key certs/tls.key -out certs/tls.csr -subj "/CN=webhook-server.$namespace.svc"
openssl x509 -req -days 500 -extfile <(printf "subjectAltName=DNS:webhook-server.$namespace.svc") -in certs/tls.csr -signkey certs/tls.key -out certs/tls.crt

echo "Creating Webhook Server TLS Secret"
kubectl create secret tls webhook-server-tls \
--cert "certs/tls.crt" \
--key "certs/tls.key" -n $namespace


echo "Updating values.yaml"
ENCODED_CA=$(cat certs/tls.crt | base64 | tr -d '\n')
sed -i 's@${CA_BUNDLE}@'"$ENCODED_CA"'@g' ../values.yaml
22 changes: 22 additions & 0 deletions cost-analyzer/templates/cost-analyzer-deployment-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ spec:
path: kc.key
{{- end }}
{{- end }}
{{- if .Values.kubecostAdmissionController }}
{{- if .Values.kubecostAdmissionController.enabled }}
{{- if .Values.kubecostAdmissionController.secretName }}
- name: webhook-server-tls
secret:
secretName: {{ .Values.kubecostAdmissionController.secretName }}
items:
- key: tls.crt
path: tls.crt
- key: tls.key
path: tls.key
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.saml }}
{{- if .Values.saml.enabled }}
{{- if .Values.saml.secretName }}
Expand Down Expand Up @@ -404,6 +418,14 @@ spec:
mountPath: /var/configs/etl/federated
readOnly: true
{{- end }}
{{- if .Values.kubecostAdmissionController }}
{{- if .Values.kubecostAdmissionController.enabled }}
{{- if .Values.kubecostAdmissionController.secretName }}
- name: {{ .Values.kubecostAdmissionController.secretName }}
mountPath: /certs
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.federatedETL }}
{{- if .Values.federatedETL.federator.enabled }}
- name: federator-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: Service
metadata:
name: webhook-server
namespace: kubecost
namespace: {{.Release.Namespace}}
spec:
selector:
{{ include "cost-analyzer.selectorLabels" . | nindent 4 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ metadata:
webhooks:
- name: "kubecost-deployment-validation.kubecost.svc"
failurePolicy: Ignore
namespaceSelector:
matchExpressions:
- key: kubernetes.io/metadata.name
operator: In
values: [ "kubecost" ]
rules:
- operations: [ "CREATE", "UPDATE" ]
apiGroups: [ "apps" ]
Expand All @@ -20,10 +15,14 @@ webhooks:
scope: "*"
clientConfig:
service:
namespace: kubecost
namespace: {{.Release.Namespace}}
name: webhook-server
path: "/validate"
{{- if .Values.kubecostAdmissionController.caBundle }}
caBundle: {{ .Values.kubecostAdmissionController.caBundle }}
{{- else }}
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQWV5Z0F3SUJBZ0lVR3E2YkdOaEowVjRsb0NiWHhUa0pocWkwUnB3d0RRWUpLb1pJaHZjTkFRRUwKQlFBd0pqRWtNQ0lHQTFVRUF3d2JkMlZpYUc5dmF5MXpaWEoyWlhJdWEzVmlaV052YzNRdWMzWmpNQjRYRFRJegpNREl3T1RFNU1UVTFNbG9YRFRJME1EWXlNekU1TVRVMU1sb3dKakVrTUNJR0ExVUVBd3diZDJWaWFHOXZheTF6ClpYSjJaWEl1YTNWaVpXTnZjM1F1YzNaak1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFB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JzME09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
{{- end }}
admissionReviewVersions: ["v1"]
sideEffects: None
timeoutSeconds: 5
Expand Down
5 changes: 5 additions & 0 deletions cost-analyzer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,8 @@ kubecostAdmissionController:
# mountPath: "/some/custom/path/productkey.json" # (use instead of secretname) declare the path at which the product key file is mounted (eg. by a secrets provisioner). The file must be of format { "key": "kc-b1325234" }
# cloudIntegrationSecret: "cloud-integration"
# ingestPodUID: false # Enables using UIDs to uniquely ID pods. This requires either Kubecost's replicated KSM metrics, or KSM v2.1.0+. This may impact performance, and changes the default cost-model allocation behavior.

#kubecostAdmissionController:
# enabled: true
# secretName: webhook-server-tls
# caBundle: ${CA_BUNDLE}

0 comments on commit 8207a31

Please sign in to comment.