add job and pod wellknownStatusRules (#113)

Signed-off-by: Zhiwei Yin <zyin@redhat.com>
This commit is contained in:
Zhiwei Yin
2022-01-29 02:30:25 -05:00
committed by GitHub
parent 1edddab8a8
commit f5ca2e6751
2 changed files with 105 additions and 0 deletions
+81
View File
@@ -48,6 +48,43 @@ const (
}
}
`
jobJson = `
{
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": "test"
},
"status": {
"conditions": [
{
"status": "True",
"type": "Complete"
}
],
"succeeded": 1
}
}
`
podJson = `
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "test"
},
"status": {
"conditions": [
{
"status": "False",
"type": "Ready"
}
],
"phase": "Succeeded"
}
}
`
)
func unstrctureObject(data string) *unstructured.Unstructured {
@@ -171,6 +208,50 @@ func TestStatusReader(t *testing.T) {
},
},
},
{
name: "Job values",
object: unstrctureObject(jobJson),
rule: workapiv1.FeedbackRule{Type: workapiv1.WellKnownStatusType},
expectError: false,
expectedValue: []workapiv1.FeedbackValue{
{
Name: "JobComplete",
Value: workapiv1.FieldValue{
Type: workapiv1.String,
String: util.StringPtr("True"),
},
},
{
Name: "JobSucceeded",
Value: workapiv1.FieldValue{
Type: workapiv1.Integer,
Integer: util.Int64Ptr(1),
},
},
},
},
{
name: "Pod values",
object: unstrctureObject(podJson),
rule: workapiv1.FeedbackRule{Type: workapiv1.WellKnownStatusType},
expectError: false,
expectedValue: []workapiv1.FeedbackValue{
{
Name: "PodReady",
Value: workapiv1.FieldValue{
Type: workapiv1.String,
String: util.StringPtr("False"),
},
},
{
Name: "PodPhase",
Value: workapiv1.FieldValue{
Type: workapiv1.String,
String: util.StringPtr("Succeeded"),
},
},
},
},
}
reader := NewStatusReader()
+24
View File
@@ -28,10 +28,34 @@ var deploymentRule = []workapiv1.JsonPath{
},
}
var jobRule = []workapiv1.JsonPath{
{
Name: "JobComplete",
Path: `.status.conditions[?(@.type=="Complete")].status`,
},
{
Name: "JobSucceeded",
Path: `.status.succeeded`,
},
}
var podRule = []workapiv1.JsonPath{
{
Name: "PodReady",
Path: `.status.conditions[?(@.type=="Ready")].status`,
},
{
Name: "PodPhase",
Path: `.status.phase`,
},
}
func DefaultWellKnownStatusRule() WellKnownStatusRuleResolver {
return &DefaultWellKnownStatusResolver{
rules: map[schema.GroupVersionKind][]workapiv1.JsonPath{
{Group: "apps", Version: "v1", Kind: "Deployment"}: deploymentRule,
{Group: "batch", Version: "v1", Kind: "Job"}: jobRule,
{Group: "", Version: "v1", Kind: "Pod"}: podRule,
},
}
}