Merge pull request #596 from replicatedhq/kiraboyle/sc-49361/strict-preflight-is-still-being-enforced

do not return that a strict analyzer is present in an application if …
This commit is contained in:
Kira C Boyle
2022-06-14 12:03:54 -07:00
committed by GitHub
2 changed files with 43 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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) {