Skip to content

Commit ee1dd2c

Browse files
helm & listener update for prod config
- helm charts: prod values for connect to gcp pubsub instead of gcplocal - listener service: mode support to setup config in either local or actual pubsub
1 parent 0b9f8c1 commit ee1dd2c

File tree

7 files changed

+75
-21
lines changed

7 files changed

+75
-21
lines changed

helm/verne/templates/config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ data:
1414
PUBSUB_CONNECT_SUCCESS_PATH: {{ .Values.listenerConfig.pubsubSuccessPath | quote }}
1515
MQTT_TOPIC: {{ .Values.listenerConfig.mqttTopic | quote }}
1616
MQTT_BROKER_ADDRESS: {{ .Values.listenerConfig.brokerAddress | quote }}
17-
PUBSUB_HOST: {{ .Values.listenerConfig.pubsubHost | quote }}
17+
PUBSUB_HOST: {{ .Values.listenerConfig.pubsubHost | quote }}
18+
MODE_PATH: {{ .Values.listenerConfig.modePath | quote }}
19+
PROJECT_ID: {{ .Values.listenerConfig.projectID | quote }}

helm/verne/templates/deployment.yaml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ spec:
1919
app: broker
2020
spec:
2121
serviceAccountName: vernemq
22-
23-
{{- if eq .Values.env "dev" }}
2422
#shared emptyDir vol
2523
volumes:
2624
- name: envs
2725
emptyDir: {}
28-
29-
#allow access to node (access gcp emulator - not for prod!)
26+
27+
#node address(for access gcp emulator - not for prod!)
28+
{{- if eq .Values.env "dev" }}
3029
initContainers:
3130
- name: init-host-ip
3231
image: busybox
@@ -38,6 +37,21 @@ spec:
3837
- name: envs
3938
mountPath: /envs
4039
{{- end }}
40+
41+
{{- if eq .Values.env "prod" }}
42+
#set mode = prod (for prod)
43+
initContainers:
44+
- name: init-mode-setter
45+
image: busybox
46+
command:
47+
- sh
48+
- c
49+
- echo "prod" > {{ .Values.listenerConfig.modePath }}
50+
volumeMounts:
51+
- name: envs
52+
mountPath: /envs
53+
{{-end }}
54+
4155
containers:
4256
- name: vernemq
4357
image: vernemq/vernemq
@@ -51,7 +65,7 @@ spec:
5165
name: verne-conf
5266

5367
- name: listener
54-
image: sardinesszsz/verne-listener:latest
68+
image: {{ .Values.image }}
5569
envFrom:
5670
- configMapRef:
5771
name: verne-conf
@@ -74,9 +88,6 @@ spec:
7488
- 'grep -q "SUCCESS" $MQTT_CONNECT_SUCCESS_PATH && grep -q "SUCCESS" $PUBSUB_CONNECT_SUCCESS_PATH'
7589
initialDelaySeconds: 10
7690
periodSeconds: 2
77-
78-
{{- if eq .Values.env "dev" }}
7991
volumeMounts:
8092
- name: envs
81-
mountPath: /envs
82-
{{- end }}
93+
mountPath: /envs

helm/verne/values.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
replicaCount: 5
1+
replicaCount: 2
22
env: dev
33
namespace: verne
4+
image: sardinesszsz/verne-listener:latest
45

56
verneConfig:
67
acceptEula: "yes"
@@ -11,5 +12,7 @@ listenerConfig:
1112
mqttSuccessPath: "/tmp/listener.status"
1213
pubsubSuccessPath: "/tmp/pub.status"
1314
mqttTopic: "mqtt-source"
14-
brokerAddress: "localhost"
15-
pubsubHost: "gcp-emulators:8085"
15+
brokerAddress: "localhost" #same pod as broker
16+
pubsubHost: "gcp-emulators:8085"
17+
modePath: "/envs/mode"
18+
projectID: "gcplocal-emulator"

k8s/dev/verne/dev-values.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
replicaCount: 5
1+
replicaCount: 1
22
env: dev
33
namespace: verne
4+
image: sardinesszsz/verne-listener:latest
45

56
verneConfig:
67
acceptEula: "yes"
@@ -11,5 +12,7 @@ listenerConfig:
1112
mqttSuccessPath: "/tmp/listener.status"
1213
pubsubSuccessPath: "/tmp/pub.status"
1314
mqttTopic: "mqtt-source"
14-
brokerAddress: "localhost"
15-
pubsubHost: "gcp-emulators:8085"
15+
brokerAddress: "localhost" #same pod as broker
16+
pubsubHost: "gcp-emulators:8085"
17+
modePath: "/envs/mode"
18+
projectID: "gcplocal-emulator"

