Skip to content

Commit 01fe1a4

Browse files
Merge pull request #26 from ShubhamTiwary914/prod/provision
Prod/provision
2 parents 8935355 + ee1dd2c commit 01fe1a4

File tree

9 files changed

+122
-21
lines changed

9 files changed

+122
-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: 19 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
@@ -39,6 +38,20 @@ spec:
3938
mountPath: /envs
4039
{{- end }}
4140

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+
4255
containers:
4356
- name: vernemq
4457
image: vernemq/vernemq
@@ -52,7 +65,7 @@ spec:
5265
name: verne-conf
5366

5467
- name: listener
55-
image: sardinesszsz/verne-listener:latest
68+
image: {{ .Values.image }}
5669
envFrom:
5770
- configMapRef:
5871
name: verne-conf
@@ -75,9 +88,6 @@ spec:
7588
- 'grep -q "SUCCESS" $MQTT_CONNECT_SUCCESS_PATH && grep -q "SUCCESS" $PUBSUB_CONNECT_SUCCESS_PATH'
7689
initialDelaySeconds: 10
7790
periodSeconds: 2
78-
79-
{{- if eq .Values.env "dev" }}
8091
volumeMounts:
8192
- name: envs
82-
mountPath: /envs
83-
{{- 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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
replicaCount: 1
2+
env: dev
3+
namespace: verne
4+
image: sardinesszsz/verne-listener:latest
5+
6+
verneConfig:
7+
acceptEula: "yes"
8+
allowAnonymous: "on"
9+
listenerConfig:
10+
hostPath: "/envs/host_ip"
11+
mqttPort: "1883"
12+
mqttSuccessPath: "/tmp/listener.status"
13+
pubsubSuccessPath: "/tmp/pub.status"
14+
mqttTopic: "mqtt-source"
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
}

taskfile.yaml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
version: '3'
22

3+
dotenv: ['.tf.env']
4+
5+
36
env:
47
MONITOR_NAMESPACE: observe
58
GCP_PROJECT: gcplocal-emulator
69
GCP_LOCAL_BASE_URL: http://localhost:8085/v1
710
DEV_PATH: ./k8s/dev
811
PROD_PATH: ./k8s/prod
9-
1012

1113
tasks:
1214
# / ======== \
@@ -53,10 +55,11 @@ tasks:
5355
cmds:
5456
- helm upgrade prometheus prometheus-community/prometheus -n $MONITOR_NAMESPACE -f ./values/prom.yaml
5557

56-
verne-helm-pack-install:
58+
verne-helm-setup-local:
59+
dir: $DEV_PATH/verne
5760
desc: install verne helm package
5861
cmds:
59-
- helm install verne verne/verne -n verne
62+
- helm install verne verne/verne -n verne -f ./dev-values.yaml
6063

6164
verne-get-ip:
6265
desc: get verne broker load balancer IP to access
@@ -169,3 +172,32 @@ tasks:
169172
# / ======== \
170173
# region PROD
171174
# \ ======== /
175+
tf-init:
176+
dir: ./terraform
177+
cmds:
178+
- terraform init
179+
180+
tf-plan:
181+
dir: ./terraform
182+
cmds:
183+
- terraform plan
184+
185+
tf-apply:
186+
dir: ./terraform
187+
cmds:
188+
- terraform apply
189+
190+
tf-apply-debug:
191+
dir: ./terraform
192+
cmds:
193+
- TF_LOG=DEBUG TF_LOG_PATH=./tf-debug.log terraform apply -auto-approve
194+
195+
tf-destroy-single:
196+
dir: ./terraform
197+
cmds:
198+
- terraform destroy -target={{.CLI_ARGS}}
199+
200+
tf-list-res:
201+
dir: ./terraform
202+
cmds:
203+
- terraform state list

terraform/gke.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ resource "google_container_cluster" "default" {
44
enable_autopilot = true
55
network = google_compute_network.logcore-net.id
66
subnetwork = google_compute_subnetwork.logcore-lowa-subnet.id
7+
project = var.project_id
78

89
cluster_autoscaling {
910
auto_provisioning_defaults {

0 commit comments

Comments
 (0)