@@ -6,16 +6,22 @@ import (
6
6
7
7
command "github.com/kosmos.io/netdoctor/pkg/command/share/remote-command"
8
8
"github.com/kosmos.io/netdoctor/pkg/utils"
9
+
10
+ progressbar "github.com/schollz/progressbar/v3"
9
11
"k8s.io/klog/v2"
10
12
)
11
13
12
14
type DoOptions struct {
13
15
Namespace string `json:"namespace,omitempty"`
14
16
Version string `json:"version,omitempty"`
15
17
16
- Protocol string `json:"protocol,omitempty"`
17
- PodWaitTime int `json:"podWaitTime,omitempty"`
18
- Port string `json:"port,omitempty"`
18
+ Protocol string `json:"protocol,omitempty"`
19
+ PodWaitTime int `json:"podWaitTime,omitempty"`
20
+ Port string `json:"port,omitempty"`
21
+ CustomizedTargetPortList []string `json:"customizedTargetPortList,omitempty"`
22
+ CustomizedTargetIPList []string `json:"customizedTargetIPList,omitempty"`
23
+ TargetDNSServer string `json:"targetDNSServer,omitempty"`
24
+ TargetHostToLookup string `json:"targetHostToLookup,omitempty"`
19
25
20
26
MaxNum int `json:"maxNum,omitempty"`
21
27
CmdTimeout int `json:"cmdTimeout,omitempty"`
@@ -94,6 +100,20 @@ func (o *DoOptions) SaveOpts() {
94
100
}
95
101
}
96
102
103
+ func (o * DoOptions ) SkipPod (podInfo * FloatInfo ) bool {
104
+ // is check: no skip
105
+ if len (o .ResumeRecord ) == 0 {
106
+ return false
107
+ }
108
+ // is resume: filt
109
+ for _ , r := range o .ResumeRecord {
110
+ if r .SrcNodeName == podInfo .NodeName {
111
+ return false
112
+ }
113
+ }
114
+ return true
115
+ }
116
+
97
117
func (o * DoOptions ) Skip (podInfo * FloatInfo , targetIP string ) bool {
98
118
// is check: no skip
99
119
if len (o .ResumeRecord ) == 0 {
@@ -112,34 +132,66 @@ func (o *DoOptions) RunRange(iPodInfos []*FloatInfo, jPodInfos []*FloatInfo) []*
112
132
var resultData []* PrintCheckData
113
133
mutex := sync.Mutex {}
114
134
115
- barctl := utils .NewBar (len (jPodInfos ) * len (iPodInfos ))
135
+ var barctl * progressbar.ProgressBar
136
+
137
+ if len (o .CustomizedTargetIPList ) != 0 && len (o .CustomizedTargetPortList ) != 0 ||
138
+ o .Protocol == string (utils .DNS ) {
139
+ barctl = utils .NewBar (len (iPodInfos ))
140
+ } else {
141
+ barctl = utils .NewBar (len (jPodInfos ) * len (iPodInfos ))
142
+ }
116
143
117
144
worker := func (iPodInfo * FloatInfo ) {
118
- for _ , jPodInfo := range jPodInfos {
119
- for _ , ip := range jPodInfo .PodIPs {
120
- var targetIP string
121
- var err error
122
- var cmdResult * command.Result
123
- targetIP = ip
124
- if err != nil {
125
- cmdResult = command .ParseError (err )
126
- } else {
127
- // isSkip
128
- if o .Skip (iPodInfo , targetIP ) {
129
- continue
145
+ var cmdObj command.Command
146
+ if len (o .CustomizedTargetIPList ) != 0 && len (o .CustomizedTargetPortList ) != 0 {
147
+ cmdObj = command .NewCmd (o .Protocol , o .CustomizedTargetIPList , o .CustomizedTargetPortList )
148
+ } else if o .Protocol == string (utils .DNS ) {
149
+ cmdObj = command .NewCmd (o .Protocol , o .TargetHostToLookup , o .TargetDNSServer )
150
+ } else {
151
+ for _ , jPodInfo := range jPodInfos {
152
+ for _ , ip := range jPodInfo .PodIPs {
153
+ var targetIP string
154
+ var err error
155
+ var cmdResult * command.Result
156
+ targetIP = ip
157
+ if err != nil {
158
+ cmdResult = command .ParseError (err )
159
+ } else {
160
+ // isSkip
161
+ if o .Skip (iPodInfo , targetIP ) {
162
+ continue
163
+ }
164
+ // ToDo RunRange && RunNative func support multiple commands, and the code needs to be optimized
165
+ cmdObj := command .NewCmd (o .Protocol , targetIP , o .Port )
166
+ cmdResult = o .SrcFloater .CommandExec (iPodInfo , cmdObj )
130
167
}
131
- // ToDo RunRange && RunNative func support multiple commands, and the code needs to be optimized
132
- cmdObj := command .NewCmd (o .Protocol , targetIP , o .Port )
133
- cmdResult = o .SrcFloater .CommandExec (iPodInfo , cmdObj )
168
+ mutex .Lock ()
169
+ resultData = append (resultData , & PrintCheckData {
170
+ * cmdResult ,
171
+ iPodInfo .NodeName , jPodInfo .NodeName , targetIP ,
172
+ })
173
+ mutex .Unlock ()
174
+ }
175
+ err := barctl .Add (1 )
176
+ if err != nil {
177
+ klog .Error ("processs bar event add error" )
134
178
}
135
- mutex .Lock ()
136
- resultData = append (resultData , & PrintCheckData {
137
- * cmdResult ,
138
- iPodInfo .NodeName , jPodInfo .NodeName , targetIP ,
139
- })
140
- mutex .Unlock ()
141
179
}
142
- barctl .Add (1 )
180
+ return
181
+ }
182
+ if o .SkipPod (iPodInfo ) {
183
+ return
184
+ }
185
+ cmdResult := o .SrcFloater .CommandExec (iPodInfo , cmdObj )
186
+ mutex .Lock ()
187
+ resultData = append (resultData , & PrintCheckData {
188
+ * cmdResult ,
189
+ iPodInfo .NodeName , iPodInfo .NodeName , cmdObj .GetTargetStr (),
190
+ })
191
+ mutex .Unlock ()
192
+ err := barctl .Add (1 )
193
+ if err != nil {
194
+ klog .Error ("processs bar event add error" )
143
195
}
144
196
}
145
197
0 commit comments