Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add node timeout #109

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cmd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -58,4 +59,19 @@ func init() {
managerCmd.PersistentFlags().StringSliceVar(&sbm.BundleCollectors, "extra-collectors", getEnvStringSlice("SUPPORT_BUNDLE_EXTRA_COLLECTORS"), "Get extra resource for the specific components e.g., harvester")
managerCmd.PersistentFlags().StringVar(&sbm.Description, "description", os.Getenv("SUPPORT_BUNDLE_DESCRIPTION"), "The support bundle description")
managerCmd.PersistentFlags().StringVar(&sbm.IssueURL, "issue-url", os.Getenv("SUPPORT_BUNDLE_ISSUE_URL"), "The support bundle issue url")
managerCmd.PersistentFlags().DurationVar(&sbm.NodeTimeout, "node-timeout", parseDurationString(os.Getenv("SUPPORT_BUNDLE_NODE_TIMEOUT")), "The support bundle node collection time out")
}

// parseDurationString could parse `1s` and `10m` duration string.
func parseDurationString(value string) time.Duration {
if value == "" {
return 0
}

d, err := time.ParseDuration(value)
if err != nil {
return 0
}

return d
}
30 changes: 27 additions & 3 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type SupportBundleManager struct {
RegistrySecret string
IssueURL string
Description string
NodeTimeout time.Duration

ExcludeResources []schema.GroupResource
ExcludeResourceList []string
Expand Down Expand Up @@ -273,8 +274,7 @@ func (m *SupportBundleManager) collectNodeBundles() error {
return err
}

<-m.ch
logrus.Info("All node bundles are received.")
m.waitNodesCompleted()

// Clean up when everything is fine. If something went wrong, keep ds for debugging.
// The ds will be garbage-collected when manager pod is gone.
Expand All @@ -293,6 +293,30 @@ func (m *SupportBundleManager) verifyNodeBundle(file string) error {
return err
}

func (m *SupportBundleManager) printTimeoutNodes() {
for node := range m.expectedNodes {
logrus.Warnf("Collection timed out for node: %s", node)
}
}

func (m *SupportBundleManager) waitNodesCompleted() {
select {
case <-m.ch:
logrus.Info("All node bundles are received.")
case <-m.timeout():
logrus.Info("Some nodes are timeout, not all node bundles are received.")
m.printTimeoutNodes()
}
}

func (m *SupportBundleManager) timeout() <-chan time.Time {
if m.NodeTimeout == 0 {
return time.After(30 * time.Minute) // default time out
}

return time.After(m.NodeTimeout)
}

func (m *SupportBundleManager) completeNode(node string) {
m.nodesLock.Lock()
defer m.nodesLock.Unlock()
Expand All @@ -308,7 +332,7 @@ func (m *SupportBundleManager) completeNode(node string) {
if len(m.expectedNodes) == 0 {
if !m.done {
logrus.Debugf("All nodes are completed")
m.ch <- struct{}{}
close(m.ch)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could just close it because there is no other one to write it.

m.done = true
}
}
Expand Down