@@ -31,25 +31,15 @@ const (
3131 kubeAPIServer = "kube-apiserver"
3232)
3333
34+ var podAPIServerMeta = unversioned.TypeMeta {
35+ APIVersion : "v1" ,
36+ Kind : "Pod" ,
37+ }
38+
3439var (
3540 secureAPIAddr = fmt .Sprintf ("https://%s:%s" , os .Getenv ("KUBERNETES_SERVICE_HOST" ), os .Getenv ("KUBERNETES_SERVICE_PORT_HTTPS" ))
3641)
3742
38- var tempAPIServerManifest = v1.Pod {
39- TypeMeta : unversioned.TypeMeta {
40- APIVersion : "v1" ,
41- Kind : "Pod" ,
42- },
43- ObjectMeta : v1.ObjectMeta {
44- Name : "temp-apiserver" ,
45- Namespace : api .NamespaceSystem ,
46- },
47- }
48-
49- var tempPodSpecMap = map [string ]v1.Pod {
50- tempAPIServer : tempAPIServerManifest ,
51- }
52-
5343func main () {
5444 glog .Info ("begin pods checkpointing..." )
5545 run (kubeAPIServer , tempAPIServer , api .NamespaceSystem )
@@ -76,13 +66,9 @@ func run(actualPodName, tempPodName, namespace string) {
7666 // The actual is running. Let's snapshot the pod,
7767 // clean it up a bit, and then save it to the ignore path for
7868 // later use.
79- tempSpec , ok := tempPodSpecMap [tempPodName ]
80- if ! ok {
81- glog .Fatalf ("cannot find pod spec for %v" , tempPodName )
82- }
83- tempSpec .Spec = parseAPIPodSpec (podList , actualPodName , namespace )
84- convertSecretsToVolumeMounts (client , & tempSpec )
85- writeManifest (tempSpec , tempPodName )
69+ checkpointPod := createCheckpointPod (podList , actualPodName , namespace )
70+ convertSecretsToVolumeMounts (client , & checkpointPod )
71+ writeManifest (checkpointPod , tempPodName )
8672 glog .Infof ("finished creating temp pod %v manifest at %s\n " , tempPodName , checkpointManifest (tempPodName ))
8773
8874 default :
@@ -185,17 +171,20 @@ func writeManifest(manifest v1.Pod, name string) {
185171 writeAndAtomicCopy (m , checkpointManifest (name ))
186172}
187173
188- func parseAPIPodSpec (podList v1.PodList , n , ns string ) v1.PodSpec {
189- var apiPod v1.Pod
174+ func createCheckpointPod (podList v1.PodList , n , ns string ) v1.Pod {
175+ var checkpointPod v1.Pod
190176 for _ , p := range podList .Items {
191177 if isPod (p , n , ns ) {
192- apiPod = p
178+ checkpointPod = p
193179 break
194180 }
195181 }
196- cleanVolumes (& apiPod )
197- stripNonessentialInfo (& apiPod )
198- return apiPod .Spec
182+ // the pod we manifest we got from kubelet does not have TypeMeta.
183+ // Add it now.
184+ checkpointPod .TypeMeta = podAPIServerMeta
185+ cleanVolumes (& checkpointPod )
186+ stripNonessentialInfo (& checkpointPod )
187+ return checkpointPod
199188}
200189
201190func newAPIClient () clientset.Interface {
0 commit comments