Skip to content

Commit

Permalink
bug: stop fetching support bundle uri on airgap (#4945)
Browse files Browse the repository at this point in the history
* bug: stop fetching support bundle uri on airgap

the function `ParseSupportBundleFromDoc()` always attempt to fetch the
support bundle from its uri (if present). there is another function that
allows us to define if we want or not use the uri:

```
ParseSupportBundle()
```

this new function requires a second argument called `followURI` and we
need to set it to false when kots is running in an airgap environment.

* chore: add wrapping to errors

addressing pr comments.
  • Loading branch information
ricardomaraschini authored Oct 15, 2024
1 parent d589e34 commit 73a7dde
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
18 changes: 9 additions & 9 deletions pkg/supportbundle/defaultspec/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package defaultspec
import (
_ "embed"

"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/replicatedhq/troubleshoot/pkg/supportbundle"
)
Expand All @@ -12,14 +13,13 @@ var raw []byte

var spec *troubleshootv1beta2.SupportBundle

func init() {
var err error
spec, err = supportbundle.ParseSupportBundleFromDoc(raw)
if err != nil {
panic(err)
func Get(isAirgap bool) (troubleshootv1beta2.SupportBundle, error) {
if spec == nil {
var err error
spec, err = supportbundle.ParseSupportBundle(raw, !isAirgap)
if err != nil {
return troubleshootv1beta2.SupportBundle{}, errors.Wrap(err, "failed to parse support bundle")
}
}
}

func Get() troubleshootv1beta2.SupportBundle {
return *spec.DeepCopy()
return *spec.DeepCopy(), nil
}
22 changes: 12 additions & 10 deletions pkg/supportbundle/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func CreateRenderedSpec(app *apptypes.App, sequence int64, kotsKinds *kotsutil.K
}

// split the default kotsadm support bundle into multiple support bundles
vendorSpec, err := createVendorSpec(builtBundle)
vendorSpec, err := createVendorSpec(builtBundle, app.IsAirgap)
if err != nil {
return nil, errors.Wrap(err, "failed to create vendor support bundle spec")
}
Expand Down Expand Up @@ -370,8 +370,8 @@ func addAfterCollectionSpec(app *apptypes.App, b *troubleshootv1beta2.SupportBun
}

// createVendorSpec creates a support bundle spec that includes the vendor specific collectors and analyzers
func createVendorSpec(b *troubleshootv1beta2.SupportBundle) (*troubleshootv1beta2.SupportBundle, error) {
supportBundle, err := staticspecs.GetVendorSpec()
func createVendorSpec(b *troubleshootv1beta2.SupportBundle, isAirgap bool) (*troubleshootv1beta2.SupportBundle, error) {
supportBundle, err := staticspecs.GetVendorSpec(isAirgap)
if err != nil {
logger.Errorf("Failed to load vendor support bundle spec: %v", err)
return nil, err
Expand Down Expand Up @@ -457,15 +457,12 @@ func addDiscoveredSpecs(
}

for _, specData := range specs {
sbObject, err := sb.ParseSupportBundleFromDoc([]byte(specData))
sbObject, err := sb.ParseSupportBundle([]byte(specData), !app.IsAirgap)
if err != nil {
logger.Errorf("Failed to unmarshal support bundle spec: %v", err)
continue
}

// ParseSupportBundleFromDoc will check if there is a uri field and if so,
// use the upstream spec, otherwise fall back to
// what's defined in the current spec
supportBundle.Spec.Collectors = append(supportBundle.Spec.Collectors, sbObject.Spec.Collectors...)
supportBundle.Spec.Analyzers = append(supportBundle.Spec.Analyzers, sbObject.Spec.Analyzers...)
}
Expand Down Expand Up @@ -709,12 +706,17 @@ func deduplicatedAfterCollection(supportBundle *troubleshootv1beta2.SupportBundl
return b
}

func getDefaultAnalyzers(isKurl bool) []*troubleshootv1beta2.Analyze {
defaultAnalyzers := defaultspec.Get().Spec.Analyzers
func getDefaultAnalyzers(isKurl, isAirgap bool) ([]*troubleshootv1beta2.Analyze, error) {
defaultSpec, err := defaultspec.Get(isAirgap)
if err != nil {
return nil, errors.Wrap(err, "failed to get default spec")
}

defaultAnalyzers := defaultSpec.Spec.Analyzers
if !isKurl {
defaultAnalyzers = removeKurlAnalyzers(defaultAnalyzers)
}
return defaultAnalyzers
return defaultAnalyzers, nil
}

// addDefaultDynamicTroubleshoot adds dynamic spec to the support bundle.
Expand Down
4 changes: 2 additions & 2 deletions pkg/supportbundle/staticspecs/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var vendorspec []byte
//go:embed defaultspec.yaml
var defaultspec []byte

func GetVendorSpec() (*troubleshootv1beta2.SupportBundle, error) {
return supportbundle.ParseSupportBundleFromDoc(vendorspec)
func GetVendorSpec(isAirgap bool) (*troubleshootv1beta2.SupportBundle, error) {
return supportbundle.ParseSupportBundle(vendorspec, !isAirgap)
}

func GetClusterSpecificSpec(app *apptypes.App) (*troubleshootv1beta2.SupportBundle, error) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/supportbundle/supportbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ func CreateSupportBundleAnalysis(appID string, archivePath string, bundle *types
if err != nil {
logger.Errorf("Failed to check if cluster is kurl: %v", err)
}
analyzer.Spec.Analyzers = append(analyzer.Spec.Analyzers, getDefaultAnalyzers(isKurl)...)

defaultAnalyzers, err := getDefaultAnalyzers(isKurl, foundApp.IsAirgap)
if err != nil {
return errors.Wrap(err, "failed to get default analyzers")
}
analyzer.Spec.Analyzers = append(analyzer.Spec.Analyzers, defaultAnalyzers...)
analyzer.Spec.Analyzers = append(analyzer.Spec.Analyzers, getDefaultDynamicAnalyzers(foundApp)...)

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

0 comments on commit 73a7dde

Please sign in to comment.