Skip to content

Commit

Permalink
[common-library] Add missing features to the common library (NR-281093)…
Browse files Browse the repository at this point in the history
… (#1463)

#### Is this a new chart
No

#### What this PR does / why we need it:
We thought that some of the features that we need for the super-agent
would be awesome to have them at `common-library` level.

We need the chart to be able to calculate the region (or let the user to
specify it) and a new API Key.

#### Which issue this PR fixes

#### Special notes for your reviewer:
To read it easier, I would go commit by commit as I added a new feature
with its own documentation on each commit.

#### 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]`)

---------

Co-authored-by: Daniel Budziwojski <[email protected]>
  • Loading branch information
kang-makes and dbudziwojskiNR authored Aug 29, 2024
1 parent 6798faa commit e398ef4
Show file tree
Hide file tree
Showing 17 changed files with 491 additions and 10 deletions.
6 changes: 3 additions & 3 deletions library/CHART-TEMPLATE/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: common-library
repository: file://../common-library
version: 1.2.0
digest: sha256:ca0a371fb6ce46b821593db9949d1942f2fdf40b54df1eff377ac094bc3d78fa
generated: "2024-06-19T10:51:12.685283+02:00"
version: 1.3.0
digest: sha256:862a49e42a8198a0070eb5ddae2a2d1e535f9e2e8d75e3ec17d722552a0e7c4e
generated: "2024-08-13T16:29:35.296624+02:00"
4 changes: 2 additions & 2 deletions library/CHART-TEMPLATE/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.2.0
version: 1.3.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand All @@ -25,7 +25,7 @@ appVersion: "1.16.0"

dependencies:
- name: common-library
version: 1.2.0
version: 1.3.0
repository: file://../common-library # We keep this as a file to test things immediately locally/in the pipeline

keywords:
Expand Down
16 changes: 15 additions & 1 deletion library/CHART-TEMPLATE/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# CHART-TEMPLATE

![Version: 1.2.0](https://img.shields.io/badge/Version-1.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.16.0](https://img.shields.io/badge/AppVersion-1.16.0-informational?style=flat-square)
![Version: 1.3.0](https://img.shields.io/badge/Version-1.3.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.16.0](https://img.shields.io/badge/AppVersion-1.16.0-informational?style=flat-square)

A Helm chart for Kubernetes showing how to use/implement the common-library

Expand Down Expand Up @@ -38,23 +38,32 @@ low data modes or any other quirk that it could have.
| affinity | object | `{}` | |
| cluster | string | `"barfoo"` | |
| containerSecurityContext | object | `{}` | |
| customInsightsKeySecretKey | string | `""` | |
| customInsightsKeySecretName | string | `""` | |
| customSecretLicenseKey | string | `""` | |
| customSecretName | string | `""` | |
| customUserKeySecretKey | string | `""` | |
| customUserKeySecretName | string | `""` | |
| deploymentAnnotations | object | `{}` | |
| dnsconfig | object | `{}` | |
| fedRamp.enabled | string | `nil` | |
| fullnameOverride | string | `""` | |
| global.affinity | object | `{}` | |
| global.cluster | string | `""` | |
| global.containerSecurityContext | object | `{}` | |
| global.customInsightsKeySecretKey | string | `""` | |
| global.customInsightsKeySecretName | string | `""` | |
| global.customSecretLicenseKey | string | `""` | |
| global.customSecretName | string | `""` | |
| global.customUserKeySecretKey | string | `""` | |
| global.customUserKeySecretName | string | `""` | |
| global.deploymentAnnotations | object | `{}` | |
| global.dnsconfig | object | `{}` | |
| global.fedRamp.enabled | string | `nil` | |
| global.hostNetwork | string | `nil` | |
| global.image.pullPolicy | list | `[]` | |
| global.image.registry | string | `nil` | |
| global.insightsKey | string | `""` | |
| global.labels | object | `{}` | |
| global.licenseKey | string | `""` | |
| global.lowDataMode | string | `nil` | |
Expand All @@ -66,17 +75,20 @@ low data modes or any other quirk that it could have.
| global.priorityClassName | string | `""` | |
| global.privileged | string | `nil` | |
| global.proxy | string | `nil` | |
| global.region | string | `""` | |
| global.serviceAccount.annotations | string | `nil` | |
| global.serviceAccount.create | string | `nil` | |
| global.serviceAccount.name | string | `nil` | |
| global.tolerations | list | `[]` | |
| global.userKey | string | `""` | |
| global.verboseLog | string | `nil` | |
| hostNetwork | string | `nil` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.registry | string | `nil` | |
| image.repository | string | `"nginx"` | |
| image.tag | string | `""` | |
| imagePullSecrets | list | `[]` | |
| insightsKey | string | `"foobaz"` | |
| labels | object | `{}` | |
| licenseKey | string | `"foobar"` | |
| lowDataMode | string | `nil` | |
Expand All @@ -89,13 +101,15 @@ low data modes or any other quirk that it could have.
| priorityClassName | string | `""` | |
| privileged | string | `nil` | |
| proxy | string | `nil` | |
| region | string | `""` | |
| resources | object | `{}` | |
| service.port | int | `80` | |
| service.type | string | `"ClusterIP"` | |
| serviceAccount.annotations | string | `nil` | |
| serviceAccount.create | string | `nil` | |
| serviceAccount.name | string | `nil` | |
| tolerations | list | `[]` | |
| userKey | string | `"barqux"` | |
| verboseLog | string | `nil` | |

## Maintainers
Expand Down
8 changes: 8 additions & 0 deletions library/CHART-TEMPLATE/templates/example-cm-region.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is a dummy CM to test that region is templated and how to use it
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "newrelic.common.naming.fullname" . }}-examples-region
namespace: {{ .Release.Namespace }}
data:
region: {{ include "newrelic.common.region" . }}
9 changes: 9 additions & 0 deletions library/CHART-TEMPLATE/templates/example-cm-userkey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is a dummy CM to test what API Key helpers of the common library return
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "newrelic.common.naming.fullname" . }}-examples-userkey
namespace: {{ .Release.Namespace }}
data:
userkey-secret-name: {{ include "newrelic.common.userKey.secretName" . }}
userkey-secret-key-name: {{ include "newrelic.common.userKey.secretKeyName" . }}
2 changes: 2 additions & 0 deletions library/CHART-TEMPLATE/templates/example-userkey-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{- /* Common library will take care of creating User Key' secret or not. */ -}}
{{- include "newrelic.common.userKey.secret" . -}}
66 changes: 66 additions & 0 deletions library/CHART-TEMPLATE/tests/cl-region.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
suite: test region helper
templates:
- templates/example-cm-region.yaml
release:
name: my-release
namespace: my-namespace
tests:
- it: Is US by default
asserts:
- equal:
path: data.region
value: US

