Skip to content

Commit

Permalink
support staging and licenseKey on the config
Browse files Browse the repository at this point in the history
  • Loading branch information
kang-makes committed Oct 23, 2023
1 parent 8251ec6 commit 7ec3d4b
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 38 deletions.
10 changes: 5 additions & 5 deletions charts/super-agent-deployment/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
config:
opamp:
endpoint: https://opamp.service.newrelic.com/v1/opamp
headers:
api-key: 1234567890abcdef1234567890abcdef12345678
global:
licenseKey: 1234567890abcdef1234567890abcdef12345678

# The agent is going to test that is able to call OpAmp service so we set a valid server to connect to.
nrStaging: true
68 changes: 59 additions & 9 deletions charts/super-agent-deployment/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,22 +1,72 @@
{{- /*
`newrelic-super-agent.config` builds the configuration from config on the values and add more config options like
Return the name of the configMap holding the Super Agent's config. Defaults to release's fill name suffiexed with "-config"
*/ -}}
{{- define "newrelic-super-agent.config.name" -}}
{{- .Values.config.name | default (include "newrelic.common.naming.truncateToDNSWithSuffix" ( dict "name" (include "newrelic.common.naming.fullname" .) "suffix" "config" )) -}}
{{- end -}}


{{- /*
Return the key name of the configMap holding the Super Agent's config. Defaults to "config.yaml"
*/ -}}
{{- define "newrelic-super-agent.config.key" -}}
{{- .Values.config.key | default "config.yaml" -}}
{{- end -}}
{{- /*
This function simply templates the default configuration for the agent.
*/ -}}
{{- define "newrelic-super-agent.config.defaultConfig" -}}
opamp:
endpoint: COMPLETE-ME
headers:
api-key: COMPLETE-ME
{{- end -}}
{{- /*
Builds the configuration from config on the values and add more config options like
cluster name, licenses, and custom attributes
*/ -}}
{{- define "newrelic-super-agent.config" -}}
{{- define "newrelic-super-agent.config.content" -}}
{{- /*
TODO:
This snippet should execute always to block all unsupported features from the common-lirary that are not yet supported
by this chart.
There are a lot of TODOs to be made in this chart yet and some of them are going to impact the YAML that holds the
config.
TODO: Remove this file when the Super Agent supports licensekey as an envVar.
*/ -}}
{{ $licenseKey := include "newrelic.common.license._licenseKey" . }}
{{- if or (include "newrelic.common.license._customSecretName" .) (include "newrelic.common.license._customSecretKey" .) -}}
{{- fail "Common library supports setting an external custom secret for the license but the super agent still does not support the license by an env var. You must specify a .licenseKey or .global.licenseKey" -}}
{{- end -}}
{{- if not $licenseKey -}}
{{- fail "You must specify .licenseKey or .global.licenseKey" -}}
{{- end -}}
This is the helper that templates the config. For this iteration we simply copy the `config` object from the values
and template it in the config map.
{{- /*
TODO: There are a lot of TODOs to be made in this chart yet and some of them are going to impact the YAML that holds
the config.
If you need a list of TODOs, just `grep TODO` on the `values.yaml` and look for things that are yet to be implemented.
*/ -}}
{{- $config := fromYaml (include "newrelic-super-agent.config.defaultConfig" .) -}}
{{- if .Values.config.content -}}
{{- $_ := deepCopy .Values.config.content | mustMergeOverwrite $config -}}
{{- end -}}
{{- if .Values.config -}}
{{- .Values.config | toYaml -}}
{{- if include "newrelic.common.fedramp.enabled" . -}}
{{- fail "FedRAMP is not supported yet" -}}{{- /* TODO: Add FedRamp support */ -}}
{{- else if include "newrelic.common.nrStaging" . -}}
{{- $_ := set $config.opamp "endpoint" "https://opamp.staging-service.newrelic.com/v1/opamp" -}}
{{- else -}}
{{- /* TODO: Is this the prod URL? */ -}}
{{- $_ := set $config.opamp "endpoint" "https://opamp.service.newrelic.com/v1/opamp" -}}
{{- end -}}
{{- /* We have to use common library internals because the agent does not support envvars yet */ -}}
{{- /* TODO: Remove this when the sa supports licenseKeys from envVars */ -}}
{{- $_ := set $config.opamp.headers "api-key" $licenseKey -}}
{{- $config | toYaml -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{{- $name := include "newrelic.common.naming.truncateToDNSWithSuffix" ( dict "name" (include "newrelic.common.naming.fullname" .) "suffix" "config" ) -}}
{{- $namespace := .Release.Namespace -}}
{{- with ( include "newrelic-super-agent.config" . ) -}}
{{- if .Values.config.create -}}
---
kind: ConfigMap
metadata:
name: {{ $name }}
namespace: {{ $namespace }}
name: {{ include "newrelic-super-agent.config.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "newrelic.common.labels" $ | nindent 4 }}
apiVersion: v1
data:
config.yaml: |
{{- . | nindent 4 }}
{{ include "newrelic-super-agent.config.key" . }}: |
{{- include "newrelic-super-agent.config.content" . | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ spec:
volumes:
- name: super-agent-config
configMap:
name: {{ include "newrelic.common.naming.truncateToDNSWithSuffix" ( dict "name" (include "newrelic.common.naming.fullname" .) "suffix" "config" ) }}
name: {{ include "newrelic-super-agent.config.name" . }}
items:
- key: {{ include "newrelic-super-agent.config.key" . }}
path: config.yaml

{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 8 }}
Expand Down
18 changes: 14 additions & 4 deletions charts/super-agent-deployment/tests/configmap_config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ release:
name: my-release
namespace: my-namespace
tests:
- it: super agent's config does not template
- it: super agent's config can be disabled
set:
config: ""
global:
licenseKey: test
config:
create: false
asserts:
- hasDocuments:
count: 0
- it: super agent's config templates
set:
global:
licenseKey: test
config:
test: value
test2: value2
content:
test: value
test2: value2
asserts:
- equal:
path: data["config.yaml"]
value: |
opamp:
endpoint: https://opamp.service.newrelic.com/v1/opamp
headers:
api-key: test
test: value
test2: value2
36 changes: 36 additions & 0 deletions charts/super-agent-deployment/tests/licenseKey_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
suite: licenseKey temporary tests
# These tests are to test that a missing licenseKey actually aborts templating the chart.
# This should be something that the common-library should do, but the common library does
# it while templating the secret with the license to be used as a envVar.
# As the super agent does not support it as a envvar (yet), we added it directly on the
# configuration file. The consequence is that the chart is able to template without
# license.
# TODO: Remove this file when the Super Agent supports licensekey as an envVar.
templates:
- templates/configmap-superagent-config.yaml
release:
name: my-release
namespace: my-namespace
tests:
- it: Empty licenses abort the template
set:
global:
licenseKey: ""
licenseKey: ""
asserts:
- failedTemplate:
errorMessage: You must specify .licenseKey or .global.licenseKey
- it: Using custom secret abort the template
set:
global:
customSecretName: non-empty
asserts:
- failedTemplate:
errorMessage: Common library supports setting an external custom secret for the license but the super agent still does not support the license by an env var. You must specify a .licenseKey or .global.licenseKey
- it: Using custom secret abort the template
set:
global:
customSecretLicenseKey: non-empty
asserts:
- failedTemplate:
errorMessage: Common library supports setting an external custom secret for the license but the super agent still does not support the license by an env var. You must specify a .licenseKey or .global.licenseKey
28 changes: 16 additions & 12 deletions charts/super-agent-deployment/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fullnameOverride: ""

# -- TODO: Name of the Kubernetes cluster monitored. Can be configured also with `global.cluster`.
cluster: ""
# -- TODO: This set this license key to use. Can be configured also with `global.licenseKey`
# -- This set this license key to use. Can be configured also with `global.licenseKey`
licenseKey: ""
# -- TODO: In case you don't want to have the license key in you values, this allows you to point to a user created secret to get the key from there. Can be configured also with `global.customSecretName`
customSecretName: ""
Expand Down Expand Up @@ -79,25 +79,29 @@ customAttributes: {}
# -- TODO: Configures the integration to send all HTTP/HTTPS request through the proxy in that URL. The URL should have a standard format like `https://user:password@hostname:port`. Can be configured also with `global.proxy`
proxy: ""

# -- (bool) TODO: Send the metrics to the staging backend. Requires a valid staging license key. Can be configured also with `global.nrStaging`
# -- (bool) Send the metrics to the staging backend. Requires a valid staging license key. Can be configured also with `global.nrStaging`
# @default -- `false`
nrStaging:

fedramp:
# -- (bool) TODO: Enables FedRAMP. Can be configured also with `global.fedramp.enabled`
# -- (bool) Enables FedRAMP. Can be configured also with `global.fedramp.enabled`
# @default -- `false`
enabled:

# -- (bool) TODO: Sets the debug logs to this integration or all integrations if it is set globally. Can be configured also with `global.verboseLog`
# @default -- `false`
verboseLog:

# -- Here you can set New Relic' Super Agent configuration.
# @default -- See `values.yaml` for examples
config: {}
# opamp:
# headers:
# some-key: some-value
# agents:
# agent_1:
# agent_type: namespace/agent_type:0.0.1
config:
create: true
name: ""
key: ""
# -- Here you can set New Relic' Super Agent configuration.
# @default -- See `values.yaml` for examples
content:
# opamp:
# headers:
# some-key: some-value
# agents:
# agent_1:
# agent_type: namespace/agent_type:0.0.1

0 comments on commit 7ec3d4b

Please sign in to comment.