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

chore(setup): pass secret name and namespace as TF variables #3767

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion deploy/helm/sumologic/conf/cleanup/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ export HTTPS_PROXY="${HTTPS_PROXY:=""}"
export NO_PROXY="${NO_PROXY:=""}"

readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"

# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"
export TF_VAR_namespace_name="${NAMESPACE:?}"

cp /etc/terraform/* /terraform/
cd /terraform || exit 1
Expand All @@ -25,7 +28,7 @@ terraform init -input=false -get=false || terraform init -input=false -upgrade
# shellcheck disable=SC1083
terraform import sumologic_collector.collector "${SUMOLOGIC_COLLECTOR_NAME}"
# shellcheck disable=SC1083
terraform import kubernetes_secret.sumologic_collection_secret {{ template "terraform.secret.fullname" . }}
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"

terraform destroy -auto-approve

Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/sumologic/conf/setup/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "sumologic_collector" "collector" {

resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "{{ template "terraform.secret.name" }}"
name = var.secret_name
namespace = var.namespace_name
}

Expand Down
6 changes: 5 additions & 1 deletion deploy/helm/sumologic/conf/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"

# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"

# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
Expand Down Expand Up @@ -148,7 +152,7 @@ terraform import sumologic_http_source.{{ template "terraform.sources.name" (dic
fi

# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret {{ template "terraform.secret.fullname" . }}
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"

# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down
5 changes: 4 additions & 1 deletion deploy/helm/sumologic/conf/setup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ variable "collector_name" {

variable "namespace_name" {
type = string
default = "{{ template "sumologic.namespace" . }}"
}

variable "secret_name" {
type = string
}

variable "create_fields" {
Expand Down
12 changes: 0 additions & 12 deletions deploy/helm/sumologic/templates/_helpers/_setup.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ Example usage:
{{ printf "%s" "sumologic" }}
{{- end -}}

{{/*
Returns the name of Kubernetes secret prefixed with release namespace.

Example usage:

{{ include "terraform.secret.fullname" }}

*/}}
{{- define "terraform.secret.fullname" -}}
{{ template "sumologic.namespace" . }}/{{ template "terraform.secret.name" . }}
{{- end -}}

