// kubenetes Service to protobuf struct func ServiceToPbStruct(Service *api.Service) *types.Service { todata := &types.Service{ Name: Service.GetName(), Labels: Service.ObjectMeta.Labels, Selector: Service.Spec.Selector, } Service_port := Service.Spec.Ports // 解析容器信息 port := make([]*types.ServicePort, len(Service_port)) for k, v := range Service_port { port[k] = &types.ServicePort{ Name: v.Name, Protocol: string(v.Protocol), Port: int32(v.Port), TargetPort: v.TargetPort.IntVal, NodePort: int32(v.NodePort), } } todata.Port = port return todata }