Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional checks for 2.0: leader-follower, statefulSet, cloud-integration configs #3066

Merged
merged 10 commits into from
Feb 15, 2024
3 changes: 3 additions & 0 deletions cost-analyzer/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
{{- include "cloudIntegrationSourceCheck" . -}}
{{- include "eksCheck" . -}}
{{- include "cloudIntegrationSecretCheck" . -}}
{{- include "gcpCloudIntegrationCheck" . -}}
{{- include "azureCloudIntegrationCheck" . -}}
{{- include "federatedStorageConfigSecretCheck" . -}}

{{- $servicePort := .Values.service.port | default 9090 }}
Kubecost {{ .Chart.Version }} has been successfully installed.

Expand Down
82 changes: 75 additions & 7 deletions cost-analyzer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Kubecost 2.0 preconditions

{{/*https://github.com/helm/helm/issues/8026#issuecomment-881216078*/}}
{{- if ((.Values.thanos).store).enabled -}}
{{- fail "\n\nYou are attempting to upgrade to Kubecost 2.0.\nKubecost no longer includes Thanos by default. \nPlease see https://docs.kubecost.com/install-and-configure/install/kubecostv2 for more information.\nIf you have any questions or concerns, please reach out to us at [email protected]" -}}
{{- fail "\n\nYou are attempting to upgrade to Kubecost 2.x.\nKubecost no longer includes Thanos by default. \nPlease see https://docs.kubecost.com/install-and-configure/install/kubecostv2 for more information.\nIf you have any questions or concerns, please reach out to us at [email protected]" -}}
{{- end -}}

{{- if or (((.Values.global).amp).enabled) (((.Values.global).gmp).enabled) (((.Values.global).thanos).queryService) (((.Values.global).mimirProxy).enabled) -}}
Expand Down Expand Up @@ -91,10 +91,19 @@ Kubecost 2.0 preconditions
{{- fail "Kubecost no longer includes PodSecurityPolicy by default. Please take steps to preserve your existing PSPs before attempting the installation/upgrade again with the podSecurityPolicy values removed." }}
{{- end }}

{{- if ((.Values.kubecostDeployment).leaderFollower).enabled -}}
{{- fail "\nIn Kubecost 2.0, kubecostDeployment does not support running as leaderFollower. Please reach out to support to discuss upgrade paths." -}}
{{- end -}}

{{- if ((.Values.kubecostDeployment).statefulSet).enabled -}}
{{- fail "\nIn Kubecost 2.0, kubecostDeployment does not support running as a statefulSet. Please reach out to support to discuss upgrade paths." -}}
{{- end -}}

{{- end -}}

{{- define "cloudIntegrationFromProductConfigs" }}
{
{{- if ((.Values.kubecostProductConfigs).athenaBucketName) }}
"aws": [
{
"athenaBucketName": "{{ .Values.kubecostProductConfigs.athenaBucketName }}",
Expand All @@ -116,6 +125,7 @@ Kubecost 2.0 preconditions
{{- end }}
}
]
{{- end }}
}
{{- end }}

Expand All @@ -126,10 +136,13 @@ will result in failure. Users are asked to select one of the two presently-avail
*/}}
{{- define "cloudIntegrationSourceCheck" -}}
{{- if and (.Values.kubecostProductConfigs).cloudIntegrationSecret (.Values.kubecostProductConfigs).cloudIntegrationJSON -}}
{{- fail "\ncloudIntegrationSecret and cloudIntegrationJSON are mutually exclusive. Please specify only one." -}}
{{- fail "\nkubecostProductConfigs.cloudIntegrationSecret and kubecostProductConfigs.cloudIntegrationJSON are mutually exclusive. Please specify only one." -}}
{{- end -}}
{{- if and (.Values.kubecostProductConfigs).cloudIntegrationSecret ((.Values.kubecostProductConfigs).athenaBucketName) }}
{{- fail "\nkubecostProductConfigs.cloudIntegrationSecret and kubecostProductConfigs.athena* values are mutually exclusive. Please specifiy only one." -}}
jessegoodier marked this conversation as resolved.
Show resolved Hide resolved
{{- end -}}
{{- if and (.Values.kubecostProductConfigs).cloudIntegrationSecret ((.Values.kubecostProductConfigs).athenaProjectID) }}
{{- fail "\nUsing a cloud-integration secret and kubecostProductConfigs.athena* values are mutually exclusive. Please specifiy only one." -}}
{{- if and (.Values.kubecostProductConfigs).cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaBucketName) }}
{{- fail "\nkubecostProductConfigs.cloudIntegrationJSON and kubecostProductConfigs.athena* values are mutually exclusive. Please specifiy only one." -}}
{{- end -}}
{{- end -}}