- it: Is US with everything null
set:
global: null
region: null
asserts:
- equal:
path: data.region
value: US

- it: Detects an EU license key
set:
global: null
region: null
licenseKey: eu01xx77XXXXf1XXXX0bXXXX6aXXXX9eFFFFNRAL
asserts:
- equal:
path: data.region
value: EU

- it: Set region (globally)
set:
global:
region: EU
asserts:
- equal:
path: data.region
value: EU

- it: Set region (locally)
set:
region: EU
asserts:
- equal:
path: data.region
value: EU

- it: Overrides global region with the local one
set:
global:
region: EU
region: local
asserts:
- equal:
path: data.region
value: Local

- it: Honors staging flag
set:
nrStaging: true
asserts:
- equal:
path: data.region
value: Staging
4 changes: 2 additions & 2 deletions library/CHART-TEMPLATE/tests/cl-staging_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tests:
path: data.staging-with-default
value: "false"

- it: Enable low data mode (globally)
- it: Enable staging (globally)
set:
global:
nrStaging: true
Expand All @@ -47,7 +47,7 @@ tests:
path: data.staging-with-default
value: "true"

- it: Enable low data mode (locally)
- it: Enable staging (locally)
set:
nrStaging: true
asserts:
Expand Down
66 changes: 66 additions & 0 deletions library/CHART-TEMPLATE/tests/cl-userkey_helpers_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
suite: test user key helpers
templates:
- templates/example-cm-userkey.yaml
release:
name: my-release
namespace: my-namespace
tests:
- it: creates secret names for local user key
set:
userKey: local
asserts:
- equal:
path: data.userkey-secret-name
value: my-release-CHART-TEMPLATE-userkey
- equal:
path: data.userkey-secret-key-name
value: userKey
- it: creates secret names for global user key
set:
global:
userKey: local
asserts:
- equal:
path: data.userkey-secret-name
value: my-release-CHART-TEMPLATE-userkey
- equal:
path: data.userkey-secret-key-name
value: userKey

