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

Revert "feat: enable remote host collector in KOTS (#4958)" #4978

Merged
merged 1 commit into from
Nov 1, 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
2 changes: 0 additions & 2 deletions pkg/supportbundle/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,9 @@ func executeSupportBundleCollectRoutine(bundle *types.SupportBundle, progressCha
Namespace: "",
ProgressChan: progressChan,
Redact: true,
RunHostCollectorsInPod: true, // always run host collectors in pod from KOTS regardless of the spec value
}

logger.Infof("Executing Collection go routine for support bundle ID: %s", bundle.ID)
logger.Infof("Always run host collectors in pod: %t", opts.RunHostCollectorsInPod)

go func() {
defer close(progressChan)
Expand Down
43 changes: 6 additions & 37 deletions pkg/supportbundle/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,11 @@ func mergeSupportBundleSpecs(builtBundles map[string]*troubleshootv1beta2.Suppor
mergedBundle.Spec.Collectors = append(mergedBundle.Spec.Collectors, builtBundle.Spec.Collectors...)
mergedBundle.Spec.Analyzers = append(mergedBundle.Spec.Analyzers, builtBundle.Spec.Analyzers...)
mergedBundle.Spec.AfterCollection = append(mergedBundle.Spec.AfterCollection, builtBundle.Spec.AfterCollection...)
mergedBundle.Spec.HostCollectors = append(mergedBundle.Spec.HostCollectors, builtBundle.Spec.HostCollectors...)
mergedBundle.Spec.HostAnalyzers = append(mergedBundle.Spec.HostAnalyzers, builtBundle.Spec.HostAnalyzers...)
}

mergedBundle.Spec.Collectors = Dedup(mergedBundle.Spec.Collectors)
mergedBundle.Spec.Analyzers = Dedup(mergedBundle.Spec.Analyzers)
mergedBundle.Spec.AfterCollection = Dedup(mergedBundle.Spec.AfterCollection)
mergedBundle.Spec.HostCollectors = Dedup(mergedBundle.Spec.HostCollectors)
mergedBundle.Spec.HostAnalyzers = Dedup(mergedBundle.Spec.HostAnalyzers)
mergedBundle = deduplicatedCollectors(mergedBundle)
mergedBundle = deduplicatedAnalyzers(mergedBundle)
mergedBundle = deduplicatedAfterCollection(mergedBundle)

return mergedBundle
}
Expand Down Expand Up @@ -465,15 +461,11 @@ func addDiscoveredSpecs(

supportBundle.Spec.Collectors = append(supportBundle.Spec.Collectors, sbObject.Spec.Collectors...)
supportBundle.Spec.Analyzers = append(supportBundle.Spec.Analyzers, sbObject.Spec.Analyzers...)
supportBundle.Spec.HostCollectors = append(supportBundle.Spec.HostCollectors, sbObject.Spec.HostCollectors...)
supportBundle.Spec.HostAnalyzers = append(supportBundle.Spec.HostAnalyzers, sbObject.Spec.HostAnalyzers...)
}

// remove duplicated specs if there are multiple support bundle upstream spec
supportBundle.Spec.Collectors = Dedup(supportBundle.Spec.Collectors)
supportBundle.Spec.Analyzers = Dedup(supportBundle.Spec.Analyzers)
supportBundle.Spec.HostCollectors = Dedup(supportBundle.Spec.HostCollectors)
supportBundle.Spec.HostAnalyzers = Dedup(supportBundle.Spec.HostAnalyzers)
// remove duplicated collectors and analyzers if there are multiple support bundle upstream spec
supportBundle = deduplicatedCollectors(supportBundle)
supportBundle = deduplicatedAnalyzers(supportBundle)

return supportBundle
}
Expand Down Expand Up @@ -1253,26 +1245,3 @@ func removeKurlAnalyzers(analyzers []*troubleshootv1beta2.Analyze) []*troublesho

return analyze
}

func Dedup[T any](objs []T) []T {
seen := make(map[string]bool)
out := []T{}

if len(objs) == 0 {
return objs
}

for _, o := range objs {
data, err := json.Marshal(o)
if err != nil {
out = append(out, o)
continue
}
key := string(data)
if _, ok := seen[key]; !ok {
out = append(out, o)
seen[key] = true
}
}
return out
}
77 changes: 0 additions & 77 deletions pkg/supportbundle/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,80 +769,3 @@ func createNamespaces(t *testing.T, clientset kubernetes.Interface, namespaces .
require.NoError(t, err)
}
}

func Test_mergeSupportBundleSpecs(t *testing.T) {
testBundle := &troubleshootv1beta2.SupportBundle{
Spec: troubleshootv1beta2.SupportBundleSpec{
Collectors: []*troubleshootv1beta2.Collect{
{
ClusterResources: &troubleshootv1beta2.ClusterResources{
CollectorMeta: troubleshootv1beta2.CollectorMeta{CollectorName: "first"},
},
},
{
ClusterResources: &troubleshootv1beta2.ClusterResources{
CollectorMeta: troubleshootv1beta2.CollectorMeta{CollectorName: "first"},
},
},
{
ClusterResources: &troubleshootv1beta2.ClusterResources{},
},
},
Analyzers: []*troubleshootv1beta2.Analyze{
{
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"},
},
},
{
ClusterVersion: &troubleshootv1beta2.ClusterVersion{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"},
},
},
},
AfterCollection: []*troubleshootv1beta2.AfterCollection{},
HostCollectors: []*troubleshootv1beta2.HostCollect{
{
CPU: &troubleshootv1beta2.CPU{},
Memory: &troubleshootv1beta2.Memory{
HostCollectorMeta: troubleshootv1beta2.HostCollectorMeta{CollectorName: "first"},
},
},
{
CPU: &troubleshootv1beta2.CPU{},
Memory: &troubleshootv1beta2.Memory{
HostCollectorMeta: troubleshootv1beta2.HostCollectorMeta{CollectorName: "first"},
},
},
{
CPU: &troubleshootv1beta2.CPU{},
Memory: &troubleshootv1beta2.Memory{
HostCollectorMeta: troubleshootv1beta2.HostCollectorMeta{CollectorName: "second"},
},
},
},
HostAnalyzers: []*troubleshootv1beta2.HostAnalyze{
{
CPU: &troubleshootv1beta2.CPUAnalyze{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"},
},
},
{
CPU: &troubleshootv1beta2.CPUAnalyze{
AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"},
},
},
},
},
}

builtBundles := map[string]*troubleshootv1beta2.SupportBundle{
"first": testBundle,
}
merged := mergeSupportBundleSpecs(builtBundles)

assert.Equal(t, 2, len(merged.Spec.Collectors))
assert.Equal(t, 1, len(merged.Spec.Analyzers))
assert.Equal(t, 2, len(merged.Spec.HostCollectors))
assert.Equal(t, 1, len(merged.Spec.HostAnalyzers))
}
2 changes: 1 addition & 1 deletion pkg/supportbundle/supportbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func CreateSupportBundleDependencies(app *apptypes.App, sequence int64, opts typ
URI: GetSpecURI(app.GetSlug()),
RedactURIs: redactURIs,
Progress: types.SupportBundleProgress{
CollectorCount: len(supportBundle.Spec.Collectors) + len(supportBundle.Spec.HostCollectors),
CollectorCount: len(supportBundle.Spec.Collectors),
},
}

Expand Down
Loading