4
4
"database/sql"
5
5
"flag"
6
6
"fmt"
7
+ "k8s.io/api/extensions/v1beta1"
7
8
"os"
8
9
9
10
log "github.com/Sirupsen/logrus"
@@ -100,25 +101,43 @@ func main() {
100
101
fmt .Println ("found postgres secret with password " + pgSecret .Password )
101
102
}
102
103
104
+ //get the deployments
105
+ var deployments * v1beta1.DeploymentList
103
106
selector = "primary=false,pg-cluster=" + clusterName
104
- podList , err : = kubeapi .GetPods (kubeClient , selector , namespace )
107
+ deployments , err = kubeapi .GetDeployments (kubeClient , selector , namespace )
105
108
if err != nil {
106
109
fmt .Println (err .Error ())
107
110
os .Exit (2 )
108
111
}
109
-
110
- var selectedReplica v1.Pod
111
- if len (podList .Items ) > 0 {
112
- selectedReplica = podList .Items [0 ]
113
- } else {
114
- fmt .Println ("no replicas found" )
112
+ if len (deployments .Items ) > 1 {
113
+ fmt .Println ("no replica deployments found for " + clusterName )
115
114
os .Exit (2 )
116
115
}
117
116
118
- var value uint64 = 0
117
+ var selectedReplica v1.Pod
118
+ var selectedDeployment v1beta1.Deployment
119
+
119
120
databaseName := "postgres"
120
121
port := "5432"
121
- for _ , pod := range podList .Items {
122
+ var value uint64 = 0
123
+
124
+ for _ , dep := range deployments .Items {
125
+ //get the pods for each deployment
126
+ selector = "primary=false,replica-name=" + dep .Name
127
+ podList , err := kubeapi .GetPods (kubeClient , selector , namespace )
128
+ if err != nil {
129
+ fmt .Println (err .Error ())
130
+ os .Exit (2 )
131
+ }
132
+ if len (podList .Items ) > 0 {
133
+ selectedReplica = podList .Items [0 ]
134
+ } else {
135
+ fmt .Println ("no replicas found" )
136
+ os .Exit (2 )
137
+ }
138
+
139
+ pod := podList .Items [0 ]
140
+
122
141
fmt .Println (pod .Name )
123
142
124
143
target := getSQLTarget (& pod , pgSecret .Username , pgSecret .Password , port , databaseName )
@@ -130,10 +149,11 @@ func main() {
130
149
if replInfo .ReceiveLocation > value {
131
150
value = replInfo .ReceiveLocation
132
151
selectedReplica = pod
152
+ selectedDeployment = dep
133
153
}
134
154
}
135
155
}
136
- fmt .Println ("selected replica pod name is " + selectedReplica .Name )
156
+ fmt .Println ("selected deployment is " + selectedDeployment . Name + " replica pod name is " + selectedReplica .Name )
137
157
}
138
158
139
159
func GetReplicationInfo (target string ) (* ReplicationInfo , error ) {
0 commit comments