Skip to content

Commit f3107e3

Browse files
committed
Load variables from ConfigMap and Secret
(cherry picked from commit 870cc1f907f1a205b7e11972f63b6da67378d787)
1 parent debb021 commit f3107e3

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

openshift-app-sample/src/main.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,33 @@ package main
1212
import (
1313
"fmt"
1414
"log"
15+
"os"
16+
"strconv"
1517

1618
"github.com/ibm-messaging/mq-golang-jms20/mqjms"
1719
)
1820

1921
func main() {
2022
fmt.Println("Beginning world!!!")
2123

24+
fmt.Println("host: ", os.Getenv("HOSTNAME"))
25+
fmt.Println("port: ", os.Getenv("PORT"))
26+
fmt.Println("qm: ", os.Getenv("QMNAME"))
27+
fmt.Println("channel: ", os.Getenv("CHANNELNAME"))
28+
29+
fmt.Println("user: ", os.Getenv("USERNAME"))
30+
fmt.Println("pw: ", os.Getenv("PASSWORD"))
31+
32+
portNum, _ := strconv.Atoi(os.Getenv("PORT"))
33+
34+
// Initialise the attributes of the CF in whatever way you like
2235
cf := mqjms.ConnectionFactoryImpl{
23-
QMName: "QM1",
24-
Hostname: "myhostname.com",
25-
PortNumber: 1414,
26-
ChannelName: "SYSTEM.DEF.SVRCONN",
27-
UserName: "username",
28-
Password: "password",
36+
QMName: os.Getenv("QMNAME"),
37+
Hostname: os.Getenv("HOSTNAME"),
38+
PortNumber: portNum,
39+
ChannelName: os.Getenv("CHANNELNAME"),
40+
UserName: os.Getenv("USERNAME"),
41+
Password: os.Getenv("PASSWORD"),
2942
}
3043

3144
// Creates a connection to the queue manager, using defer to close it automatically

openshift-app-sample/yaml/pod-sample.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ metadata:
55
spec:
66
containers:
77
- name: golang-app
8-
image: uk.icr.io/golang-sample/golang-app:1.2
8+
image: uk.icr.io/golang-sample/golang-app:1.3
9+
envFrom:
10+
- configMapRef:
11+
name: qmgr-details
12+
- secretRef:
13+
name: qmgr-credentials
914
restartPolicy: OnFailure
1015
imagePullSecrets:
1116
- name: all-icr-io

0 commit comments

Comments
 (0)