Merge pull request #474 from replicatedhq/add-node-status-check

38798: Adding node status check
This commit is contained in:
Sean Rester
2021-10-28 17:52:18 -04:00
committed by GitHub
12 changed files with 744 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package util

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package util

View File

@@ -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": [

View File

@@ -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": [

View File

@@ -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": [