diff --git a/config/crds/troubleshoot.sh_analyzers.yaml b/config/crds/troubleshoot.sh_analyzers.yaml index afeceb48..cb71abc3 100644 --- a/config/crds/troubleshoot.sh_analyzers.yaml +++ b/config/crds/troubleshoot.sh_analyzers.yaml @@ -485,6 +485,53 @@ spec: - namespace - outcomes type: object + jobStatus: + properties: + checkName: + type: string + exclude: + type: BoolString + name: + type: string + namespace: + type: string + outcomes: + items: + properties: + fail: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + pass: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + warn: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + type: object + type: array + required: + - name + - namespace + - outcomes + type: object longhorn: properties: checkName: @@ -780,6 +827,53 @@ spec: - collectorName - outcomes type: object + replicasetStatus: + properties: + checkName: + type: string + exclude: + type: BoolString + name: + type: string + namespace: + type: string + outcomes: + items: + properties: + fail: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + pass: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + warn: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + type: object + type: array + required: + - name + - namespace + - outcomes + type: object secret: properties: checkName: diff --git a/config/crds/troubleshoot.sh_preflights.yaml b/config/crds/troubleshoot.sh_preflights.yaml index 50972b0a..5ae9ab35 100644 --- a/config/crds/troubleshoot.sh_preflights.yaml +++ b/config/crds/troubleshoot.sh_preflights.yaml @@ -485,6 +485,53 @@ spec: - namespace - outcomes type: object + jobStatus: + properties: + checkName: + type: string + exclude: + type: BoolString + name: + type: string + namespace: + type: string + outcomes: + items: + properties: + fail: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + pass: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + warn: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + type: object + type: array + required: + - name + - namespace + - outcomes + type: object longhorn: properties: checkName: @@ -780,6 +827,53 @@ spec: - collectorName - outcomes type: object + replicasetStatus: + properties: + checkName: + type: string + exclude: + type: BoolString + name: + type: string + namespace: + type: string + outcomes: + items: + properties: + fail: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + pass: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + warn: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + type: object + type: array + required: + - name + - namespace + - outcomes + type: object secret: properties: checkName: diff --git a/config/crds/troubleshoot.sh_supportbundles.yaml b/config/crds/troubleshoot.sh_supportbundles.yaml index b0ac84f8..b606854d 100644 --- a/config/crds/troubleshoot.sh_supportbundles.yaml +++ b/config/crds/troubleshoot.sh_supportbundles.yaml @@ -516,6 +516,53 @@ spec: - namespace - outcomes type: object + jobStatus: + properties: + checkName: + type: string + exclude: + type: BoolString + name: + type: string + namespace: + type: string + outcomes: + items: + properties: + fail: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + pass: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + warn: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + type: object + type: array + required: + - name + - namespace + - outcomes + type: object longhorn: properties: checkName: @@ -811,6 +858,53 @@ spec: - collectorName - outcomes type: object + replicasetStatus: + properties: + checkName: + type: string + exclude: + type: BoolString + name: + type: string + namespace: + type: string + outcomes: + items: + properties: + fail: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + pass: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + warn: + properties: + message: + type: string + uri: + type: string + when: + type: string + type: object + type: object + type: array + required: + - name + - namespace + - outcomes + type: object secret: properties: checkName: diff --git a/pkg/analyze/node_resources.go b/pkg/analyze/node_resources.go index 4f99fdef..ff25807c 100644 --- a/pkg/analyze/node_resources.go +++ b/pkg/analyze/node_resources.go @@ -50,7 +50,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec for _, outcome := range analyzer.Outcomes { if outcome.Fail != nil { - isWhenMatch, err := compareNodeResourceConditionalToActual(outcome.Fail.When, matchingNodes, len(nodes)) + isWhenMatch, err := compareNodeResourceConditionalToActual(outcome.Fail.When, matchingNodes) if err != nil { return nil, errors.Wrap(err, "failed to parse when") } @@ -63,7 +63,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec return result, nil } } else if outcome.Warn != nil { - isWhenMatch, err := compareNodeResourceConditionalToActual(outcome.Warn.When, matchingNodes, len(nodes)) + isWhenMatch, err := compareNodeResourceConditionalToActual(outcome.Warn.When, matchingNodes) if err != nil { return nil, errors.Wrap(err, "failed to parse when") } @@ -76,7 +76,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec return result, nil } } else if outcome.Pass != nil { - isWhenMatch, err := compareNodeResourceConditionalToActual(outcome.Pass.When, matchingNodes, len(nodes)) + isWhenMatch, err := compareNodeResourceConditionalToActual(outcome.Pass.When, matchingNodes) if err != nil { return nil, errors.Wrap(err, "failed to parse when") } @@ -94,7 +94,7 @@ func analyzeNodeResources(analyzer *troubleshootv1beta2.NodeResources, getCollec return result, nil } -func compareNodeResourceConditionalToActual(conditional string, matchingNodes []corev1.Node, totalNodeCount int) (res bool, err error) { +func compareNodeResourceConditionalToActual(conditional string, matchingNodes []corev1.Node) (res bool, err error) { res = false err = nil @@ -159,6 +159,27 @@ func compareNodeResourceConditionalToActual(conditional string, matchingNodes [] actualValue = findMax(matchingNodes, property) case "sum": actualValue = findSum(matchingNodes, property) + case "nodeCondition": + operatorChecker := regexp.MustCompile(`={1,3}`) + if !operatorChecker.MatchString(operator) { + err = errors.New("nodeCondition function can only be compared using equals expression.") + return + } + if match[2] == "" { + err = errors.New("value function parameter missing.") + return + } + + for _, node := range matchingNodes { + for _, condition := range node.Status.Conditions { + if string(condition.Type) == match[2] && condition.Status == desiredValue { + res = true + return + } + } + } + res = false + return } switch operator { diff --git a/pkg/analyze/node_resources_test.go b/pkg/analyze/node_resources_test.go index ea2ba8f1..d1dd68ed 100644 --- a/pkg/analyze/node_resources_test.go +++ b/pkg/analyze/node_resources_test.go @@ -371,7 +371,7 @@ func Test_compareNodeResourceConditionalToActual(t *testing.T) { t.Run(test.name, func(t *testing.T) { req := require.New(t) - actual, err := compareNodeResourceConditionalToActual(test.conditional, test.matchingNodes, test.totalNodeCount) + actual, err := compareNodeResourceConditionalToActual(test.conditional, test.matchingNodes) if test.isError { req.Error(err) } else { diff --git a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go index 5b5181fe..59713525 100644 --- a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/pkg/apis/troubleshoot/v1beta2/zz_generated.deepcopy.go b/pkg/apis/troubleshoot/v1beta2/zz_generated.deepcopy.go index 3ddf8c9a..c368877b 100644 --- a/pkg/apis/troubleshoot/v1beta2/zz_generated.deepcopy.go +++ b/pkg/apis/troubleshoot/v1beta2/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/pkg/longhorn/util/iscsi.go b/pkg/longhorn/util/iscsi.go index b10562a3..c5bd3f13 100644 --- a/pkg/longhorn/util/iscsi.go +++ b/pkg/longhorn/util/iscsi.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package util diff --git a/pkg/longhorn/util/iscsi_windows.go b/pkg/longhorn/util/iscsi_windows.go index 6d98e9aa..d9efaefe 100644 --- a/pkg/longhorn/util/iscsi_windows.go +++ b/pkg/longhorn/util/iscsi_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package util diff --git a/schemas/analyzer-troubleshoot-v1beta2.json b/schemas/analyzer-troubleshoot-v1beta2.json index e6c2a8f0..ced0c791 100644 --- a/schemas/analyzer-troubleshoot-v1beta2.json +++ b/schemas/analyzer-troubleshoot-v1beta2.json @@ -711,6 +711,78 @@ } } }, + "jobStatus": { + "type": "object", + "required": [ + "name", + "namespace", + "outcomes" + ], + "properties": { + "checkName": { + "type": "string" + }, + "exclude": { + "oneOf": [{"type": "string"},{"type": "boolean"}] + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "outcomes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fail": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "pass": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "warn": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + } + } + } + } + } + }, "longhorn": { "type": "object", "required": [ @@ -1167,6 +1239,78 @@ } } }, + "replicasetStatus": { + "type": "object", + "required": [ + "name", + "namespace", + "outcomes" + ], + "properties": { + "checkName": { + "type": "string" + }, + "exclude": { + "oneOf": [{"type": "string"},{"type": "boolean"}] + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "outcomes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fail": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "pass": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "warn": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + } + } + } + } + } + }, "secret": { "type": "object", "required": [ diff --git a/schemas/preflight-troubleshoot-v1beta2.json b/schemas/preflight-troubleshoot-v1beta2.json index b2f32204..42aaf089 100644 --- a/schemas/preflight-troubleshoot-v1beta2.json +++ b/schemas/preflight-troubleshoot-v1beta2.json @@ -711,6 +711,78 @@ } } }, + "jobStatus": { + "type": "object", + "required": [ + "name", + "namespace", + "outcomes" + ], + "properties": { + "checkName": { + "type": "string" + }, + "exclude": { + "oneOf": [{"type": "string"},{"type": "boolean"}] + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "outcomes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fail": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "pass": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "warn": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + } + } + } + } + } + }, "longhorn": { "type": "object", "required": [ @@ -1167,6 +1239,78 @@ } } }, + "replicasetStatus": { + "type": "object", + "required": [ + "name", + "namespace", + "outcomes" + ], + "properties": { + "checkName": { + "type": "string" + }, + "exclude": { + "oneOf": [{"type": "string"},{"type": "boolean"}] + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "outcomes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fail": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "pass": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "warn": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + } + } + } + } + } + }, "secret": { "type": "object", "required": [ diff --git a/schemas/supportbundle-troubleshoot-v1beta2.json b/schemas/supportbundle-troubleshoot-v1beta2.json index 59c8101b..dc66c196 100644 --- a/schemas/supportbundle-troubleshoot-v1beta2.json +++ b/schemas/supportbundle-troubleshoot-v1beta2.json @@ -757,6 +757,78 @@ } } }, + "jobStatus": { + "type": "object", + "required": [ + "name", + "namespace", + "outcomes" + ], + "properties": { + "checkName": { + "type": "string" + }, + "exclude": { + "oneOf": [{"type": "string"},{"type": "boolean"}] + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "outcomes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fail": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "pass": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "warn": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + } + } + } + } + } + }, "longhorn": { "type": "object", "required": [ @@ -1213,6 +1285,78 @@ } } }, + "replicasetStatus": { + "type": "object", + "required": [ + "name", + "namespace", + "outcomes" + ], + "properties": { + "checkName": { + "type": "string" + }, + "exclude": { + "oneOf": [{"type": "string"},{"type": "boolean"}] + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "outcomes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fail": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "pass": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + }, + "warn": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "uri": { + "type": "string" + }, + "when": { + "type": "string" + } + } + } + } + } + } + } + }, "secret": { "type": "object", "required": [