Skip to content

Commit d73d5c6

Browse files
CpuIDbanjoh
andauthored
preflight: fix segfault when collector's are not defined in YAML (#939)
* preflight: fix segfault when collector's are not defined in YAML * fix bug with kind: Preflight specs with uploadResultsTo, wrong variable being used :) ref #894 Co-authored-by: Evans Mungai <[email protected]>
1 parent 8cb922c commit d73d5c6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pkg/preflight/collect.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ func (cr RemoteCollectResult) IsRBACAllowed() bool {
8484
// CollectHost runs the collection phase of host preflight checks
8585
func CollectHost(opts CollectOpts, p *troubleshootv1beta2.HostPreflight) (CollectResult, error) {
8686
collectSpecs := make([]*troubleshootv1beta2.HostCollect, 0, 0)
87-
collectSpecs = append(collectSpecs, p.Spec.Collectors...)
87+
if p != nil && p.Spec.Collectors != nil {
88+
collectSpecs = append(collectSpecs, p.Spec.Collectors...)
89+
}
8890

8991
allCollectedData := make(map[string][]byte)
9092

@@ -128,7 +130,9 @@ func Collect(opts CollectOpts, p *troubleshootv1beta2.Preflight) (CollectResult,
128130
var foundForbidden bool
129131

130132
collectSpecs := make([]*troubleshootv1beta2.Collect, 0, 0)
131-
collectSpecs = append(collectSpecs, p.Spec.Collectors...)
133+
if p != nil && p.Spec.Collectors != nil {
134+
collectSpecs = append(collectSpecs, p.Spec.Collectors...)
135+
}
132136
collectSpecs = collect.EnsureCollectorInList(collectSpecs, troubleshootv1beta2.Collect{ClusterInfo: &troubleshootv1beta2.ClusterInfo{}})
133137
collectSpecs = collect.EnsureCollectorInList(collectSpecs, troubleshootv1beta2.Collect{ClusterResources: &troubleshootv1beta2.ClusterResources{}})
134138
collectSpecs = collect.EnsureClusterResourcesFirst(collectSpecs)
@@ -267,7 +271,9 @@ func Collect(opts CollectOpts, p *troubleshootv1beta2.Preflight) (CollectResult,
267271
// Collect runs the collection phase of preflight checks
268272
func CollectRemote(opts CollectOpts, p *troubleshootv1beta2.HostPreflight) (CollectResult, error) {
269273
collectSpecs := make([]*troubleshootv1beta2.RemoteCollect, 0, 0)
270-
collectSpecs = append(collectSpecs, p.Spec.RemoteCollectors...)
274+
if p != nil && p.Spec.RemoteCollectors != nil {
275+
collectSpecs = append(collectSpecs, p.Spec.RemoteCollectors...)
276+
}
271277

272278
allCollectedData := make(map[string][]byte)
273279

pkg/preflight/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func RunPreflights(interactive bool, output string, format string, args []string
132132
preflightSpec = ConcatPreflightSpec(preflightSpec, spec)
133133
}
134134
} else {
135-
uploadResultSpecs = append(uploadResultSpecs, preflightSpec)
135+
uploadResultSpecs = append(uploadResultSpecs, spec)
136136
}
137137
} else if spec, ok := obj.(*troubleshootv1beta2.HostPreflight); ok {
138138
if i == 0 {

0 commit comments

Comments
 (0)