@@ -17,7 +17,7 @@ import (
1717 "github.com/mariadb-operator/agent/pkg/logger"
1818 "github.com/mariadb-operator/init/pkg/config"
1919 mariadbv1alpha1 "github.com/mariadb-operator/mariadb-operator/api/v1alpha1"
20- "github.com/mariadb-operator/mariadb-operator/pkg/pod"
20+ mariadbpod "github.com/mariadb-operator/mariadb-operator/pkg/pod"
2121 "github.com/mariadb-operator/mariadb-operator/pkg/statefulset"
2222 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323 "k8s.io/apimachinery/pkg/util/wait"
3636 mariadbNamespace string
3737)
3838
39- type Env struct {
39+ type environment struct {
4040 podName string
4141 mariadbRootPassword string
4242}
@@ -140,14 +140,14 @@ func main() {
140140 os .Exit (1 )
141141 }
142142 logger .Info ("Waiting for previous Pod to be ready" , "pod" , previousPodName )
143- if err := waitForPreviousPod (ctx , mdb , previousPodName , clientset , logger ); err != nil {
143+ if err := waitForPodReady (ctx , mdb , previousPodName , clientset , logger ); err != nil {
144144 logger .Error (err , "Error waiting for previous Pod to be ready" , "pod" , previousPodName )
145145 os .Exit (1 )
146146 }
147147 logger .Info ("Init done" )
148148}
149149
150- func env () (* Env , error ) {
150+ func env () (* environment , error ) {
151151 podName := os .Getenv ("POD_NAME" )
152152 if podName == "" {
153153 return nil , errors .New ("environment variable 'POD_NAME' is required" )
@@ -156,7 +156,7 @@ func env() (*Env, error) {
156156 if mariadbRootPassword == "" {
157157 return nil , errors .New ("environment variable 'MARIADB_ROOT_PASSWORD' is required" )
158158 }
159- return & Env {
159+ return & environment {
160160 podName : podName ,
161161 mariadbRootPassword : mariadbRootPassword ,
162162 }, nil
@@ -190,19 +190,19 @@ func previousPodName(mariadb *mariadbv1alpha1.MariaDB, podIndex int) (string, er
190190 return statefulset .PodName (mariadb .ObjectMeta , previousPodIndex ), nil
191191}
192192
193- func waitForPreviousPod (ctx context.Context , mariadb * mariadbv1alpha1.MariaDB , previousPodName string , clientset * kubernetes.Clientset ,
193+ func waitForPodReady (ctx context.Context , mariadb * mariadbv1alpha1.MariaDB , name string , clientset * kubernetes.Clientset ,
194194 logger logr.Logger ) error {
195195 return wait .PollImmediateUntilWithContext (ctx , 1 * time .Second , func (context.Context ) (bool , error ) {
196- previousPod , err := clientset .CoreV1 ().Pods (mariadb .Namespace ).Get (ctx , previousPodName , metav1.GetOptions {})
196+ pod , err := clientset .CoreV1 ().Pods (mariadb .Namespace ).Get (ctx , name , metav1.GetOptions {})
197197 if err != nil {
198- logger .V (1 ).Info ("Error getting previous Pod" , "err" , err )
198+ logger .V (1 ).Info ("Error getting Pod" , "err" , err )
199199 return false , nil
200200 }
201- if ! pod .PodReady (previousPod ) {
202- logger .V (1 ).Info ("Previous Pod not ready" , "pod" , previousPodName )
201+ if ! mariadbpod .PodReady (pod ) {
202+ logger .V (1 ).Info ("Pod not ready" , "pod" , previousPodName )
203203 return false , nil
204204 }
205- logger .V (1 ).Info ("Previous Pod ready" , "pod" , previousPodName )
205+ logger .V (1 ).Info ("Pod ready" , "pod" , previousPodName )
206206 return true , nil
207207 })
208208}
0 commit comments