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

eks-cloud expansion and example test job #206

Merged
merged 3 commits into from
Feb 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
kind: HelmRepository
name: newrelic-charts
namespace: flux-system
version: 5.0.62
version: 5.0.63
interval: 1m0s
targetNamespace: newrelic
values:
Expand Down
2 changes: 1 addition & 1 deletion eks-anywhere-snow/Addons/Partner/newrelic/newrelic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
kind: HelmRepository
name: newrelic-charts
namespace: flux-system
version: 5.0.62
version: 5.0.63
interval: 1m0s
targetNamespace: newrelic
values:
Expand Down
2 changes: 1 addition & 1 deletion eks-anywhere-vsphere/Addons/Partner/newrelic/newrelic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
kind: HelmRepository
name: newrelic-charts
namespace: flux-system
version: 5.0.62
version: 5.0.63
interval: 1m0s
targetNamespace: newrelic
values:
Expand Down
22 changes: 22 additions & 0 deletions eks-cloud/Partner/newrelic/external-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: newrelic-external-secret
namespace: newrelic
spec:
refreshInterval: 1m
secretStoreRef:
name: eksa-secret-store #The secret store name we have just created.
kind: ClusterSecretStore
target:
name: newrelic-secret # Secret name in k8s
data:
- secretKey: newrelic-licensekey # which key it's going to be stored
remoteRef:
key: newrelic-licensekey # Our secret-name goes here
- secretKey: newrelic-account
remoteRef:
key: newrelic-account
- secretKey: newrelic-apikey # which key it's going to be stored
remoteRef:
key: newrelic-apikey
8 changes: 8 additions & 0 deletions eks-cloud/Partner/newrelic/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Namespace
metadata:
name: newrelic
labels:
aws.conformance.vendor: newrelic
aws.conformance.vendor-solution: newrelic-bundle
scrape: "true"
10 changes: 10 additions & 0 deletions eks-cloud/Partner/newrelic/newrelic-source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: newrelic-charts
namespace: flux-system
spec:
interval: 30s
url: https://helm-charts.newrelic.com

48 changes: 48 additions & 0 deletions eks-cloud/Partner/newrelic/newrelic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: newrelic
namespace: newrelic
spec:
chart:
spec:
chart: nri-bundle
reconcileStrategy: ChartVersion
sourceRef:
kind: HelmRepository
name: newrelic-charts
namespace: flux-system
version: 5.0.63
interval: 1m0s
targetNamespace: newrelic
values:
global:
cluster: eks-conformance-testing
lowDataMode: false
newrelic-infrastructure:
controlPlane:
enabled: false
privileged: false
common:
config:
interval: 40s
namespaceSelector:
matchLabels:
scrape: "true"
kube-state-metrics:
image:
tag: v2.6.0
enabled: true
nri-metadata-injection:
enabled: false
valuesFrom:
- kind: Secret
name: newrelic-secret
valuesKey: newrelic-licensekey
targetPath: global.licenseKey
# - kind: ConfigMap
# name: aws-env-metadata
# namespace: kube-system
# valuesKey: clusterName
# targetPath: global.cluster
21 changes: 21 additions & 0 deletions eks-cloud/Testers/Sample/testJob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: sample-cloud-daily-test-cronjob
namespace: default
spec:
schedule: "10 10 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: job
image: busybox
args:
- /bin/sh
- -c
- date; echo sleeping....; sleep 5s; exit 0;
restartPolicy: Never
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
47 changes: 47 additions & 0 deletions eks-cloud/Testers/newrelic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Development Setup for the TestJob

* Set Environment variables, replacing NR license keys, API Keys and Account as appropriate

``
export newrelic_licensekey=YOUR_LICENSE_KEY
export newrelic_account=YOUR_ACCOUNT
export newrelic_apikey=YOUR_APIKEY

``

* Install NR K8 instrumentation

```
function ver { printf "%03d%03d" $(echo "$1" | tr '.' ' '); } && \
K8S_VERSION=$(kubectl version --short 2>&1 | grep 'Server Version' | awk -F' v' '{ print $2; }' | awk -F. '{ print $1"."$2; }') && \
if [[ $(ver $K8S_VERSION) -lt $(ver "1.25") ]]; then KSM_IMAGE_VERSION="v2.6.0"; else KSM_IMAGE_VERSION="v2.7.0"; fi && \
helm repo add newrelic https://helm-charts.newrelic.com && helm repo update && \
kubectl create namespace newrelic ; helm upgrade --install newrelic-bundle newrelic/nri-bundle \
--set global.licenseKey=$newrelic_licensekey \
--set global.cluster=development \
--namespace=newrelic \
--set newrelic-infrastructure.privileged=false \
--set global.lowDataMode=true \
--set kube-state-metrics.image.tag=${KSM_IMAGE_VERSION} \
--set kube-state-metrics.enabled=true \
--set kubeEvents.enabled=true
```

* Create Secret

```
kubectl create secret generic newrelic-secret -n newrelic \
--from-literal=newrelic-licensekey=$newrelic_licensekey \
--from-literal=newrelic-account=$newrelic_account \
--from-literal=newrelic-apikey=$newrelic_apikey
```

* Modify Cron job time

Make changes in spec.schedule in eks-cloud/Testers/newrelic/test-job.yaml reflect the time when you want the cron job to run in your development environment

* Install K8 manifest files

```
kubectl apply -f eks-cloud/Testers/newrelic/
```
31 changes: 31 additions & 0 deletions eks-cloud/Testers/newrelic/test-job-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: newrelic-testjob-service-account
namespace: newrelic
automountServiceAccountToken: true
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: newrelic-testjob-role
namespace: newrelic
rules:
- apiGroups: ["*"]
resources: ["pods","secret"]
verbs: ["get","list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: newrelic-testjob-clusterrole-binding
namespace: newrelic
subjects:
- kind: ServiceAccount
name: newrelic-testjob-service-account
namespace: newrelic
roleRef:
kind: ClusterRole
name: newrelic-testjob-role
apiGroup: rbac.authorization.k8s.io
67 changes: 67 additions & 0 deletions eks-cloud/Testers/newrelic/test-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: newrelic-testjob
namespace: newrelic
spec:
schedule: "10 10 * * *"
# Running the cron at the 10 minute of 10th hour everyday
jobTemplate:
spec:
activeDeadlineSeconds: 900
# timeout after 15 minutes
template:
spec:
# serviceAccount: newrelic-testjob-service-account
# initContainers:
# - name: kubectl
# image: bitnami/kubectl
# command: ['sh', '-c', "while [[$(kubectl get pods -l app.kubernetes.io/name=nri-metadata-injection -o 'jsonpath={..status.conditions[?(@.type==\"Running\")].status}') != \"True\" ]]; do echo \"waiting to init\"; sleep 10; done"]
containers:
- name: test-container
image: golang:latest
command: [ "bash", "-c", "--"]
args:
- >-
sleep 300;
export NR_LICENSE_KEY=$(cat /tmp/newrelic-licensekey/newrelic-licensekey);
export NR_ACCOUNT=$(cat /tmp/newrelic-account/newrelic-account);
export NR_API_KEY=$(cat /tmp/newrelic-apikey/newrelic-apikey);
git clone https://github.com/newrelic/newrelic-integration-e2e-action.git;
cd newrelic-integration-e2e-action;
go run main.go -account_id=$NR_ACCOUNT -agent_enabled=false -api_key=$NR_API_KEY -license_key=$NR_LICENSE_KEY -region="US" -spec_path=/tmp/configmaps/test-spec.yml -scenario_tag=$HOSTNAME --retry_attempts=1 --retry_seconds=5 -verbose_mode=true;
volumeMounts:
- name: newrelic-licensekey
mountPath: "/tmp/newrelic-licensekey"
readOnly: true
- name: newrelic-account
mountPath: "/tmp/newrelic-account"
readOnly: true
- name: newrelic-apikey
mountPath: "/tmp/newrelic-apikey"
readOnly: true
- name: test-spec-volume
mountPath: /tmp/configmaps
restartPolicy: Never
volumes:
- name: newrelic-licensekey
secret:
secretName: newrelic-secret
items:
- key: newrelic-licensekey
path: newrelic-licensekey
- name: newrelic-account
secret:
secretName: newrelic-secret
items:
- key: newrelic-account
path: newrelic-account
- name: newrelic-apikey
secret:
secretName: newrelic-secret
items:
- key: newrelic-apikey
path: newrelic-apikey
- name: test-spec-volume
configMap:
name: test-spec
19 changes: 19 additions & 0 deletions eks-cloud/Testers/newrelic/test-spec-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: test-spec
namespace: newrelic
data:
test-spec.yml: |-
description: |
End-to-end tests for k8s integration
custom_test_key: k8s.podName
scenarios:
- description: |
This scenario will verify that metrics from a k8s Cluster are correctly collected without privileges
tests:
nrqls:
- query: "SELECT latest(k8s.pod.startTime) FROM Metric SINCE 5 MINUTES AGO"
entities: []

Loading