Skip to content

Commit 72af9bb

Browse files
committed
update
Signed-off-by: Hang Yan <[email protected]>
1 parent a64b1fa commit 72af9bb

File tree

2 files changed

+25
-52
lines changed

2 files changed

+25
-52
lines changed

pkg/apiserver/registry/system/samplingpacket/rest.go

+21-48
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,23 @@ const (
4545
var (
4646
// Declared as variables for testing.
4747
defaultFS = afero.NewOsFs()
48-
defaultExecutor = exec.New()
49-
newAgentDumper = support.NewAgentDumper
5048

5149
clock clockutils.Clock = clockutils.RealClock{}
5250
)
5351

5452
// NewControllerStorage creates a sampling storage for working on antrea controller.
5553
func NewControllerStorage() Storage {
56-
bundle := &supportBundleREST{
54+
bundle := &samplingPacketsREST{
5755
mode: modeController,
58-
cache: &systemv1beta1.SupportBundle{
56+
cache: &systemv1beta1.CapturedPacket{
5957
ObjectMeta: metav1.ObjectMeta{Name: modeController},
60-
Status: systemv1beta1.SupportBundleStatusNone,
58+
Status: systemv1beta1.SamplingPacketStatusNone,
6159
},
6260
}
6361
return Storage{
6462
Mode: modeController,
65-
SupportBundle: bundle,
66-
Download: &downloadREST{supportBundle: bundle},
63+
SamplingPacket: bundle,
64+
Download: &downloadREST{capturedPacket: bundle},
6765
}
6866
}
6967

@@ -78,7 +76,7 @@ func NewAgentStorage() Storage {
7876
return Storage{
7977
Mode: modeAgent,
8078
SupportBundle: bundle,
81-
Download: &downloadREST{supportBundle: bundle},
79+
Download: &downloadREST{capturedPacket: bundle},
8280
}
8381
}
8482

@@ -125,17 +123,13 @@ func (r *samplingPacketsREST) Create(ctx context.Context, obj runtime.Object, _
125123
r.cancelFunc = cancelFunc
126124
go func() {
127125
var err error
128-
var b *systemv1beta1.SupportBundle
129-
if r.mode == modeAgent {
130-
b, err = r.collectAgent(ctx, since)
131-
} else if r.mode == modeController {
132-
b, err = r.collectController(ctx, since)
133-
}
126+
var b *systemv1beta1.CapturedPacket
127+
b, err = r.collectAgent(ctx, since)
134128
func() {
135129
r.statusLocker.Lock()
136130
defer r.statusLocker.Unlock()
137131
if err != nil {
138-
klog.Errorf("Error when collecting supportBundle: %v", err)
132+
klog.Errorf("Error when collecting capturedPacket: %v", err)
139133
r.cache.Status = systemv1beta1.SamplingPacketStatusNone
140134
return
141135
}
@@ -167,7 +161,7 @@ func (r *samplingPacketsREST) Get(_ context.Context, name string, _ *metav1.GetO
167161
r.statusLocker.RLock()
168162
defer r.statusLocker.RUnlock()
169163
if r.cache.Name != name {
170-
return nil, errors.NewNotFound(systemv1beta1.Resource("supportBundle"), name)
164+
return nil, errors.NewNotFound(systemv1beta1.Resource("capturedPacket"), name)
171165
}
172166
return r.cache, nil
173167
}
@@ -176,7 +170,7 @@ func (r *samplingPacketsREST) Get(_ context.Context, name string, _ *metav1.GetO
176170
// collecting. It only allows querying the resource whose name is equal to the mode.
177171
func (r *samplingPacketsREST) Delete(_ context.Context, name string, _ rest.ValidateObjectFunc, _ *metav1.DeleteOptions) (runtime.Object, bool, error) {
178172
if name != r.mode {
179-
return nil, false, errors.NewNotFound(systemv1beta1.Resource("supportBundle"), name)
173+
return nil, false, errors.NewNotFound(systemv1beta1.Resource("capturedPacket"), name)
180174
}
181175
r.statusLocker.Lock()
182176
defer r.statusLocker.Unlock()
@@ -213,7 +207,7 @@ func (r *samplingPacketsREST) collect(ctx context.Context, dumpers ...func(strin
213207
defer outputFile.Close()
214208
hashSum, err := compress.PackDir(defaultFS, basedir, outputFile)
215209
if err != nil {
216-
return nil, fmt.Errorf("error when packaging supportBundle: %w", err)
210+
return nil, fmt.Errorf("error when packaging capturedPacket: %w", err)
217211
}
218212

219213
select {
@@ -242,31 +236,10 @@ func (r *samplingPacketsREST) collect(ctx context.Context, dumpers ...func(strin
242236
}, nil
243237
}
244238

245-
func (r *samplingPacketsREST) collectAgent(ctx context.Context, name string) (*systemv1beta1.SupportBundle, error) {
246-
dumper := newAgentDumper(defaultFS, defaultExecutor, r.ovsCtlClient, r.aq, r.npq, since, r.v4Enabled, r.v6Enabled)
247-
return r.collect(
248-
ctx,
249-
dumper.DumpLog,
250-
dumper.DumpHostNetworkInfo,
251-
dumper.DumpFlows,
252-
dumper.DumpNetworkPolicyResources,
253-
dumper.DumpAgentInfo,
254-
dumper.DumpHeapPprof,
255-
dumper.DumpOVSPorts,
256-
dumper.DumpMemberlist,
257-
)
239+
func (r *samplingPacketsREST) collectAgent(ctx context.Context, name string) (*systemv1beta1.CapturedPacket, error) {
240+
return r.collect(ctx)
258241
}
259242

260-
func (r *samplingPacketsREST) collectController(ctx context.Context, since string) (*systemv1beta1.SupportBundle, error) {
261-
dumper := support.NewControllerDumper(defaultFS, defaultExecutor, since)
262-
return r.collect(
263-
ctx,
264-
dumper.DumpLog,
265-
dumper.DumpNetworkPolicyResources,
266-
dumper.DumpControllerInfo,
267-
dumper.DumpHeapPprof,
268-
)
269-
}
270243

271244
func (r *samplingPacketsREST) clean(ctx context.Context, bundlePath string, duration time.Duration) {
272245
select {
@@ -278,10 +251,10 @@ func (r *samplingPacketsREST) clean(ctx context.Context, bundlePath string, dura
278251
select { // check the context again in case of cancellation when acquiring the lock.
279252
case <-ctx.Done():
280253
default:
281-
if r.cache.Status == systemv1beta1.SupportBundleStatusCollected {
282-
r.cache = &systemv1beta1.SupportBundle{
254+
if r.cache.Status == systemv1beta1.SamplingPacketStatusCollected {
255+
r.cache = &systemv1beta1.CapturedPacket{
283256
ObjectMeta: metav1.ObjectMeta{Name: r.mode},
284-
Status: systemv1beta1.SupportBundleStatusNone,
257+
Status: systemv1beta1.SamplingPacketStatusNone,
285258
}
286259
}
287260
}
@@ -298,18 +271,18 @@ var (
298271

299272
// downloadREST implements the REST for downloading the bundle.
300273
type downloadREST struct {
301-
supportBundle *samplingPacketsREST
274+
capturedPacket *samplingPacketsREST
302275
}
303276

304277
func (d *downloadREST) New() runtime.Object {
305-
return &systemv1beta1.SupportBundle{}
278+
return &systemv1beta1.CapturedPacket{}
306279
}
307280

308281
func (d *downloadREST) Destroy() {
309282
}
310283

311284
func (d *downloadREST) Get(_ context.Context, _ string, _ *metav1.GetOptions) (runtime.Object, error) {
312-
return &bundleStream{d.supportBundle.cache}, nil
285+
return &bundleStream{d.capturedPacket.cache}, nil
313286
}
314287

315288
func (d *downloadREST) ProducesMIMETypes(_ string) []string {
@@ -326,7 +299,7 @@ var (
326299
)
327300

328301
type bundleStream struct {
329-
cache *systemv1beta1.SupportBundle
302+
cache *systemv1beta1.CapturedPacket
330303
}
331304

332305
func (b *bundleStream) GetObjectKind() schema.ObjectKind {

pkg/apiserver/registry/system/samplingpacket/rest_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ func TestControllerStorage(t *testing.T) {
183183
require.True(t, exist)
184184

185185
_, err = storage.SupportBundle.Get(context.TODO(), modeAgent, nil)
186-
assert.Equal(t, errors.NewNotFound(system.Resource("supportBundle"), modeAgent), err)
186+
assert.Equal(t, errors.NewNotFound(system.Resource("capturedPacket"), modeAgent), err)
187187

188188
_, deleted, err := storage.SupportBundle.Delete(context.TODO(), modeAgent, nil, nil)
189-
assert.Equal(t, errors.NewNotFound(system.Resource("supportBundle"), modeAgent), err)
189+
assert.Equal(t, errors.NewNotFound(system.Resource("capturedPacket"), modeAgent), err)
190190
assert.False(t, deleted)
191191

192192
_, deleted, err = storage.SupportBundle.Delete(context.TODO(), modeController, nil, nil)
@@ -340,8 +340,8 @@ func TestAgentStorageFailure(t *testing.T) {
340340
assert.Empty(t, collectedBundle.Size)
341341

342342
_, err = storage.SupportBundle.Get(ctx, modeController, nil)
343-
assert.Equal(t, errors.NewNotFound(system.Resource("supportBundle"), modeController), err)
343+
assert.Equal(t, errors.NewNotFound(system.Resource("capturedPacket"), modeController), err)
344344
_, deleted, err := storage.SupportBundle.Delete(ctx, modeController, nil, nil)
345-
assert.Equal(t, errors.NewNotFound(system.Resource("supportBundle"), modeController), err)
345+
assert.Equal(t, errors.NewNotFound(system.Resource("capturedPacket"), modeController), err)
346346
assert.False(t, deleted)
347347
}

0 commit comments

Comments
 (0)