Skip to content

Commit

Permalink
Merge pull request #3471 from replicatedhq/garcialuis/sc-60507/dont-i…
Browse files Browse the repository at this point in the history
…nject-kurl-specific-collectors

exclude kURL specific collectors from support bundle if not running in kURL
  • Loading branch information
garcialuis committed Dec 8, 2022
2 parents 55af291 + 0132e1b commit a954c40
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 7 deletions.
93 changes: 88 additions & 5 deletions pkg/supportbundle/spec.go
Expand Up @@ -422,22 +422,33 @@ func deduplicatedAnalyzers(supportBundle *troubleshootv1beta2.SupportBundle) *tr

// addDefaultTroubleshoot adds kots.io (github.com/replicatedhq/kots/support-bundle/spec.yaml) spec to the support bundle.
func addDefaultTroubleshoot(supportBundle *troubleshootv1beta2.SupportBundle, imageName string, pullSecret *troubleshootv1beta2.ImagePullSecrets) *troubleshootv1beta2.SupportBundle {
isKurl, err := kurl.IsKurl()
if err != nil {
logger.Errorf("Failed to check if cluster is kurl: %v", err)
}
next := supportBundle.DeepCopy()
next.Spec.Collectors = append(next.Spec.Collectors, getDefaultCollectors(imageName, pullSecret)...)
next.Spec.Analyzers = append(next.Spec.Analyzers, getDefaultAnalyzers()...)
next.Spec.Collectors = append(next.Spec.Collectors, getDefaultCollectors(imageName, pullSecret, isKurl)...)
next.Spec.Analyzers = append(next.Spec.Analyzers, getDefaultAnalyzers(isKurl)...)
return next
}

func getDefaultCollectors(imageName string, pullSecret *troubleshootv1beta2.ImagePullSecrets) []*troubleshootv1beta2.Collect {
func getDefaultCollectors(imageName string, pullSecret *troubleshootv1beta2.ImagePullSecrets, isKurl bool) []*troubleshootv1beta2.Collect {
supportBundle := defaultspec.Get()
if imageName != "" {
supportBundle = *populateImages(&supportBundle, imageName, pullSecret)
}
if !isKurl {
supportBundle = *removeKurlCollectors(&supportBundle)
}
return supportBundle.Spec.Collectors
}

func getDefaultAnalyzers() []*troubleshootv1beta2.Analyze {
return defaultspec.Get().Spec.Analyzers
func getDefaultAnalyzers(isKurl bool) []*troubleshootv1beta2.Analyze {
defaultAnalyzers := defaultspec.Get().Spec.Analyzers
if !isKurl {
defaultAnalyzers = removeKurlAnalyzers(defaultAnalyzers)
}
return defaultAnalyzers
}

// addDefaultDynamicTroubleshoot adds dynamic spec to the support bundle.
Expand Down Expand Up @@ -902,3 +913,75 @@ func populateImages(supportBundle *troubleshootv1beta2.SupportBundle, imageName

return next
}

// removeKurlCollectors removes collectors from the default support bundle spec that are specific to kURL clusters
func removeKurlCollectors(supportBundle *troubleshootv1beta2.SupportBundle) *troubleshootv1beta2.SupportBundle {
next := supportBundle.DeepCopy()

collects := []*troubleshootv1beta2.Collect{}
for _, collect := range next.Spec.Collectors {
if collect.Ceph != nil {
continue
}
if collect.Longhorn != nil {
continue
}
if collect.Collectd != nil {
continue
}
if collect.Exec != nil {
if collect.Exec.Name == "kots/kurl/weave" {
continue
}
}
if collect.Logs != nil {
if collect.Logs.Name == "kots/kurl/weave" {
continue
}
if collect.Logs.Namespace == "kurl" || collect.Logs.Namespace == "rook-ceph" {
continue
}
}
if collect.ConfigMap != nil && collect.ConfigMap.Namespace == "kurl" {
continue
}
if collect.CopyFromHost != nil && collect.CopyFromHost.CollectorName == "kurl-host-preflights" {
continue
}
collects = append(collects, collect)
}
next.Spec.Collectors = collects

return next
}

// removeKurlAnalyzers removes analyzers from the default support bundle spec that are specific to kURL clusters
func removeKurlAnalyzers(analyzers []*troubleshootv1beta2.Analyze) []*troubleshootv1beta2.Analyze {

analyze := []*troubleshootv1beta2.Analyze{}

for _, analyzer := range analyzers {
if analyzer.CephStatus != nil {
continue
}
if analyzer.Longhorn != nil {
continue
}
if analyzer.WeaveReport != nil {
continue
}
if analyzer.TextAnalyze != nil {
checkName := analyzer.TextAnalyze.CheckName

if checkName == "Weave Report" || checkName == "Weave Status" {
continue
}
if checkName == "Flannel: can read net-conf.json" || checkName == "Flannel: has access" {
continue
}
}
analyze = append(analyze, analyzer)
}

return analyze
}
8 changes: 6 additions & 2 deletions pkg/supportbundle/supportbundle.go
Expand Up @@ -15,6 +15,7 @@ import (
apptypes "github.com/replicatedhq/kots/pkg/app/types"
"github.com/replicatedhq/kots/pkg/helm"
"github.com/replicatedhq/kots/pkg/kotsutil"
"github.com/replicatedhq/kots/pkg/kurl"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/redact"
"github.com/replicatedhq/kots/pkg/render/helper"
Expand Down Expand Up @@ -351,8 +352,11 @@ func CreateSupportBundleAnalysis(appID string, archivePath string, bundle *types
},
}
}

analyzer.Spec.Analyzers = append(analyzer.Spec.Analyzers, getDefaultAnalyzers()...)
isKurl, err := kurl.IsKurl()
if err != nil {
logger.Errorf("Failed to check if cluster is kurl: %v", err)
}
analyzer.Spec.Analyzers = append(analyzer.Spec.Analyzers, getDefaultAnalyzers(isKurl)...)
analyzer.Spec.Analyzers = append(analyzer.Spec.Analyzers, getDefaultDynamicAnalyzers(foundApp)...)

s := k8sjson.NewYAMLSerializer(k8sjson.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)
Expand Down

0 comments on commit a954c40

Please sign in to comment.