- it: returns local custom secret names
set:
customUserKeySecretName: local
customUserKeySecretKey: localkey
asserts:
- equal:
path: data.userkey-secret-name
value: local
- equal:
path: data.userkey-secret-key-name
value: localkey
- it: returns global custom secret names
set:
global:
customUserKeySecretName: global
customUserKeySecretKey: globalkey
asserts:
- equal:
path: data.userkey-secret-name
value: global
- equal:
path: data.userkey-secret-key-name
value: globalkey
- it: local secret names override global secret names
set:
customUserKeySecretName: local
customUserKeySecretKey: localkey
global:
customUserKeySecretName: global
customUserKeySecretKey: globalkey
asserts:
- equal:
path: data.userkey-secret-name
value: local
- equal:
path: data.userkey-secret-key-name
value: localkey
56 changes: 56 additions & 0 deletions library/CHART-TEMPLATE/tests/cl-userkey_secret_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
suite: test user key secret
templates:
- templates/example-userkey-secret.yaml
release:
name: my-release
namespace: my-namespace
tests:
- it: errors if userKey is empty
set:
global: null
userKey: null
asserts:
- failedTemplate:
errorMessage: You must specify a userKey or a customUserKeySecretName containing it
- it: creates secret with local license key
set:
global: null
userKey: local
asserts:
- equal:
path: data.userKey
value: bG9jYWw= # echo -n local | base64
- it: creates secret with global license key
set:
userKey: null
global:
userKey: global
asserts:
- equal:
path: data.userKey
value: Z2xvYmFs # echo -n global | base64
- it: local overrides global
set:
userKey: local
global:
userKey: global
asserts:
- equal:
path: data.userKey
value: bG9jYWw= # echo -n local | base64

- it: does not create a secret if one is provided locally
set:
userKey: I exist but will be ignored
customUserKeySecretName: foo
asserts:
- hasDocuments:
count: 0
- it: does not create a secret if one is provided globally
set:
userKey: I exist but will be ignored
global:
customUserKeySecretName: foo
asserts:
- hasDocuments:
count: 0
15 changes: 14 additions & 1 deletion library/CHART-TEMPLATE/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ global:
licenseKey: ""
customSecretName: ""
customSecretLicenseKey: ""
insightsKey: ""
customInsightsKeySecretName: ""
customInsightsKeySecretKey: ""
region: ""
userKey: ""
customUserKeySecretName: ""
customUserKeySecretKey: ""

image:
pullPolicy: []
Expand Down Expand Up @@ -41,10 +48,16 @@ global:
verboseLog:

licenseKey: foobar # These ease testing as we don't have to set these values in each test
insightsKey: foobaz # These ease testing as we don't have to set these values in each test
cluster: barfoo # These ease testing as we don't have to set these values in each test
customSecretName: ""
customSecretLicenseKey: ""
insightsKey: foobaz # These ease testing as we don't have to set these values in each test
customInsightsKeySecretName: ""
customInsightsKeySecretKey: ""
region: ""
userKey: "barqux" # These ease testing as we don't have to set these values in each test
customUserKeySecretName: ""
customUserKeySecretKey: ""

nameOverride: ""
fullnameOverride: ""
Expand Down
2 changes: 1 addition & 1 deletion library/common-library/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: common-library
description: Provides helpers to provide consistency on all the charts

type: library
version: 1.2.0
version: 1.3.0

keywords:
- newrelic
Expand Down
Loading

0 comments on commit e398ef4

Please sign in to comment.