-
Notifications
You must be signed in to change notification settings - Fork 94
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(support-bundle): add runHostCollectorsInPod in spec #1608
Conversation
pkg/collect/host_collector.go
Outdated
@@ -8,6 +8,8 @@ type HostCollector interface { | |||
Title() string | |||
IsExcluded() (bool, error) | |||
Collect(progressChan chan<- interface{}) (map[string][]byte, error) | |||
RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) | |||
HasRemoted() bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? The naming has me a bit confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i see now. I wonder if this could be renamed to something that would make it clearer what this is for.
cmd/troubleshoot/cli/run.go
Outdated
@@ -183,6 +183,7 @@ func runTroubleshoot(v *viper.Viper, args []string) error { | |||
OutputPath: v.GetString("output"), | |||
Redact: v.GetBool("redact"), | |||
FromCLI: true, | |||
RunHostCollectorsInPod: false || mainBundle.Metadata.RunHostCollectorsInPod, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be set to mainBundle.Metadata.RunHostCollectorsInPod
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, it has been set to mainBundle.Metadata.RunHostCollectorsInPod
cmd/troubleshoot/cli/run.go
Outdated
for _, sb := range kinds.SupportBundlesV1Beta2 { | ||
sb := sb | ||
mainBundle = supportbundle.ConcatSpec(mainBundle, &sb) | ||
enableRunHostCollectorsInPod = enableRunHostCollectorsInPod || sb.Metadata.RunHostCollectorsInPod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this cause a panic if sb.Metadata
was nil
for some reason? Should we check that it isn't nil here and then just set enableRunHostCollecorsInPod := sb.Metadata.RunHostCollectorsInPod
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we should check that. I have added the checking part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. Also a couple questions:
-
Should we refactor things in this PR so that we move the remote collector functions to
internal
and then have both Collectors and RemoteCollectors use those? That way we're in a better place to deprecate RemoteCollectors soon? Or would you rather just do that in a follow up? -
I don't see any of the code for actually making the pod that's used as the runner privileged. Is that going to be in a follow up as well?
dfd63fa
to
55e6760
Compare
The runner privileged has been added into the current code. For moving things to |
pkg/collect/host_collector.go
Outdated
@@ -8,6 +8,8 @@ type HostCollector interface { | |||
Title() string | |||
IsExcluded() (bool, error) | |||
Collect(progressChan chan<- interface{}) (map[string][]byte, error) | |||
RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) // RemoteCollect is used to priviledge pods to collect data from different nodes | |||
HasRemoted() bool // HasRemoted returns true if the collector has a remote collector implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if HasRemoteCollector
would be more descriptive here. Just nitpicking mostly, will leave it up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this function is not easy to read. I have removed it. And use
if err == collect.ErrRemoteCollectorNotImplemented {
to check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to use
if errors.Is(err, collect.ErrRemoteCollectorNotImplemented) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comment, but otherwise lgtm
pkg/collect/host_os_info.go
Outdated
@@ -18,6 +19,9 @@ type HostOSInfo struct { | |||
|
|||
const HostOSInfoPath = `host-collectors/system/hostos_info.json` | |||
|
|||
type NodeInfo struct { | |||
HostOSInfo HostOSInfo `json:"host-collectors/system/hostos_info.json"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is json:"host-collectors/system/hostos_info.json"
used? Its an interesting use of json tags where the tag is a path. I've not seen before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, it has been removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks good. I requested a few changes
In a future PR we want to start using "replicated/troubleshoot:<version>"
instead of "replicated/troubleshoot:latest"
so as to ensure the same version of the image is used as by the binary calling it. There will be an issue with tests passing since the image will most likely not be available.
pkg/collect/host_os_info.go
Outdated
return nil, errors.Wrap(err, "failed to convert kube flags to rest config") | ||
} | ||
|
||
progressCh := make(chan interface{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be using progressChan
channel for sending progress feedback, instead of creating a new one? The new one is also not doing anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, that has been fixed
pkg/collect/host_certificate.go
Outdated
return nil, errors.New("not implemented") | ||
} | ||
|
||
func (c *CollectHostCertificate) HasRemoted() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the only purpose of HasRemote()
is to check that a collector has implemented the RemoteCollect()
function, I'd leave the function out in favour or checking the not implemented
error. It would be good to keep public functions at a minimum
You could do something like
var ErrNotImplemented = errors.New("not implemented")
...
result, err := collector.RemoteCollect(opts.ProgressChan)
if errors.Is(err, collect.ErrNotImplemented) {
result, err = collector.Collect(opts.ProgressChan)
...
}
if err != nil {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, I have changed to
if errors.Is(err, collect.ErrRemoteCollectorNotImplemented) {
pkg/collect/host_os_info.go
Outdated
@@ -20,7 +20,7 @@ type HostOSInfo struct { | |||
const HostOSInfoPath = `host-collectors/system/hostos_info.json` | |||
|
|||
type NodeInfo struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot see where this is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an e2e test for this use case?
e2e test added |
supportbundleName := "host-os-remote-collector" | ||
tarPath := fmt.Sprintf("%s.tar.gz", supportbundleName) | ||
targetFolder := fmt.Sprintf("%s/host-collectors/system/", supportbundleName) | ||
cmd := exec.CommandContext(context.Background(), sbBinary(), "spec/hostOSRemoteCollector.yaml", "--interactive=false", fmt.Sprintf("-o=%s", supportbundleName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relace context.Background()
with ctx
parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Description, Motivation and Context
sc-111270
Test Yaml
Result
support-bundle-2024-09-12T16_02_26.tar.gz
Checklist
Does this PR introduce a breaking change?
This PR is backward compatible.