diff --git a/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go b/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go index e68ae1af..21f114fb 100644 --- a/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go +++ b/pkg/apis/troubleshoot/v1beta2/analyzer_shared.go @@ -206,3 +206,79 @@ type Analyze struct { WeaveReport *WeaveReportAnalyze `json:"weaveReport,omitempty" yaml:"weaveReport,omitempty"` Sysctl *SysctlAnalyze `json:"sysctl,omitempty" yaml:"sysctl,omitempty"` } + +func (a *Analyze) GetExclude() *multitype.BoolOrString { + if a.ClusterVersion != nil { + return a.ClusterVersion.Exclude + } + if a.StorageClass != nil { + return a.StorageClass.Exclude + } + if a.CustomResourceDefinition != nil { + return a.CustomResourceDefinition.Exclude + } + if a.Ingress != nil { + return a.Ingress.Exclude + } + if a.Secret != nil { + return a.Secret.Exclude + } + if a.ConfigMap != nil { + return a.ConfigMap.Exclude + } + if a.ImagePullSecret != nil { + return a.ImagePullSecret.Exclude + } + if a.DeploymentStatus != nil { + return a.DeploymentStatus.Exclude + } + if a.StatefulsetStatus != nil { + return a.StatefulsetStatus.Exclude + } + if a.JobStatus != nil { + return a.JobStatus.Exclude + } + if a.ReplicaSetStatus != nil { + return a.ReplicaSetStatus.Exclude + } + if a.ClusterPodStatuses != nil { + return a.ClusterPodStatuses.Exclude + } + if a.ContainerRuntime != nil { + return a.ContainerRuntime.Exclude + } + if a.Distribution != nil { + return a.Distribution.Exclude + } + if a.NodeResources != nil { + return a.NodeResources.Exclude + } + if a.TextAnalyze != nil { + return a.TextAnalyze.Exclude + } + if a.Postgres != nil { + return a.Postgres.Exclude + } + if a.Mysql != nil { + return a.Mysql.Exclude + } + if a.Redis != nil { + return a.Redis.Exclude + } + if a.CephStatus != nil { + return a.CephStatus.Exclude + } + if a.Longhorn != nil { + return a.Longhorn.Exclude + } + if a.RegistryImages != nil { + return a.RegistryImages.Exclude + } + if a.WeaveReport != nil { + return a.WeaveReport.Exclude + } + if a.Sysctl != nil { + return a.Sysctl.Exclude + } + return nil +} diff --git a/pkg/preflight/util.go b/pkg/preflight/util.go index 398b7bae..5df140d6 100644 --- a/pkg/preflight/util.go +++ b/pkg/preflight/util.go @@ -64,6 +64,9 @@ func hasStrictAnalyzer(analyzerMap map[string]interface{}) (bool, error) { if err != nil { return false, errors.Wrap(err, "error while un-marshalling marshalledAnalyzers") } + if analyzeMeta.Exclude.BoolOrDefaultFalse() { + continue + } if analyzeMeta.Strict.BoolOrDefaultFalse() { return true, nil } diff --git a/pkg/preflight/util_test.go b/pkg/preflight/util_test.go index 9805fa66..5569bb88 100644 --- a/pkg/preflight/util_test.go +++ b/pkg/preflight/util_test.go @@ -46,6 +46,16 @@ var ( StrVal: "1", }, } + analyzeMetaStrictTrueExcludeTrue = troubleshootv1beta2.AnalyzeMeta{ + Exclude: &multitype.BoolOrString{ + Type: multitype.Bool, + BoolVal: true, + }, + Strict: &multitype.BoolOrString{ + Type: multitype.Bool, + BoolVal: true, + }, + } ) func TestHasStrictAnalyzers(t *testing.T) { @@ -238,6 +248,36 @@ func TestHasStrictAnalyzers(t *testing.T) { want: true, wantErr: false, }, + { + name: "expect false when preflight spec's analyzer has analyzer with strict true and exclude true", + preflight: &troubleshootv1beta2.Preflight{ + Spec: troubleshootv1beta2.PreflightSpec{ + Analyzers: []*troubleshootv1beta2.Analyze{ + { + ClusterVersion: &troubleshootv1beta2.ClusterVersion{AnalyzeMeta: analyzeMetaStrictTrueExcludeTrue}, + }, + }, + }, + }, + want: false, + wantErr: false, + }, + { + name: "expect true when preflight spec's analyzer has analyzer with strict true in one of multiple analyzers, but one analyzer with strict true is exclude true", + preflight: &troubleshootv1beta2.Preflight{ + Spec: troubleshootv1beta2.PreflightSpec{ + Analyzers: []*troubleshootv1beta2.Analyze{ + { + ClusterVersion: &troubleshootv1beta2.ClusterVersion{AnalyzeMeta: analyzeMetaStrictTrueExcludeTrue}, + StorageClass: &troubleshootv1beta2.StorageClass{AnalyzeMeta: analyzeMetaStrictFalseInt}, + Secret: &troubleshootv1beta2.AnalyzeSecret{AnalyzeMeta: analyzeMetaStrictTrueBool}, + }, + }, + }, + }, + want: true, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {