File tree Expand file tree Collapse file tree 3 files changed +19
-53
lines changed
Expand file tree Collapse file tree 3 files changed +19
-53
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ import (
2323 "encoding/json"
2424
2525 log "github.com/Sirupsen/logrus"
26- "io/ioutil"
2726 "text/template"
2827
2928 "github.com/crunchydata/postgres-operator/operator/util"
@@ -43,33 +42,10 @@ var ReplicaDeploymentTemplate1 *template.Template
4342var ServiceTemplate1 * template.Template
4443
4544func init () {
46- var err error
47- var buf []byte
48- var SERVICE_PATH_1 = "/pgconf/postgres-operator/cluster/1/cluster-service.json"
49- var DEPLOYMENT_PATH_1 = "/pgconf/postgres-operator/cluster/1/cluster-deployment.json"
50- var REPLICA_DEPLOYMENT_PATH_1 = "/pgconf/postgres-operator/cluster/1/cluster-replica-deployment.json"
51-
52- buf , err = ioutil .ReadFile (DEPLOYMENT_PATH_1 )
53- if err != nil {
54- log .Error (err .Error ())
55- panic (err .Error ())
56- }
57- DeploymentTemplate1 = template .Must (template .New ("deployment1 template" ).Parse (string (buf )))
58-
59- buf , err = ioutil .ReadFile (REPLICA_DEPLOYMENT_PATH_1 )
60- if err != nil {
61- log .Error (err .Error ())
62- panic (err .Error ())
63- }
64- ReplicaDeploymentTemplate1 = template .Must (template .New ("replica1 deployment template" ).Parse (string (buf )))
65-
66- buf , err = ioutil .ReadFile (SERVICE_PATH_1 )
67- if err != nil {
68- log .Error (err .Error ())
69- panic (err .Error ())
70- }
7145
72- ServiceTemplate1 = template .Must (template .New ("service1 template" ).Parse (string (buf )))
46+ ServiceTemplate1 = util .LoadTemplate ("/pgconf/postgres-operator/cluster/1/cluster-service.json" )
47+ ReplicaDeploymentTemplate1 = util .LoadTemplate ("/pgconf/postgres-operator/cluster/1/cluster-replica-deployment.json" )
48+ DeploymentTemplate1 = util .LoadTemplate ("/pgconf/postgres-operator/cluster/1/cluster-deployment.json" )
7349}
7450
7551func (r ClusterStrategy1 ) AddCluster (clientset * kubernetes.Clientset , client * rest.RESTClient , db * tpr.PgCluster ) error {
Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ import (
1919 "bytes"
2020 "encoding/json"
2121 log "github.com/Sirupsen/logrus"
22- "io/ioutil"
2322 "text/template"
2423
2524 "github.com/crunchydata/postgres-operator/operator/pvc"
@@ -39,33 +38,11 @@ var RestorePodTemplate1 *template.Template
3938var ServiceTemplate1 * template.Template
4039
4140func init () {
42- var err error
43- var buf []byte
44- var SERVICE_PATH = "/pgconf/postgres-operator/database/1/database-service.json"
45- var POD_PATH = "/pgconf/postgres-operator/database/1/database-pod.json"
46- var RESTORE_POD_PATH = "/pgconf/postgres-operator/database/1/restore-database-pod.json"
47-
48- buf , err = ioutil .ReadFile (POD_PATH )
49- if err != nil {
50- log .Error (err .Error ())
51- panic (err .Error ())
52- }
53- PodTemplate1 = template .Must (template .New ("pod1 template" ).Parse (string (buf )))
54-
55- buf , err = ioutil .ReadFile (RESTORE_POD_PATH )
56- if err != nil {
57- log .Error (err .Error ())
58- panic (err .Error ())
59- }
60- RestorePodTemplate1 = template .Must (template .New ("restore1 pod template" ).Parse (string (buf )))
6141
62- buf , err = ioutil .ReadFile (SERVICE_PATH )
63- if err != nil {
64- log .Error (err .Error ())
65- panic (err .Error ())
66- }
42+ ServiceTemplate1 = util .LoadTemplate ("/pgconf/postgres-operator/database/1/database-service.json" )
43+ PodTemplate1 = util .LoadTemplate ("/pgconf/postgres-operator/database/1/database-pod.json" )
44+ RestorePodTemplate1 = util .LoadTemplate ("/pgconf/postgres-operator/database/1/restore-database-pod.json" )
6745
68- ServiceTemplate1 = template .Must (template .New ("service1 template" ).Parse (string (buf )))
6946}
7047
7148// database consists of a Service and a Pod
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ package util
1717
1818import (
1919 "bytes"
20+ log "github.com/Sirupsen/logrus"
21+ "io/ioutil"
22+ "text/template"
2023)
2124
2225func CreateSecContext (FS_GROUP string , SUPP string ) string {
@@ -53,3 +56,13 @@ func CreateSecContext(FS_GROUP string, SUPP string) string {
5356
5457 return sc .String ()
5558}
59+
60+ func LoadTemplate (path string ) * template.Template {
61+ buf , err := ioutil .ReadFile (path )
62+ if err != nil {
63+ log .Error (err .Error ())
64+ panic (err .Error ())
65+ }
66+ return template .Must (template .New (path ).Parse (string (buf )))
67+
68+ }
You can’t perform that action at this time.
0 commit comments