Skip to content

Commit 60e6fba

Browse files
feat(cf-common): add classic calculateRabbitMqUri helper (#3)
* feat(cf-common): add classic calculateRabbitMqUri helper
1 parent 9669a12 commit 60e6fba

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
2+
suite: classic connection Uri
3+
templates:
4+
- templates/deployment.yaml
5+
tests:
6+
- it: Test External RabbitMQ connection Uri
7+
values:
8+
- values.yaml
9+
set:
10+
global:
11+
rabbitmqUsername: username
12+
rabbitmqPassword: password
13+
rabbitmqProtocol: amqps
14+
rabbitmqHostname: hostname.domain:5671
15+
rabbitmq:
16+
enabled: false
17+
container:
18+
env:
19+
RABBIT_URL: '{{ include "cf-common.classic.calculateRabbitMqUri" . }}'
20+
asserts:
21+
- contains:
22+
path: spec.template.spec.containers[0].env
23+
content:
24+
name: RABBIT_URL
25+
value: "amqps://username:password@hostname.domain:5671"
26+
27+
- it: Test Internal RabbitMQ connection Uri
28+
release:
29+
name: cf
30+
values:
31+
- values.yaml
32+
set:
33+
global:
34+
rabbitmqService: rabbitmq
35+
rabbitmq:
36+
enabled: true
37+
auth:
38+
username: user
39+
password: pass
40+
container:
41+
env:
42+
RABBIT_URL: '{{ include "cf-common.classic.calculateRabbitMqUri" . }}'
43+
asserts:
44+
- contains:
45+
path: spec.template.spec.containers[0].env
46+
content:
47+
name: RABBIT_URL
48+
value: "amqp://user:pass@cf-rabbitmq"

charts/cf-common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: v0.0.0
33
description: Codefresh library chart
44
name: cf-common
5-
version: 0.0.2
5+
version: 0.0.3
66
type: library
77
keywords:
88
- codefresh

charts/cf-common/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Codefresh library chart
44

5-
![Version: 0.0.2](https://img.shields.io/badge/Version-0.0.2-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
5+
![Version: 0.0.3](https://img.shields.io/badge/Version-0.0.3-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![AppVersion: v0.0.0](https://img.shields.io/badge/AppVersion-v0.0.0-informational?style=flat-square)
66

77
## Installing the Chart
88

@@ -18,7 +18,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
1818
# Chart.yaml
1919
dependencies:
2020
- name: cf-common
21-
version: 0.0.2
21+
version: 0.0.3
2222
repository: https://chartmuseum.codefresh.io/cf-common
2323
```
2424
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{/*
2+
Calculate RabbitMQ URI
3+
Usage
4+
{{ include "cf-common.classic.calculateRabbitMqUri" . }}
5+
*/}}
6+
7+
{{- define "cf-common.classic.calculateRabbitMqUri" }}
8+
9+
{{- $rabbitmqProtocol := $.Values.global.rabbitmqProtocol | default "amqp" -}}
10+
{{- $rabbitmqUsername := .Values.global.rabbitmqUsername -}}
11+
{{- $rabbitmqPassword := .Values.global.rabbitmqPassword -}}
12+
13+
{{- /*
14+
If built-in bitnami/rabbitmq chart enabled get username/password there
15+
*/}}
16+
{{- if $.Values.rabbitmq }}
17+
{{- if $.Values.rabbitmq.enabled }}
18+
{{- $rabbitmqUsername = .Values.rabbitmq.auth.username -}}
19+
{{- $rabbitmqPassword = .Values.rabbitmq.auth.password -}}
20+
{{- end }}
21+
{{- end }}
22+
23+
{{- /*
24+
coalesce here for backward compatibility
25+
*/}}
26+
{{- $rabbitmqHostname := .Values.global.rabbitmqHostname | default (printf "%s-%s" .Release.Name (coalesce .Values.global.rabbitService .Values.global.rabbitmqService ) ) -}}
27+
28+
{{- printf "%s://%s:%s@%s" $rabbitmqProtocol $rabbitmqUsername $rabbitmqPassword $rabbitmqHostname -}}
29+
30+
{{- end }}

0 commit comments

Comments
 (0)