From 5e7bd06fcbe7ffcead2f3ef30fb422e5990db672 Mon Sep 17 00:00:00 2001 From: Kira Boyle Date: Tue, 14 Jun 2022 10:23:42 -0700 Subject: [PATCH] do not return that a strict analyzer is present in an application if a strict analyzer is excluded --- pkg/preflight/util.go | 3 +++ pkg/preflight/util_test.go | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) 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) {