Skip to content

Commit

Permalink
Merge branch 'main' into renovate/golang-version
Browse files Browse the repository at this point in the history
  • Loading branch information
dbudziwojskiNR authored Nov 14, 2024
2 parents 038c197 + 3308ad8 commit 024b6bc
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### enhancement
- Update e2e-resources to able to run in demo mode on OpenShift @TmNguyen12 [#1133](https://github.com/newrelic/nri-kubernetes/pull/1133)

## v3.31.0 - 2024-11-11

### 🚀 Enhancements
Expand Down
31 changes: 31 additions & 0 deletions OpenShift.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,34 @@ oc apply -f deploy/local-openshift.yaml
### Tips

* If at any point you need to login to the guest VM, use the following command: `ssh -i ~/.crc/machines/crc/id_rsa core@$(crc ip)`

### Deploying e2e-resources on OpenShift
The namespace we'll be using as an example is `e2e-openshift-running`

1. Create a new service account to be assigned to the hpa and statefulset deployment pods
```
oc create serviceaccount nri-bundle-sa
```

2. Add the `privileged` scc to your new user
```
oc adm policy add-scc-to-user privileged system:serviceaccounts:e2e-openshift-running:nri-bundle-sa
```

3. Enable OpenShift in the `charts/internal/e2e-resources/values.yaml`
```
openShift:
enabled: true
```

4. Enable multiNode if using OpenShift platform
```
persistentVolume:
enabled: true
multiNode: true
```

5. Must run in `demo` mode
```
helm upgrade --install e2e-resources --set demo.enabled=true charts/internal/e2e-resources -n e2e-openshift-running
```
11 changes: 9 additions & 2 deletions charts/internal/e2e-resources/templates/cronjob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ spec:
- -Mbignum=bpi
- -wle
{{- if .Values.demo.enabled }}
- open(FH, '>', './{{ .Values.fileSystemTest.fileName }}') or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(4000)
- open(FH, '>', '/output/{{ .Values.fileSystemTest.fileName }}') or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(4000)
{{- else }}
- open(FH, '>', './{{ .Values.fileSystemTest.fileName }}') or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(1500)
- open(FH, '>', '/output/{{ .Values.fileSystemTest.fileName }}') or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(1500)
{{- end }}
volumeMounts:
- mountPath: /output
name: storage
restartPolicy: OnFailure
volumes:
- name: storage
emptyDir:
sizeLimit: 30Mi
{{- end }}
2 changes: 1 addition & 1 deletion charts/internal/e2e-resources/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
- perl
- -Mbignum=bpi
- -wle
- while (true) { open(FH, '>', './{{ .Values.fileSystemTest.fileName }}') or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(2700) }
- 'while (1) { open(FH, ">", "/output/{{ .Values.fileSystemTest.fileName }}") or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(2700) }'
volumeMounts:
- mountPath: /output
name: storage
Expand Down
2 changes: 1 addition & 1 deletion charts/internal/e2e-resources/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
- perl
- -Mbignum=bpi
- -wle
- while (true) { open(FH, '>', './{{ .Values.fileSystemTest.fileName }}') or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(2700) }
- 'while (1) { open(FH, ">", "/output/{{ .Values.fileSystemTest.fileName }}") or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(2700) }'
volumeMounts:
- mountPath: /output
name: storage
Expand Down
60 changes: 60 additions & 0 deletions charts/internal/e2e-resources/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@ kind: Deployment
metadata:
name: {{ .Release.Name }}-hpa
spec:
{{ if .Values.openShift.enabled }}
replicas: 1
selector:
matchLabels:
app: calculate-pi
template:
metadata:
labels:
app: calculate-pi
spec:
serviceAccountName: nri-bundle-sa
containers:
- name: calculate-pi
image: registry.access.redhat.com/ubi8/python-39:latest
command: ["python", "/app/calculate_pi.py"]
volumeMounts:
- name: script-volume
mountPath: /app
resources:
requests:
cpu: "100m"
limits:
cpu: "500m"
imagePullPolicy: IfNotPresent
volumes:
- name: script-volume
configMap:
name: calculate-pi-config
{{ else }}
selector:
matchLabels:
run: php-apache
Expand All @@ -24,7 +53,37 @@ spec:
cpu: 500m
requests:
cpu: 200m
{{ end }}
---
{{ if .Values.openShift.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: calculate-pi-config
data:
calculate_pi.py: |
from decimal import Decimal, getcontext
def calculate_pi(n):
getcontext().prec = n
pi = Decimal(0)
k = 0
while k < n:
pi += (Decimal(1) / (16 ** k)) * (
Decimal(4) / (8 * k + 1) -
Decimal(2) / (8 * k + 4) -
Decimal(1) / (8 * k + 5) -
Decimal(1) / (8 * k + 6)
)
k += 1
return pi
if __name__ == "__main__":
while True:
calculate_pi(1000)
{{ end }}
---
{{ if not .Values.openShift.enabled }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -36,6 +95,7 @@ spec:
- port: 80
selector:
run: php-apache
{{ end }}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ spec:
capacity:
storage: 5Mi
volumeMode: Filesystem
{{- if .Values.persistentVolume.multiNode }}
local:
path: /mnt/
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: Exists
{{- else }}
hostPath:
path: /data/pv/
path: /mnt/
type: DirectoryOrCreate
{{- end }}
{{- end }}
5 changes: 4 additions & 1 deletion charts/internal/e2e-resources/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ spec:
labels:
app: statefulset
spec:
{{- if .Values.openShift.enabled }}
serviceAccountName: nri-bundle-sa
{{- end }}
containers:
- name: compute-pi-digits
image: perl:5.34.0
Expand All @@ -41,7 +44,7 @@ spec:
- perl
- -Mbignum=bpi
- -wle
- while (true) { open(FH, '>', './{{ .Values.fileSystemTest.fileName }}') or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(2700) }
- 'while (1) { open(FH, ">", "/output/{{ .Values.fileSystemTest.fileName }}") or die "Cannot open file - $!"; print FH bpi(100); close(FH); print bpi(2700) }'
volumeMounts:
- mountPath: /output
name: storage
Expand Down
9 changes: 9 additions & 0 deletions charts/internal/e2e-resources/templates/storageClass.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.persistentVolume.enabled }}
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: {{ .Release.Name }}-pv-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
{{- end }}

8 changes: 8 additions & 0 deletions charts/internal/e2e-resources/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ hpa:
persistentVolume:
# -- Create PVs
enabled: true
# -- Changes PV type to run on multi-node clusters (e.g. GKE, OpenShift on GCP)
multiNode: false
persistentVolumeClaim:
# -- Create PVCs
enabled: true
Expand All @@ -53,3 +55,9 @@ demo:
# -- Variables for filesystem testing
fileSystemTest:
fileName: 'pi.txt'

# Changes resource yaml files for running on OpenShift & MiniShift
# OpenShift currently only runs on in demo mode
openShift:
enabled: false

2 changes: 1 addition & 1 deletion charts/newrelic-infrastructure/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ images:
agent:
registry: ""
repository: newrelic/infrastructure-bundle
tag: 3.2.60
tag: 3.2.61
pullPolicy: IfNotPresent
# -- Image for the New Relic Kubernetes integration.
# @default -- See `values.yaml`
Expand Down

0 comments on commit 024b6bc

Please sign in to comment.