Expand Down Expand Up @@ -160,7 +173,7 @@ support templating a chart which uses the lookup function.
{{- if .Capabilities.APIVersions.Has "v1/Secret" }}
{{- $secret := lookup "v1" "Secret" .Release.Namespace .Values.kubecostProductConfigs.cloudIntegrationSecret }}
{{- if or (not $secret) (not (index $secret.data "cloud-integration.json")) }}
{{- fail (printf "The cloud integration secret '%s' does not exist or does not contain the expected key 'cloud-integration.json'" .Values.kubecostProductConfigs.cloudIntegrationSecret) }}
{{- fail (printf "The cloud integration secret '%s' does not exist or does not contain the expected key 'cloud-integration.json'\nIf you are using `--dry-run`, please add `--dry-run=server`. This requires Helm 3.13+." .Values.kubecostProductConfigs.cloudIntegrationSecret) }}
{{- end }}
{{- end -}}
{{- end -}}
Expand Down Expand Up @@ -1080,7 +1093,7 @@ Begin Kubecost 2.0 templates
mountPath: /var/configs/etl
readOnly: true
{{- end }}
{{- if or (.Values.kubecostProductConfigs).cloudIntegrationSecret (.Values.kubecostProductConfigs).cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaProjectID) }}
{{- if or (.Values.kubecostProductConfigs).cloudIntegrationSecret (.Values.kubecostProductConfigs).cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaBucketName) }}
- name: cloud-integration
mountPath: /var/configs/cloud-integration
{{- end }}
Expand Down Expand Up @@ -1150,4 +1163,59 @@ SSO enabled flag for nginx configmap
{{- else -}}
{{- printf "false" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "gcpCloudIntegrationJSON" }}
Kubecost 2.x requires a change to the method that cloud-provider billing integrations are configured.
Please use this output to create a cloud-integration.json config. See:
<https://docs.kubecost.com/install-and-configure/install/cloud-integration#adding-a-cloud-integration>
for more information

{
"gcp":
{
[
{
"bigQueryBillingDataDataset": "{{ .Values.kubecostProductConfigs.bigQueryBillingDataDataset }}",
"bigQueryBillingDataProject": "{{ .Values.kubecostProductConfigs.bigQueryBillingDataProject }}",
"bigQueryBillingDataTable": "{{ .Values.kubecostProductConfigs.bigQueryBillingDataTable }}",
"projectID": "{{ .Values.kubecostProductConfigs.projectID }}"
}
]
}
}
{{- end }}

{{- define "gcpCloudIntegrationCheck" }}
{{- if ((.Values.kubecostProductConfigs).bigQueryBillingDataDataset) }}
{{- fail (include "gcpCloudIntegrationJSON" .) }}
{{- end }}
{{- end }}


{{- define "azureCloudIntegrationJSON" }}

Kubecost 2.x requires a change to the method that cloud-provider billing integrations are configured.
Please use this output to create a cloud-integration.json config. See:
<https://docs.kubecost.com/install-and-configure/install/cloud-integration#adding-a-cloud-integration>
for more information
{
"azure":
[
{
"azureStorageContainer": "{{ .Values.kubecostProductConfigs.azureStorageContainer }}",
"azureSubscriptionID": "{{ .Values.kubecostProductConfigs.azureSubscriptionID }}",
"azureStorageAccount": "{{ .Values.kubecostProductConfigs.azureStorageAccount }}",
"azureStorageAccessKey": "{{ .Values.kubecostProductConfigs.azureStorageKey }}",
"azureContainerPath": "{{ .Values.kubecostProductConfigs.azureContainerPath }}",
"azureCloud": "{{ .Values.kubecostProductConfigs.azureCloud }}"
}
]
}
{{- end }}

{{- define "azureCloudIntegrationCheck" }}
{{- if ((.Values.kubecostProductConfigs).azureStorageContainer) }}
{{- fail (include "azureCloudIntegrationJSON" .) }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{/*
A cloud integration secret is required for cloud cost to function as a dedicated pod.
*/}}
{{- if or (.Values.kubecostProductConfigs).cloudIntegrationSecret (.Values.kubecostProductConfigs).cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaProjectID) }}
{{- if or (.Values.kubecostProductConfigs).cloudIntegrationSecret (.Values.kubecostProductConfigs).cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaBucketName) }}

apiVersion: apps/v1
kind: Deployment
Expand Down
2 changes: 1 addition & 1 deletion cost-analyzer/templates/cloud-integration-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if or ((.Values.kubecostProductConfigs).cloudIntegrationJSON) ((.Values.kubecostProductConfigs).athenaProjectID) }}
{{- if or ((.Values.kubecostProductConfigs).cloudIntegrationJSON) ((.Values.kubecostProductConfigs).athenaBucketName) }}
apiVersion: v1
kind: Secret
type: Opaque
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ spec:
items:
- key: cloud-integration.json
path: cloud-integration.json
{{- else if or .Values.kubecostProductConfigs.cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaProjectID) }}
{{- else if or .Values.kubecostProductConfigs.cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaBucketName) }}
- name: cloud-integration
secret:
secretName: cloud-integration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ spec:
items:
- key: cloud-integration.json
path: cloud-integration.json
{{- else if or .Values.kubecostProductConfigs.cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaProjectID) }}
{{- else if or .Values.kubecostProductConfigs.cloudIntegrationJSON ((.Values.kubecostProductConfigs).athenaBucketName) }}
- name: cloud-integration
secret:
secretName: cloud-integration
Expand Down Expand Up @@ -197,7 +197,7 @@ spec:
- name: azure-storage-config
mountPath: /var/azure-storage-config
{{- end }}
{{- if or (.Values.kubecostProductConfigs.cloudIntegrationSecret) (.Values.kubecostProductConfigs.cloudIntegrationJSON) ((.Values.kubecostProductConfigs).athenaProjectID) }}
{{- if or (.Values.kubecostProductConfigs.cloudIntegrationSecret) (.Values.kubecostProductConfigs.cloudIntegrationJSON) ((.Values.kubecostProductConfigs).athenaBucketName) }}
- name: cloud-integration
mountPath: /var/configs/cloud-integration
{{- end }}
Expand Down