k8s/prod/verne/prod-values.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
replicaCount: 3
2+
env: prod
3+
namespace: verne
4+
image: sardinesszsz/verne-listener:latest
5+
6+
verneConfig:
7+
acceptEula: "yes"
8+
allowAnonymous: "on"
9+
listenerConfig:
10+
mqttPort: "1883"
11+
mqttSuccessPath: "/tmp/listener.status"
12+
pubsubSuccessPath: "/tmp/pub.status"
13+
mqttTopic: "mqtt-source"
14+
brokerAddress: "localhost" #same pod as broker
15+
modePath: "/envs/mode"
16+
projectID: "quick-sonar-469406-j1"

scripts/run-local.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ else
7676
fi
7777

7878
#verne setup
79+
VERNE_DIR="../k8s/dev/verne"
7980
log_info "Installing Verne chart..."
8081
if helm list -n verne | grep -q "verne"; then
8182
log_skip "Verne chart already installed"
8283
else
83-
helm install verne verne/verne -n verne
84+
helm install verne verne/verne -n verne -f "$VERNE_DIR/dev-values.yaml"
8485
fi
8586

8687
#setup observability stack
87-
OBSERVE_DIR="../k8s/observe"
88+
OBSERVE_DIR="../k8s/dev/observe"
8889
log_info "Setting up observability stack..."
8990

9091
#loki

services/listener/main.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ var (
1717
//readiness probe file path (container healthcheck)
1818
LISTENER_HEALTHFILE_PATH = os.Getenv("MQTT_CONNECT_SUCCESS_PATH")
1919
PUB_HEALTHFILE_PATH = os.Getenv("PUBSUB_CONNECT_SUCCESS_PATH")
20+
MODE_PATH = os.Getenv("MODE_PATH")
2021
)
2122

2223
var (
2324
//target= verne container in same pod (hence TCP at localhost:1883)
2425
Broker string = os.Getenv("MQTT_BROKER_ADDRESS")
2526
Port int = 1883
26-
projectID string = "gcplocal-emulator"
27+
projectID string = os.Getenv("PROJECT_ID")
2728
pubsubTopic string = "source"
2829

2930
MqttTopicPath string = os.Getenv("MQTT_TOPIC")
3031
pubsubPort string = "8085"
3132
pubsubHost string = os.Getenv("PUBSUB_HOST")
33+
mode string = "dev"
3234
)
3335

3436
var (
@@ -60,6 +62,7 @@ func localConfigs() {
6062
//read host_ip (for k3s local) -> node where gcp emulator runs
6163
data, err := os.ReadFile("/envs/host_ip")
6264
if err != nil {
65+
utils.Log(utils.LOG_ERROR, "error loading host_ip from /envs/host_ip")
6366
panic(err)
6467
}
6568
hostIP := string(utils.TrimSpace(data))
@@ -72,8 +75,19 @@ func localConfigs() {
7275
utils.Log(utils.LOG_WARN, "currently running localhost pubsub via gcp-emulator, change in production to real gcp!")
7376
}
7477

78+
func configs() {
79+
modepath, err := os.ReadFile(MODE_PATH)
80+
if err != nil {
81+
utils.Log(utils.LOG_ERROR, utils.Sprintf("error finding what mode to set at %s"))
82+
}
83+
mode = string(utils.TrimSpace(modepath))
84+
if mode == "dev" {
85+
localConfigs()
86+
}
87+
}
88+
7589
func main() {
76-
localConfigs()
90+
configs()
7791

7892
//connect to pubsub (+channel for publishing)
7993
pubctx, pubclient = confPubSub(projectID)
@@ -151,7 +165,11 @@ func confPubSub(projectID string) (context.Context, *pubsub.Client) {
151165
if err != nil {
152166
utils.Log(utils.LOG_ERROR, utils.Sprintf("failed to create pubsub client: %v", err))
153167
}
154-
utils.Log(utils.LOG_DEBUG, utils.Sprintf("connected to pubsub host: %s", os.Getenv("PUBSUB_EMULATOR_HOST")))
168+
if MODE_PATH == "dev" {
169+
utils.Log(utils.LOG_DEBUG, utils.Sprintf("connected to pubsub host: %s", os.Getenv("PUBSUB_EMULATOR_HOST")))
170+
} else {
171+
utils.Log(utils.LOG_DEBUG, "connected to pubsub host")
172+
}
155173
logSuccess(PUB_HEALTHFILE_PATH)
156174
return ctx, client
157175
}

0 commit comments

Comments
 (0)