Skip to content

Commit

Permalink
[super-agent-deployment] Add fleet configmap (#1221)
Browse files Browse the repository at this point in the history
#### Is this a new chart
No

#### What this PR does / why we need it:
This allows the super agent deployment to have fleet configurations.

#### Special notes for your reviewer:
Installability might fail because I made a breaking change on the
`values.yaml` file.

#### Checklist
- [x] Chart Version bumped
- [x] Variables are documented in the README.md
- [x] Title of the PR starts with chart name (e.g. `[mychartname]`)
  • Loading branch information
kilokang authored Dec 20, 2023
1 parent ce48011 commit c3bc152
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 41 deletions.
2 changes: 1 addition & 1 deletion charts/super-agent-deployment/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: super-agent-deployment
description: A Helm chart to install New Relic Super agent on Kubernetes

type: application
version: 0.0.4-beta
version: 0.0.5-beta
appVersion: nightly # TODO: Change this with a proper version of the image.

dependencies:
Expand Down
12 changes: 7 additions & 5 deletions charts/super-agent-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# super-agent-deployment

![Version: 0.0.0-beta](https://img.shields.io/badge/Version-0.0.0--beta-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: nightly](https://img.shields.io/badge/AppVersion-nightly-informational?style=flat-square)
![Version: 0.0.5-beta](https://img.shields.io/badge/Version-0.0.5--beta-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: nightly](https://img.shields.io/badge/AppVersion-nightly-informational?style=flat-square)

A Helm chart to install New Relic Super agent on Kubernetes

Expand Down Expand Up @@ -36,10 +36,12 @@ At the point of the creation of the chart, it has no particularities and this se
|-----|------|---------|-------------|
| affinity | object | `{}` | Sets pod/node affinities. Can be configured also with `global.affinity` |
| cluster | string | `""` | TODO: Name of the Kubernetes cluster monitored. Can be configured also with `global.cluster`. |
| config.content | string | See `values.yaml` for examples | Here you can set New Relic' Super Agent configuration. |
| config.create | bool | `true` | Set if the configMap is going to be created by this chart or the user will provide its own. |
| config.key | string | `""` | The key in the configMap that has the configuration for the Super Agent. |
| config.name | string | `""` | The name the configMap is going to have. If create is set to false, the name of an existing configMap that will be used to config the Super Agent. |
| config.subAgents | object | See `values.yaml` for examples | Values that the fleet is going to have in the deployment. |
| config.superAgent | object | See `values.yaml` | Configuration for the Super Agent. |
| config.superAgent.content | string | See `values.yaml` for examples | Here you can set New Relic' Super Agent configuration. |
| config.superAgent.create | bool | `true` | Set if the configMap is going to be created by this chart or the user will provide its own. |
| config.superAgent.key | string | `""` | The key in the configMap that has the configuration for the Super Agent. |
| config.superAgent.name | string | `""` | The name the configMap is going to have. If create is set to false, the name of an existing configMap that will be used to config the Super Agent. |
| containerSecurityContext | object | `{}` | Sets security context (at container level). Can be configured also with `global.containerSecurityContext` |
| customAttributes | object | `{}` | TODO: Adds extra attributes to the cluster and all the metrics emitted to the backend. Can be configured also with `global.customAttributes` |
| customSecretLicenseKey | string | `""` | TODO: In case you don't want to have the license key in you values, this allows you to point to which secret key is the license key located. Can be configured also with `global.customSecretLicenseKey` |
Expand Down
19 changes: 17 additions & 2 deletions charts/super-agent-deployment/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
cluster: sa-cluster
config:
content:
agents: {}
superAgent:
content:
agents: {}
subAgents:
test-0:
content:
a: test
value: 0
test-1:
content:
a: test
value: 1
test-2:
content:
a: test
aYAML:
canI: HaveSomeYAML
6 changes: 3 additions & 3 deletions charts/super-agent-deployment/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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" )) -}}
{{- .Values.config.superAgent.name | default (include "newrelic.common.naming.truncateToDNSWithSuffix" ( dict "name" (include "newrelic.common.naming.fullname" .) "suffix" "superagent-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" -}}
{{- .Values.config.superAgent.key | default "config.yaml" -}}
{{- end -}}
Expand All @@ -36,7 +36,7 @@ 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 := .Values.config.content | default dict -}}
{{- $config := .Values.config.superAgent.content | default dict -}}
{{- $config = mustMergeOverwrite (dict "k8s" (dict "cluster_name" (include "newrelic.common.cluster" .))) $config -}}
{{- $config = mustMergeOverwrite (dict "k8s" (dict "namespace" .Release.Namespace)) $config -}}
{{- $config | toYaml -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- range $subAgentName, $subAgentConfig := .Values.config.subAgents -}}
{{- $releasePrefix := include "newrelic.common.naming.fullname" $ -}}
{{- $configName := printf "%s-%s" "subagent" $subAgentName -}}
{{- $name := include "newrelic.common.naming.truncateToDNSWithSuffix" (dict "name" $releasePrefix "suffix" $configName) }}
---
kind: ConfigMap
metadata:
name: {{ $name }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "newrelic.common.labels" $ | nindent 4 }}
subagent: {{ $subAgentName }}
apiVersion: v1
data:
values.yml: |
{{- $subAgentConfig.content | toYaml | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{- if .Values.config.create -}}
{{- if .Values.config.superAgent.create -}}
---
kind: ConfigMap
metadata:
name: {{ include "newrelic-super-agent.config.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "newrelic.common.labels" $ | nindent 4 }}
{{- include "newrelic.common.labels" . | nindent 4 }}
apiVersion: v1
data:
{{ include "newrelic-super-agent.config.key" . }}: |
{{ include "newrelic-super-agent.config.key" . }}: |
{{- include "newrelic-super-agent.config.content" . | nindent 4 }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/super-agent-deployment/templates/deployment-superagent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
metadata:
annotations:
checksum/agent-config: {{ include (print $.Template.BasePath "/configmap-superagent-config.yaml") . | sha256sum }}
checksum/subagent-config: {{ include (print $.Template.BasePath "/configmap-subagent-configs.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -67,6 +68,14 @@ spec:
- name: super-agent-config
mountPath: /etc/newrelic-super-agent
readOnly: true
{{- range $subAgentName, $subAgentConfig := .Values.config.subAgents }}
{{- $releaseSuffx := include "newrelic.common.naming.fullname" $ }}
{{- $configName := printf "%s-%s" "subagent" $subAgentName }}
{{- $name := include "newrelic.common.naming.truncateToDNSWithSuffix" (dict "name" $releaseSuffx "suffix" $configName) }}
- name: subagent-configmap-{{ $name }}
mountPath: /etc/newrelic-super-agent/fleet/agents.d/{{ $subAgentName }}
readOnly: true
{{- end }}
# TODO: when releasing we should check if this is still needed and if we need to persist the data.
- mountPath: /var/lib/newrelic-super-agent
name: var-lib-newrelic-super-agent
Expand All @@ -84,6 +93,15 @@ spec:
items:
- key: {{ include "newrelic-super-agent.config.key" . }}
path: config.yaml
{{- range $subAgentName, $subAgentConfig := .Values.config.subAgents }}
{{- $releaseSuffx := include "newrelic.common.naming.fullname" $ }}
{{- $configName := printf "%s-%s" "subagent" $subAgentName }}
{{- $name := include "newrelic.common.naming.truncateToDNSWithSuffix" (dict "name" $releaseSuffx "suffix" $configName) }}
- name: subagent-configmap-{{ $name }}
configMap:
name: {{ $name }}
{{- end }}

- name: var-lib-newrelic-super-agent
emptyDir: {}
{{- with .Values.extraVolumes }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
suite: subagent configurations
templates:
- templates/configmap-subagent-configs.yaml
release:
name: my-release
namespace: my-namespace
tests:
- it: does not template nothing by default
asserts:
- hasDocuments:
count: 0
- it: super agent's config template correctly
set:
config:
subAgents:
test-0:
content:
a: test
value: 0
test-1:
content:
a: test
value: 1
test-2:
content:
a: test
aYAML:
canI: HaveSomeYAML
asserts:
- hasDocuments:
count: 3

- documentIndex: 0
equal:
path: metadata.name
value: my-release-super-agent-deployment-subagent-test-0
- documentIndex: 0
equal:
path: data["values.yml"]
value: |
a: test
value: 0
- documentIndex: 1
equal:
path: metadata.name
value: my-release-super-agent-deployment-subagent-test-1
- documentIndex: 1
equal:
path: data["values.yml"]
value: |
a: test
value: 1
- documentIndex: 2
equal:
path: metadata.name
value: my-release-super-agent-deployment-subagent-test-2
- documentIndex: 2
equal:
path: data["values.yml"]
value: |
a: test
aYAML:
canI: HaveSomeYAML
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suite: super agent's config values are honored
suite: super agent's config
templates:
- templates/configmap-superagent-config.yaml
release:
Expand All @@ -8,14 +8,16 @@ tests:
- it: super agent's config can be disabled
set:
config:
create: false
superAgent:
create: false
asserts:
- hasDocuments:
count: 0
- it: super agent's config always include cluster_name and namespace
set:
cluster: my-cluster
config: {}
config:
superAgent: {}
asserts:
- equal:
path: data["config.yaml"]
Expand All @@ -27,9 +29,10 @@ tests:
set:
cluster: my-cluster
config:
content:
test: value
test2: value2
superAgent:
content:
test: value
test2: value2
asserts:
- equal:
path: data["config.yaml"]
Expand All @@ -43,12 +46,13 @@ tests:
set:
cluster: my-cluster
config:
content:
test: value
test2: value2
k8s:
cluster_name: config-cluster
namespace: config-namespace
superAgent:
content:
test: value
test2: value2
k8s:
cluster_name: config-cluster
namespace: config-namespace
asserts:
- equal:
path: data["config.yaml"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
suite: test securityContext
suite: test super agent deployment's securityContext
templates:
- templates/deployment-superagent.yaml
- templates/configmap-superagent-config.yaml
- templates/configmap-subagent-configs.yaml
tests:
- it: securityContext.runAsUser is populated with defaults
set:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
suite: test super agent deployment's subagent configurations
templates:
- templates/deployment-superagent.yaml
- templates/configmap-superagent-config.yaml
- templates/configmap-subagent-configs.yaml
release:
name: my-release
namespace: my-namespace
tests:

- it: there are no subagent configurations by default
set:
cluster: test
asserts:
- template: templates/deployment-superagent.yaml
equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- name: super-agent-config
mountPath: /etc/newrelic-super-agent
readOnly: true
- mountPath: /var/lib/newrelic-super-agent
name: var-lib-newrelic-super-agent
readOnly: false
- template: templates/deployment-superagent.yaml
equal:
path: spec.template.spec.volumes
value:
- name: super-agent-config
configMap:
name: my-release-super-agent-deployment-superagent-config
items:
- key: config.yaml
path: config.yaml
- name: var-lib-newrelic-super-agent
emptyDir: {}

- it: subagent configurations template file mounts
set:
cluster: test
config:
subAgents:
test-0:
content:
a: test
value: 0
test-1:
content:
a: test
value: 1
test-2:
content:
a: test
aYAML:
canI: HaveSomeYAML
asserts:
- template: templates/deployment-superagent.yaml
equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- name: super-agent-config
mountPath: /etc/newrelic-super-agent
readOnly: true
- name: subagent-configmap-my-release-super-agent-deployment-subagent-test-0
mountPath: /etc/newrelic-super-agent/fleet/agents.d/test-0
readOnly: true
- name: subagent-configmap-my-release-super-agent-deployment-subagent-test-1
mountPath: /etc/newrelic-super-agent/fleet/agents.d/test-1
readOnly: true
- name: subagent-configmap-my-release-super-agent-deployment-subagent-test-2
mountPath: /etc/newrelic-super-agent/fleet/agents.d/test-2
readOnly: true
- mountPath: /var/lib/newrelic-super-agent
name: var-lib-newrelic-super-agent
readOnly: false
- template: templates/deployment-superagent.yaml
equal:
path: spec.template.spec.volumes
value:
- name: super-agent-config
configMap:
name: my-release-super-agent-deployment-superagent-config
items:
- key: config.yaml
path: config.yaml
- name: subagent-configmap-my-release-super-agent-deployment-subagent-test-0
configMap:
name: my-release-super-agent-deployment-subagent-test-0
- name: subagent-configmap-my-release-super-agent-deployment-subagent-test-1
configMap:
name: my-release-super-agent-deployment-subagent-test-1
- name: subagent-configmap-my-release-super-agent-deployment-subagent-test-2
configMap:
name: my-release-super-agent-deployment-subagent-test-2
- name: var-lib-newrelic-super-agent
emptyDir: {}



Loading

0 comments on commit c3bc152

Please sign in to comment.