Support for optional collectors and analyzers

This commit is contained in:
Marc Campbell
2019-12-18 01:38:51 +00:00
parent d0a0d925bb
commit 98f926b46c
8 changed files with 83 additions and 12 deletions

View File

@@ -112,7 +112,9 @@ func runPreflights(v *viper.Viper, arg string) error {
continue
}
analyzeResults = append(analyzeResults, analyzeResult)
if analyzeResult != nil {
analyzeResults = append(analyzeResults, analyzeResult)
}
}
finishedCh <- true
@@ -156,12 +158,14 @@ func runCollectors(v *viper.Viper, preflight troubleshootv1beta1.Preflight) (map
return nil, errors.Wrap(err, "failed to run collector")
}
output, err := parseCollectorOutput(string(result))
if err != nil {
return nil, errors.Wrap(err, "failed to parse collector output")
}
for k, v := range output {
allCollectedData[k] = v
if result != nil {
output, err := parseCollectorOutput(string(result))
if err != nil {
return nil, errors.Wrap(err, "failed to parse collector output")
}
for k, v := range output {
allCollectedData[k] = v
}
}
}

View File

@@ -179,10 +179,12 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
continue
}
err = parseAndSaveCollectorOutput(string(result), bundlePath)
if err != nil {
progressChan <- fmt.Errorf("failed to parse collector spec %q: %v", collector.GetDisplayName(), err)
continue
if result != nil {
err = parseAndSaveCollectorOutput(string(result), bundlePath)
if err != nil {
progressChan <- fmt.Errorf("failed to parse collector spec %q: %v", collector.GetDisplayName(), err)
continue
}
}
}

View File

@@ -20,33 +20,63 @@ type getChildCollectedFileContents func(string) (map[string][]byte, error)
func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileContents, findFiles getChildCollectedFileContents) (*AnalyzeResult, error) {
if analyzer.ClusterVersion != nil {
if analyzer.ClusterVersion.Exclude {
return nil, nil
}
return analyzeClusterVersion(analyzer.ClusterVersion, getFile)
}
if analyzer.StorageClass != nil {
if analyzer.StorageClass.Exclude {
return nil, nil
}
return analyzeStorageClass(analyzer.StorageClass, getFile)
}
if analyzer.CustomResourceDefinition != nil {
if analyzer.CustomResourceDefinition.Exclude {
return nil, nil
}
return analyzeCustomResourceDefinition(analyzer.CustomResourceDefinition, getFile)
}
if analyzer.Ingress != nil {
if analyzer.Ingress.Exclude {
return nil, nil
}
return analyzeIngress(analyzer.Ingress, getFile)
}
if analyzer.Secret != nil {
if analyzer.Secret.Exclude {
return nil, nil
}
return analyzeSecret(analyzer.Secret, getFile)
}
if analyzer.ImagePullSecret != nil {
if analyzer.ImagePullSecret.Exclude {
return nil, nil
}
return analyzeImagePullSecret(analyzer.ImagePullSecret, findFiles)
}
if analyzer.DeploymentStatus != nil {
if analyzer.DeploymentStatus.Exclude {
return nil, nil
}
return analyzeDeploymentStatus(analyzer.DeploymentStatus, getFile)
}
if analyzer.StatefulsetStatus != nil {
if analyzer.StatefulsetStatus.Exclude {
return nil, nil
}
return analyzeStatefulsetStatus(analyzer.StatefulsetStatus, getFile)
}
if analyzer.ContainerRuntime != nil {
if analyzer.ContainerRuntime.Exclude {
return nil, nil
}
return analyzeContainerRuntime(analyzer.ContainerRuntime, getFile)
}
if analyzer.Distribution != nil {
if analyzer.Distribution.Exclude {
return nil, nil
}
return analyzeDistribution(analyzer.Distribution, getFile)
}

View File

@@ -62,7 +62,9 @@ func DownloadAndAnalyze(bundleURL string, analyzersSpec string) ([]*AnalyzeResul
continue
}
analyzeResults = append(analyzeResults, analyzeResult)
if analyzeResult != nil {
analyzeResults = append(analyzeResults, analyzeResult)
}
}
return analyzeResults, nil

View File

@@ -76,6 +76,7 @@ type Distribution struct {
type AnalyzeMeta struct {
CheckName string `json:"checkName,omitempty" yaml:"checkName,omitempty"`
Exclude bool `json:"exclude,omitempty" yaml:"exclude,omitempty"`
}
type Analyze struct {

View File

@@ -2,12 +2,15 @@ package v1beta1
type CollectorMeta struct {
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
Exclude bool `json:"when,omitmempty" yaml:"when,omitempty"`
}
type ClusterInfo struct {
CollectorMeta `json:",inline" yaml:",inline"`
}
type ClusterResources struct {
CollectorMeta `json:",inline" yaml:",inline"`
}
type Secret struct {

View File

@@ -348,6 +348,7 @@ func (in *AnalyzerStatus) DeepCopy() *AnalyzerStatus {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterInfo) DeepCopyInto(out *ClusterInfo) {
*out = *in
out.CollectorMeta = in.CollectorMeta
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterInfo.
@@ -363,6 +364,7 @@ func (in *ClusterInfo) DeepCopy() *ClusterInfo {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClusterResources) DeepCopyInto(out *ClusterResources) {
*out = *in
out.CollectorMeta = in.CollectorMeta
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterResources.

View File

@@ -25,30 +25,57 @@ type Context struct {
func (c *Collector) RunCollectorSync() ([]byte, error) {
if c.Collect.ClusterInfo != nil {
if c.Collect.ClusterInfo.Exclude {
return nil, nil
}
return ClusterInfo(c.GetContext())
}
if c.Collect.ClusterResources != nil {
if c.Collect.ClusterResources.Exclude {
return nil, nil
}
return ClusterResources(c.GetContext())
}
if c.Collect.Secret != nil {
if c.Collect.Secret.Exclude {
return nil, nil
}
return Secret(c.GetContext(), c.Collect.Secret)
}
if c.Collect.Logs != nil {
if c.Collect.Logs.Exclude {
return nil, nil
}
return Logs(c.GetContext(), c.Collect.Logs)
}
if c.Collect.Run != nil {
if c.Collect.Run.Exclude {
return nil, nil
}
return Run(c.GetContext(), c.Collect.Run)
}
if c.Collect.Exec != nil {
if c.Collect.Exec.Exclude {
return nil, nil
}
return Exec(c.GetContext(), c.Collect.Exec)
}
if c.Collect.Data != nil {
if c.Collect.Data.Exclude {
return nil, nil
}
return Data(c.GetContext(), c.Collect.Data)
}
if c.Collect.Copy != nil {
if c.Collect.Copy.Exclude {
return nil, nil
}
return Copy(c.GetContext(), c.Collect.Copy)
}
if c.Collect.HTTP != nil {
if c.Collect.HTTP.Exclude {
return nil, nil
}
return HTTP(c.GetContext(), c.Collect.HTTP)
}