@@ -46,13 +46,13 @@ func (i *InitSyncer) InitSync() {
4646 case constants .PodDeviceGroupName :
4747 go func () {
4848 defer wg .Done ()
49- i .initSyncPods ( rest .Id )
49+ i .initSyncPodsOrServices ( constants . PodDeviceGroupName , rest .Id )
5050 log .Infof ("Finish syncing %v" , constants .PodDeviceGroupName )
5151 }()
5252 case constants .ServiceDeviceGroupName :
5353 go func () {
5454 defer wg .Done ()
55- i .initSyncServices ( rest .Id )
55+ i .initSyncPodsOrServices ( constants . ServiceDeviceGroupName , rest .Id )
5656 log .Infof ("Finish syncing %v" , constants .ServiceDeviceGroupName )
5757 }()
5858 default :
@@ -96,10 +96,10 @@ func (i *InitSyncer) intSyncNodes(parentGroupID int32) {
9696 }
9797}
9898
99- func (i * InitSyncer ) initSyncPods ( parentGroupID int32 ) {
100- rest , err := devicegroup .Find (parentGroupID , constants . PodDeviceGroupName , i .DeviceManager .LMClient )
99+ func (i * InitSyncer ) initSyncPodsOrServices ( deviceType string , parentGroupID int32 ) {
100+ rest , err := devicegroup .Find (parentGroupID , deviceType , i .DeviceManager .LMClient )
101101 if err != nil || rest == nil {
102- log .Warnf ("Failed to get the pod group" )
102+ log .Warnf ("Failed to get the %s group" , deviceType )
103103 return
104104 }
105105 if rest .SubGroups == nil {
@@ -108,39 +108,22 @@ func (i *InitSyncer) initSyncPods(parentGroupID int32) {
108108
109109 // loop every namespace
110110 for _ , subGroup := range rest .SubGroups {
111- //get pod info from k8s
112- podsMap , err := pod .GetPodsMap (i .DeviceManager .K8sClient , subGroup .Name )
113- if err != nil || podsMap == nil {
114- log .Warnf ("Failed to get the pods from k8s, namespace: %v, err: %v" , subGroup .Name , err )
115- continue
111+ //get pod/service info from k8s
112+ var deviceMap map [string ]string
113+ if deviceType == constants .PodDeviceGroupName {
114+ deviceMap , err = pod .GetPodsMap (i .DeviceManager .K8sClient , subGroup .Name )
115+ } else if deviceType == constants .ServiceDeviceGroupName {
116+ deviceMap , err = service .GetServicesMap (i .DeviceManager .K8sClient , subGroup .Name )
117+ } else {
118+ return
116119 }
117-
118- // get and check all the devices in the group
119- i .syncDevices (constants .PodDeviceGroupName , podsMap , subGroup )
120- }
121- }
122-
123- func (i * InitSyncer ) initSyncServices (parentGroupID int32 ) {
124- rest , err := devicegroup .Find (parentGroupID , constants .ServiceDeviceGroupName , i .DeviceManager .LMClient )
125- if err != nil || rest == nil {
126- log .Warnf ("Failed to get the pod group" )
127- return
128- }
129- if rest .SubGroups == nil {
130- return
131- }
132-
133- // loop every namesplace
134- for _ , subGroup := range rest .SubGroups {
135- //get service info from k8s
136- servicesMap , err := service .GetServicesMap (i .DeviceManager .K8sClient , subGroup .Name )
137- if err != nil || servicesMap == nil {
138- log .Warnf ("Failed to get the services from k8s, namespace: %v, err: %v" , subGroup .Name , err )
120+ if err != nil || deviceMap == nil {
121+ log .Warnf ("Failed to get the %s from k8s, namespace: %v, err: %v" , deviceType , subGroup .Name , err )
139122 continue
140123 }
141124
142125 // get and check all the devices in the group
143- i .syncDevices (constants . ServiceDeviceGroupName , servicesMap , subGroup )
126+ i .syncDevices (deviceType , deviceMap , subGroup )
144127 }
145128}
146129
0 commit comments