Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Wang <wshaoquan@vmware.com>
  • Loading branch information
wsquan171 committed Dec 9, 2022
1 parent 3654506 commit 15a2f86
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/apiserver/registry/system/supportbundle/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ func (r *supportBundleREST) Create(ctx context.Context, obj runtime.Object, _ re
defer r.statusLocker.Unlock()
if err != nil {
klog.Errorf("Error when collecting supportBundle: %v", err)
r.cache.Status = systemv1alpha1.SupportBundleStatusNone
r.cache = &systemv1alpha1.SupportBundle{
ObjectMeta: metav1.ObjectMeta{Name: bundleName},
Status: systemv1alpha1.SupportBundleStatusNone,
}
return
}
select {
Expand All @@ -167,9 +170,15 @@ func (r *supportBundleREST) New() runtime.Object {
func (r *supportBundleREST) Get(_ context.Context, name string, _ *metav1.GetOptions) (runtime.Object, error) {
r.statusLocker.RLock()
defer r.statusLocker.RUnlock()
if r.cache.Name != name {
if name != bundleName {
return nil, errors.NewNotFound(systemv1alpha1.Resource("supportBundle"), name)
}
if r.cache == nil {
r.cache = &systemv1alpha1.SupportBundle{
ObjectMeta: metav1.ObjectMeta{Name: bundleName},
Status: systemv1alpha1.SupportBundleStatusNone,
}
}
return r.cache, nil
}

Expand Down Expand Up @@ -213,7 +222,7 @@ func (r *supportBundleREST) collect(ctx context.Context, dumpers ...func(string)
defer outputFile.Close()
hashSum, err := packDir(basedir, outputFile)
if err != nil {
return nil, fmt.Errorf("error when packaing supportBundle: %w", err)
return nil, fmt.Errorf("error when packing supportBundle: %w", err)
}

select {
Expand Down Expand Up @@ -315,7 +324,7 @@ func (r *supportBundleREST) clean(ctx context.Context, bundlePath string, durati
select { // check the context again in case of cancellation when acquiring the lock.
case <-ctx.Done():
default:
if r.cache.Status == systemv1alpha1.SupportBundleStatusCollected {
if r.cache != nil && r.cache.Status == systemv1alpha1.SupportBundleStatusCollected {
r.cache = &systemv1alpha1.SupportBundle{
ObjectMeta: metav1.ObjectMeta{Name: bundleName},
Status: systemv1alpha1.SupportBundleStatusNone,
Expand Down

0 comments on commit 15a2f86

Please sign in to comment.