{{/*
Convert source name to Terraform metric name:
* converts all `-` to `_`
Expand Down
6 changes: 6 additions & 0 deletions deploy/helm/sumologic/templates/cleanup/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ spec:
- secretRef:
name: {{ .Values.sumologic.envFromSecret | default (include "sumologic.metadata.name.setup.secret" .)}}
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
{{- if eq (include "sumologic-mock.local-mode-enabled" .) "true" }}
value: http://{{ template "sumologic-mock.hostname" . }}:{{ template "sumologic-mock.port" . }}/terraform/api/
Expand All @@ -62,6 +66,8 @@ spec:
value: {{ include "terraform.collector.name" . }}
- name: CHART_VERSION
value: "{{ .Chart.Version }}"
- name: SUMOLOGIC_SECRET_NAME
value: "{{ template "terraform.secret.name" }}"
{{- include "proxy-env-variables" . | nindent 10 }}
securityContext:
runAsUser: 999
Expand Down
6 changes: 6 additions & 0 deletions deploy/helm/sumologic/templates/setup/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ spec:
- secretRef:
name: {{ .Values.sumologic.envFromSecret | default (include "sumologic.metadata.name.setup.secret" .)}}
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
{{- if eq (include "sumologic-mock.local-mode-enabled" .) "true" }}
value: http://{{ template "sumologic-mock.hostname" . }}:{{ template "sumologic-mock.port" . }}/terraform/api/
Expand All @@ -75,6 +79,8 @@ spec:
{{- end }}
- name: SUMOLOGIC_COLLECTOR_NAME
value: {{ include "terraform.collector.name" . }}
- name: SUMOLOGIC_SECRET_NAME
value: "{{ template "terraform.secret.name" }}"
- name: CHART_VERSION
value: "{{ .Chart.Version }}"
{{- include "proxy-env-variables" . | nindent 8 -}}
Expand Down
6 changes: 6 additions & 0 deletions tests/helm/testdata/goldenfile/cleanup/basic.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ spec:
- secretRef:
name: RELEASE-NAME-sumologic-setup
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
value:
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"

- name: NO_PROXY
value: kubernetes.default.svc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ spec:
- secretRef:
name: RELEASE-NAME-sumologic-setup
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
value: http://RELEASE-NAME-sumologic-mock.sumologic.svc.cluster.local.:3000/terraform/api/
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"

- name: NO_PROXY
value: kubernetes.default.svc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ spec:
- secretRef:
name: RELEASE-NAME-sumologic-setup
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
value: http://RELEASE-NAME-sumologic-mock.sumologic.svc.cluster.local.:3000/terraform/api/
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"

- name: NO_PROXY
value: kubernetes.default.svc
Expand Down
6 changes: 6 additions & 0 deletions tests/helm/testdata/goldenfile/setup/basic.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ spec:
- secretRef:
name: RELEASE-NAME-sumologic-setup
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
value:
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ spec:
- secretRef:
name: RELEASE-NAME-sumologic-setup
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
value: http://RELEASE-NAME-sumologic-mock.sumologic.svc.cluster.local.:3000/terraform/api/
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ spec:
- secretRef:
name: RELEASE-NAME-sumologic-setup
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: SUMOLOGIC_BASE_URL
value: http://RELEASE-NAME-sumologic-mock.sumologic.svc.cluster.local.:3000/terraform/api/
- name: SUMOLOGIC_COLLECTOR_NAME
value: kubernetes
- name: SUMOLOGIC_SECRET_NAME
value: "sumologic"
- name: CHART_VERSION
value: "%CURRENT_CHART_VERSION%"

Expand Down
13 changes: 10 additions & 3 deletions tests/helm/testdata/goldenfile/terraform/all_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:

resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}

Expand All @@ -354,9 +354,13 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"

# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"

# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
Expand Down Expand Up @@ -498,7 +502,7 @@ data:
fi

# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"

# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -836,7 +840,10 @@ data:

variable "namespace_name" {
type = string
default = "sumologic"
}

variable "secret_name" {
type = string
}

variable "create_fields" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:

resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}

Expand All @@ -354,9 +354,13 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"

# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"

# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
Expand Down Expand Up @@ -497,7 +501,7 @@ data:
fi

# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"

# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -739,7 +743,10 @@ data:

variable "namespace_name" {
type = string
default = "sumologic"
}

variable "secret_name" {
type = string
}

variable "create_fields" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ data:

resource "kubernetes_secret" "sumologic_collection_secret" {
metadata {
name = "sumologic"
name = var.secret_name
namespace = var.namespace_name
}

Expand All @@ -354,9 +354,13 @@ data:
readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly SUMOLOGIC_COLLECTOR_NAME="${SUMOLOGIC_COLLECTOR_NAME:?}"
readonly NAMESPACE="${NAMESPACE:?}"
readonly SUMOLOGIC_SECRET_NAME="${SUMOLOGIC_SECRET_NAME:?}"

# Set variables for terraform
export TF_VAR_collector_name="${SUMOLOGIC_COLLECTOR_NAME}"
export TF_VAR_namespace_name="${NAMESPACE}"
export TF_VAR_secret_name="${SUMOLOGIC_SECRET_NAME}"
export TF_VAR_chart_version="${CHART_VERSION:?}"

# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
Expand Down Expand Up @@ -482,7 +486,7 @@ data:
fi

# Kubernetes Secret
terraform import kubernetes_secret.sumologic_collection_secret sumologic/sumologic
terraform import kubernetes_secret.sumologic_collection_secret "${NAMESPACE}/${SUMOLOGIC_SECRET_NAME}"

# Apply planned changes
TF_LOG_PROVIDER=DEBUG terraform apply \
Expand Down Expand Up @@ -535,7 +539,10 @@ data:

variable "namespace_name" {
type = string
default = "sumologic"
}

variable "secret_name" {
type = string
}

variable "create_fields" {
Expand Down
Loading
Loading