66 "io/ioutil"
77 "net/http"
88 "os"
9+ "path"
910 "path/filepath"
1011 "strings"
1112 "time"
@@ -41,13 +42,19 @@ var (
4142)
4243
4344func main () {
45+ checkpoints , err := getCheckpointManifests ()
46+ if err != nil {
47+ glog .Fatalf ("failed to load existing checkpoint manifests: %v" , err )
48+ }
4449 glog .Info ("begin pods checkpointing..." )
45- run (kubeAPIServer , tempAPIServer , api .NamespaceSystem )
50+ run (kubeAPIServer , tempAPIServer , api .NamespaceSystem , checkpoints )
4651}
4752
48- func run (actualPodName , tempPodName , namespace string ) {
53+ func run (actualPodName , tempPodName , namespace string , checkpoints map [ string ] struct {} ) {
4954 client := newAPIClient ()
5055 for {
56+ _ , checkpointed := checkpoints [checkpointManifest (tempPodName )]
57+
5158 var podList v1.PodList
5259 if err := json .Unmarshal (getPodsFromKubeletAPI (), & podList ); err != nil {
5360 glog .Fatal (err )
@@ -62,17 +69,18 @@ func run(actualPodName, tempPodName, namespace string) {
6269 glog .Error (err )
6370 }
6471 case isPodRunning (podList , client , actualPodName , namespace ):
65- glog .Infof ("actual pod %v found, creating temp pod manifest" , actualPodName )
72+ glog .Infof ("actual pod %v found, creating checkpoint pod manifest" , actualPodName )
6673 // The actual is running. Let's snapshot the pod,
6774 // clean it up a bit, and then save it to the ignore path for
6875 // later use.
6976 checkpointPod := createCheckpointPod (podList , actualPodName , namespace )
7077 convertSecretsToVolumeMounts (client , & checkpointPod )
7178 writeManifest (checkpointPod , tempPodName )
72- glog .Infof ("finished creating temp pod %v manifest at %s\n " , tempPodName , checkpointManifest (tempPodName ))
79+ checkpoints [checkpointManifest (tempPodName )] = struct {}{}
80+ glog .Infof ("finished creating checkpoint pod %v manifest at %s\n " , tempPodName , checkpointManifest (tempPodName ))
7381
74- default :
75- glog .Info ("no actual pod running, installing temp pod static manifest" )
82+ case checkpointed :
83+ glog .Info ("no actual pod running, installing checkpoint pod static manifest" )
7684 b , err := ioutil .ReadFile (checkpointManifest (tempPodName ))
7785 if err != nil {
7886 glog .Error (err )
@@ -249,3 +257,20 @@ func activeManifest(name string) string {
249257func checkpointManifest (name string ) string {
250258 return filepath .Join (ignorePath , name + ".json" )
251259}
260+
261+ func getCheckpointManifests () (map [string ]struct {}, error ) {
262+ checkpoints := make (map [string ]struct {})
263+
264+ fs , err := ioutil .ReadDir (ignorePath )
265+ if err != nil {
266+ if os .IsNotExist (err ) {
267+ return checkpoints , nil
268+ }
269+ return nil , err
270+ }
271+ for _ , f := range fs {
272+ glog .Infof ("found checkpoint pod manifests %v" , f .Name ())
273+ checkpoints [path .Join (ignorePath , f .Name ())] = struct {}{}
274+ }
275+ return checkpoints , nil
276+ }
0 commit comments