mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
implement uri: field (#702)
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
troubleshootclientsetscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/docrewrite"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/httputil"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/logger"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/oci"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/specs"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -28,7 +29,7 @@ func GetSupportBundleFromURI(bundleURI string) (*troubleshootv1beta2.SupportBund
|
||||
|
||||
multidocs := strings.Split(string(collectorContent), "\n---\n")
|
||||
|
||||
supportbundle, err := ParseSupportBundleFromDoc([]byte(multidocs[0]))
|
||||
supportbundle, err := ParseSupportBundle([]byte(multidocs[0]), true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse collector")
|
||||
}
|
||||
@@ -36,7 +37,7 @@ func GetSupportBundleFromURI(bundleURI string) (*troubleshootv1beta2.SupportBund
|
||||
return supportbundle, nil
|
||||
}
|
||||
|
||||
func ParseSupportBundleFromDoc(doc []byte) (*troubleshootv1beta2.SupportBundle, error) {
|
||||
func ParseSupportBundle(doc []byte, followURI bool) (*troubleshootv1beta2.SupportBundle, error) {
|
||||
doc, err := docrewrite.ConvertToV1Beta2(doc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to convert to v1beta2")
|
||||
@@ -50,6 +51,9 @@ func ParseSupportBundleFromDoc(doc []byte) (*troubleshootv1beta2.SupportBundle,
|
||||
return nil, errors.Wrap(err, "failed to parse document")
|
||||
}
|
||||
|
||||
// parse doc and detect if it's a SupportBundle type,
|
||||
// if it's a Collector type, convert it to a SupportBundle
|
||||
|
||||
collector, ok := obj.(*troubleshootv1beta2.Collector)
|
||||
if ok {
|
||||
supportBundle := troubleshootv1beta2.SupportBundle{
|
||||
@@ -70,12 +74,36 @@ func ParseSupportBundleFromDoc(doc []byte) (*troubleshootv1beta2.SupportBundle,
|
||||
|
||||
supportBundle, ok := obj.(*troubleshootv1beta2.SupportBundle)
|
||||
if ok {
|
||||
// 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
|
||||
if supportBundle.Spec.Uri != "" && followURI {
|
||||
logger.Printf("using upstream reference: %+v\n", supportBundle.Spec.Uri)
|
||||
upstreamSupportBundleContent, err := LoadSupportBundleSpec(supportBundle.Spec.Uri)
|
||||
if err != nil {
|
||||
logger.Printf("failed to load upstream supportbundle, falling back")
|
||||
return supportBundle, nil
|
||||
}
|
||||
|
||||
multidocs := strings.Split(string(upstreamSupportBundleContent), "\n---\n")
|
||||
|
||||
upstreamSupportBundle, err := ParseSupportBundle([]byte(multidocs[0]), false)
|
||||
if err != nil {
|
||||
logger.Printf("failed to parse upstream supportbundle, falling back")
|
||||
return supportBundle, nil
|
||||
}
|
||||
return upstreamSupportBundle, nil
|
||||
}
|
||||
return supportBundle, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("spec was not parseable as a troubleshoot kind")
|
||||
}
|
||||
|
||||
func ParseSupportBundleFromDoc(doc []byte) (*troubleshootv1beta2.SupportBundle, error) {
|
||||
return ParseSupportBundle(doc, true)
|
||||
}
|
||||
|
||||
func GetRedactorFromURI(redactorURI string) (*troubleshootv1beta2.Redactor, error) {
|
||||
decode := scheme.Codecs.UniversalDeserializer().Decode
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ func CollectSupportBundleFromSpec(spec *troubleshootv1beta2.SupportBundleSpec, a
|
||||
// collectors, analyzers and after collection steps. Input arguments are the URIs of the support bundle and redactor specs.
|
||||
// The support bundle is archived in the OS temp folder (os.TempDir()).
|
||||
func CollectSupportBundleFromURI(specURI string, redactorURIs []string, opts SupportBundleCreateOpts) (*SupportBundleResponse, error) {
|
||||
supportbundle, err := GetSupportBundleFromURI(specURI)
|
||||
supportBundle, err := GetSupportBundleFromURI(specURI)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not bundle from URI")
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func CollectSupportBundleFromURI(specURI string, redactorURIs []string, opts Sup
|
||||
}
|
||||
}
|
||||
|
||||
return CollectSupportBundleFromSpec(&supportbundle.Spec, additionalRedactors, opts)
|
||||
return CollectSupportBundleFromSpec(&supportBundle.Spec, additionalRedactors, opts)
|
||||
}
|
||||
|
||||
// ProcessSupportBundleAfterCollection performs the after collection actions, like Callbacks and sending the archive to a remote server.
|
||||
|
||||
12
pkg/supportbundle/test/bad-upstream-uri-spec.yaml
Normal file
12
pkg/supportbundle/test/bad-upstream-uri-spec.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
apiVersion: troubleshoot.sh/v1beta2
|
||||
kind: SupportBundle
|
||||
metadata:
|
||||
name: default
|
||||
spec:
|
||||
uri: https://raw.githubusercontent.com/adamancini/troubleshoot-specs/main/host/bad-spec.yaml
|
||||
collectors:
|
||||
- clusterInfo: {}
|
||||
- clusterResources: {}
|
||||
analyzers:
|
||||
- cephStatus: {}
|
||||
- longhorn: {}
|
||||
12
pkg/supportbundle/test/bad-uri-spec.yaml
Normal file
12
pkg/supportbundle/test/bad-uri-spec.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
apiVersion: troubleshoot.sh/v1beta2
|
||||
kind: SupportBundle
|
||||
metadata:
|
||||
name: default
|
||||
spec:
|
||||
uri: https://githubusercontent.com/adamancini/troubleshoot-specs/main/host/cluster-down
|
||||
collectors:
|
||||
- clusterInfo: {}
|
||||
- clusterResources: {}
|
||||
analyzers:
|
||||
- cephStatus: {}
|
||||
- longhorn: {}
|
||||
12
pkg/supportbundle/test/uri-spec.yaml
Normal file
12
pkg/supportbundle/test/uri-spec.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
apiVersion: troubleshoot.sh/v1beta2
|
||||
kind: SupportBundle
|
||||
metadata:
|
||||
name: default
|
||||
spec:
|
||||
uri: https://raw.githubusercontent.com/replicatedhq/troubleshoot-specs/main/host/cluster-down.yaml
|
||||
collectors:
|
||||
- clusterInfo: {}
|
||||
- clusterResources: {}
|
||||
analyzers:
|
||||
- cephStatus: {}
|
||||
- longhorn: {}
|
||||
Reference in New Issue
Block a user