@@ -387,16 +387,16 @@ func (r *runtime) GetPods(all bool) ([]*kubecontainer.Pod, error) {
387387 return kubepods , nil
388388}
389389
390- func (r * runtime ) buildHyperPodServices (pod * api.Pod ) []* grpctypes.UserService {
390+ func (r * runtime ) buildHyperPodServices (pod * api.Pod ) []grpctypes.UserService {
391391 items , err := r .kubeClient .Core ().Services (pod .Namespace ).List (api.ListOptions {})
392392 if err != nil {
393393 glog .Warningf ("Get services failed: %v" , err )
394394 return nil
395395 }
396396
397- var services []* grpctypes.UserService
397+ var services []grpctypes.UserService
398398 for _ , svc := range items .Items {
399- hyperService := & grpctypes.UserService {
399+ hyperService := grpctypes.UserService {
400400 ServiceIP : svc .Spec .ClusterIP ,
401401 }
402402 endpoints , _ := r .kubeClient .Core ().Endpoints (pod .Namespace ).Get (svc .Name )
@@ -421,40 +421,33 @@ func (r *runtime) buildHyperPodServices(pod *api.Pod) []*grpctypes.UserService {
421421 return services
422422}
423423
424- func (r * runtime ) buildHyperPod (pod * api.Pod , restartCount int , pullSecrets []api.Secret ) ([]byte , * grpctypes. UserPod , error ) {
424+ func (r * runtime ) buildHyperPod (pod * api.Pod , restartCount int , pullSecrets []api.Secret ) ([]byte , error ) {
425425 // check and pull image
426426 for _ , c := range pod .Spec .Containers {
427427 if err , _ := r .imagePuller .PullImage (pod , & c , pullSecrets ); err != nil {
428- return nil , nil , err
428+ return nil , err
429429 }
430430 }
431431
432432 // build hyper volume spec
433433 specMap := make (map [string ]interface {})
434- spec := & grpctypes.UserPod {}
435434
436435 // process rbd volume globally
437436 volumeMap , ok := r .runtimeHelper .ListVolumesForPod (pod .UID )
438437 if ! ok {
439- return nil , nil , fmt .Errorf ("cannot get the volumes for pod %q" , kubecontainer .GetPodFullName (pod ))
438+ return nil , fmt .Errorf ("cannot get the volumes for pod %q" , kubecontainer .GetPodFullName (pod ))
440439 }
441440 volumes := make ([]map [string ]interface {}, 0 , 1 )
442- var gVolumes []* grpctypes.UserVolume
443441 for name , mounter := range volumeMap {
444442 glog .V (4 ).Infof ("Hyper: volume %s, path %s, meta %s" , name , mounter .GetPath (), mounter .GetMetaData ())
445443 v := make (map [string ]interface {})
446444 v [KEY_NAME ] = name
447- var gv grpctypes.UserVolume
448- gv .Name = name
449445
450446 // Process rbd volume
451447 metadata := mounter .GetMetaData ()
452448 if metadata != nil && metadata ["volume_type" ].(string ) == "rbd" {
453449 v [KEY_VOLUME_DRIVE ] = metadata ["volume_type" ]
454450 v ["source" ] = "rbd:" + metadata ["name" ].(string )
455- gv .Driver = metadata ["volume_type" ].(string )
456- gv .Source = "rbd:" + metadata ["name" ].(string )
457-
458451 monitors := make ([]string , 0 , 1 )
459452 for _ , host := range metadata ["hosts" ].([]interface {}) {
460453 for _ , port := range metadata ["ports" ].([]interface {}) {
@@ -466,22 +459,14 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
466459 "keyring" : metadata ["keyring" ],
467460 "monitors" : monitors ,
468461 }
469- gv .Option = & grpctypes.UserVolumeOption {
470- User : metadata ["auth_username" ].(string ),
471- Keyring : metadata ["keyring" ].(string ),
472- Monitors : monitors ,
473- }
474462 } else {
475463 glog .V (4 ).Infof ("Hyper: volume %s %s" , name , mounter .GetPath ())
476464
477465 v [KEY_VOLUME_DRIVE ] = VOLUME_TYPE_VFS
478466 v [KEY_VOLUME_SOURCE ] = mounter .GetPath ()
479- gv .Driver = VOLUME_TYPE_VFS
480- gv .Source = mounter .GetPath ()
481467 }
482468
483469 volumes = append (volumes , v )
484- gVolumes = append (gVolumes , & gv )
485470 }
486471
487472 glog .V (4 ).Infof ("Hyper volumes: %v" , volumes )
@@ -490,27 +475,23 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
490475 services := r .buildHyperPodServices (pod )
491476 if services == nil {
492477 // services can't be null for kubernetes, so fake one if it is null
493- services = []* grpctypes.UserService {
478+ services = []grpctypes.UserService {
494479 {
495480 ServiceIP : "127.0.0.2" ,
496481 ServicePort : 65534 ,
497482 },
498483 }
499484 }
500485 specMap ["services" ] = services
501- spec .Services = services
502486 }
503487
504488 // build hyper containers spec
505489 var containers []map [string ]interface {}
506- var gContainers []* grpctypes.UserContainer
507490 var k8sHostNeeded = true
508491 dnsServers := make (map [string ]string )
509- var gDnsServers []string
510492 terminationMsgLabels := make (map [string ]string )
511493 for _ , container := range pod .Spec .Containers {
512494 c := make (map [string ]interface {})
513- var gc grpctypes.UserContainer
514495 c [KEY_NAME ] = r .buildHyperContainerFullName (
515496 string (pod .UID ),
516497 string (pod .Name ),
@@ -520,77 +501,51 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
520501 container )
521502 c [KEY_IMAGE ] = container .Image
522503 c [KEY_TTY ] = container .TTY
523- gc .Name = r .buildHyperContainerFullName (
524- string (pod .UID ),
525- string (pod .Name ),
526- string (pod .Namespace ),
527- container .Name ,
528- restartCount ,
529- container )
530- gc .Image = container .Image
531- gc .Tty = container .TTY
532504
533505 if container .WorkingDir != "" {
534506 c [KEY_WORKDIR ] = container .WorkingDir
535- gc .Workdir = container .WorkingDir
536507 }
537508
538509 opts , err := r .runtimeHelper .GenerateRunContainerOptions (pod , & container , "" )
539510 if err != nil {
540- return nil , nil , err
511+ return nil , err
541512 }
542513
543514 command , args := kubecontainer .ExpandContainerCommandAndArgs (& container , opts .Envs )
544515 if len (command ) > 0 {
545516 c [KEY_ENTRYPOINT ] = command
546- gc .Entrypoint = command
547517 }
548518 if len (args ) > 0 {
549519 c [KEY_COMMAND ] = args
550- gc .Command = args
551520 }
552521
553522 // dns
554523 for _ , dns := range opts .DNS {
555524 dnsServers [dns ] = dns
556- gDnsServers = append (gDnsServers , dns )
557525 }
558526
559527 // envs
560528 envs := make ([]map [string ]string , 0 , 1 )
561- var gEnvs []* grpctypes.EnvironmentVar
562529 for _ , e := range opts .Envs {
563530 envs = append (envs , map [string ]string {
564531 "env" : e .Name ,
565532 "value" : e .Value ,
566533 })
567- gEnvs = append (gEnvs , & grpctypes.EnvironmentVar {
568- Env : e .Name ,
569- Value : e .Value ,
570- })
571534 }
572535 c [KEY_ENVS ] = envs
573- gc .Envs = gEnvs
574536
575537 // port-mappings
576538 var ports []map [string ]interface {}
577- var gPorts []* grpctypes.UserContainerPort
578539 for _ , mapping := range opts .PortMappings {
579540 p := make (map [string ]interface {})
580- var gp grpctypes.UserContainerPort
581541 p [KEY_CONTAINER_PORT ] = mapping .ContainerPort
582- gp .ContainerPort = int32 (mapping .ContainerPort )
583542 if mapping .HostPort != 0 {
584543 p [KEY_HOST_PORT ] = mapping .HostPort
585- gp .HostPort = int32 (mapping .HostPort )
586544 }
587545 p [KEY_PROTOCOL ] = mapping .Protocol
588- gp .Protocol = string (mapping .Protocol )
589546 ports = append (ports , p )
590- gPorts = append (gPorts , & gp )
591547 }
592548 c [KEY_PORTS ] = ports
593- gc .Ports = gPorts
594549
595550 // NOTE: PodContainerDir is from TerminationMessagePath, TerminationMessagePath is default to /dev/termination-log
596551 if opts .PodContainerDir != "" && container .TerminationMessagePath != "" {
@@ -603,11 +558,11 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
603558 containerLogPath := path .Join (opts .PodContainerDir , string (randomUID ))
604559 fs , err := os .Create (containerLogPath )
605560 if err != nil {
606- return nil , nil , err
561+ return nil , err
607562 }
608563
609564 if err := fs .Close (); err != nil {
610- return nil , nil , err
565+ return nil , err
611566 }
612567 mnt := & kubecontainer.Mount {
613568 // Use a random name for the termination message mount, so that
@@ -627,18 +582,12 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
627582 // volumes
628583 if len (opts .Mounts ) > 0 {
629584 var containerVolumes []map [string ]interface {}
630- var gContainerVolumes []* grpctypes.UserVolumeReference
631585 for _ , volume := range opts .Mounts {
632586 v := make (map [string ]interface {})
633587 v [KEY_MOUNTPATH ] = volume .ContainerPath
634588 v [KEY_VOLUME ] = volume .Name
635589 v [KEY_READONLY ] = volume .ReadOnly
636590 containerVolumes = append (containerVolumes , v )
637- gContainerVolumes = append (gContainerVolumes , & grpctypes.UserVolumeReference {
638- Path : volume .ContainerPath ,
639- Volume : volume .Name ,
640- ReadOnly : volume .ReadOnly ,
641- })
642591
643592 if k8sHostNeeded {
644593 // Setup global hosts volume
@@ -649,11 +598,6 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
649598 KEY_VOLUME_DRIVE : VOLUME_TYPE_VFS ,
650599 KEY_VOLUME_SOURCE : volume .HostPath ,
651600 })
652- gVolumes = append (gVolumes , & grpctypes.UserVolume {
653- Name : volume .Name ,
654- Driver : VOLUME_TYPE_VFS ,
655- Source : volume .HostPath ,
656- })
657601 }
658602
659603 // Setup global termination msg volume
@@ -665,25 +609,16 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
665609 KEY_VOLUME_DRIVE : VOLUME_TYPE_VFS ,
666610 KEY_VOLUME_SOURCE : volume .HostPath ,
667611 })
668- gVolumes = append (gVolumes , & grpctypes.UserVolume {
669- Name : volume .Name ,
670- Driver : VOLUME_TYPE_VFS ,
671- Source : volume .HostPath ,
672- })
673612 }
674613 }
675614 }
676615 c [KEY_VOLUMES ] = containerVolumes
677- gc .Volumes = gContainerVolumes
678616 }
679617
680618 containers = append (containers , c )
681- gContainers = append (gContainers , & gc )
682619 }
683620 specMap [KEY_CONTAINERS ] = containers
684621 specMap [KEY_VOLUMES ] = volumes
685- spec .Containers = gContainers
686- spec .Volumes = gVolumes
687622
688623 // dns
689624 if len (dnsServers ) > 0 {
@@ -693,13 +628,11 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
693628 }
694629 specMap [KEY_DNS ] = dns
695630 }
696- spec .Dns = gDnsServers
697631
698632 // build hyper pod resources spec
699633 var podCPULimit , podMemLimit int64
700634 var labels map [string ]string
701635 podResource := make (map [string ]int64 )
702- gPodResource := & grpctypes.UserResource {}
703636 for _ , container := range pod .Spec .Containers {
704637 resource := container .Resources .Limits
705638 var containerCPULimit , containerMemLimit int64
@@ -728,9 +661,6 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
728661 podResource [KEY_VCPU ] = (podCPULimit + 999 ) / 1000
729662 podResource [KEY_MEMORY ] = ((podMemLimit ) / 1000 / 1024 ) / 1024
730663 specMap [KEY_RESOURCE ] = podResource
731- gPodResource .Vcpu = int32 ((podCPULimit + 999 ) / 1000 )
732- gPodResource .Memory = int32 (((podMemLimit ) / 1000 / 1024 ) / 1024 )
733- spec .Resource = gPodResource
734664 glog .V (5 ).Infof ("Hyper: pod limit vcpu=%v mem=%vMiB" , podResource [KEY_VCPU ], podResource [KEY_MEMORY ])
735665
736666 // Setup labels
@@ -750,11 +680,9 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
750680 }
751681
752682 specMap [KEY_LABELS ] = podLabels
753- spec .Labels = podLabels
754683
755684 // other params required
756685 specMap [KEY_ID ] = kubecontainer .BuildPodFullName (pod .Name , pod .Namespace )
757- spec .Id = kubecontainer .BuildPodFullName (pod .Name , pod .Namespace )
758686
759687 // Cap hostname at 63 chars (specification is 64bytes which is 63 chars and the null terminating char).
760688 const hostnameMaxLen = 63
@@ -763,14 +691,13 @@ func (r *runtime) buildHyperPod(pod *api.Pod, restartCount int, pullSecrets []ap
763691 podHostname = podHostname [:hostnameMaxLen ]
764692 }
765693 specMap [KEY_HOSTNAME ] = podHostname
766- spec .Hostname = podHostname
767694
768695 podData , err := json .Marshal (specMap )
769696 if err != nil {
770- return nil , nil , err
697+ return nil , err
771698 }
772699
773- return podData , spec , nil
700+ return podData , nil
774701}
775702
776703func (r * runtime ) savePodSpec (spec , podFullName string ) error {
@@ -839,7 +766,7 @@ func (r *runtime) RunPod(pod *api.Pod, restartCount int, pullSecrets []api.Secre
839766 podStatus * kubecontainer.PodStatus
840767 )
841768
842- podData , podSpec , err : = r .buildHyperPod (pod , restartCount , pullSecrets )
769+ podData , err = r .buildHyperPod (pod , restartCount , pullSecrets )
843770 if err != nil {
844771 glog .Errorf ("Hyper: buildHyperPod failed, error: %v" , err )
845772 return err
@@ -885,12 +812,18 @@ func (r *runtime) RunPod(pod *api.Pod, restartCount int, pullSecrets []api.Secre
885812 }
886813
887814 // Create and start hyper pod
888- podID , err = r .hyperClient .CreatePod (podSpec )
815+ podSpec , err := r .getPodSpec (podFullName )
816+ if err != nil {
817+ glog .Errorf ("Hyper: create pod %s failed, error: %v" , podFullName , err )
818+ return err
819+ }
820+ result , err := r .hyperClient .CreatePod (podSpec )
889821 if err != nil {
890822 glog .Errorf ("Hyper: create pod %s failed, error: %v" , podData , err )
891823 return err
892824 }
893825
826+ podID = string (result ["ID" ].(string ))
894827 err = r .hyperClient .StartPod (podID )
895828 if err != nil {
896829 glog .Errorf ("Hyper: start pod %s (ID:%s) failed, error: %v" , pod .Name , podID , err )
0 commit comments