MCPcopy Create free account
hub / github.com/crossplane-contrib/function-patch-and-transform / RunReadinessCheck

Function RunReadinessCheck

ready.go:60–108  ·  view source on GitHub ↗

RunReadinessCheck runs the readiness check against the supplied object.

(c v1beta1.ReadinessCheck, o ConditionedObject)

Source from the content-addressed store, hash-verified

58
59// RunReadinessCheck runs the readiness check against the supplied object.
60func RunReadinessCheck(c v1beta1.ReadinessCheck, o ConditionedObject) (bool, error) { //nolint:gocyclo // just a switch
61 if err := ValidateReadinessCheck(c); err != nil {
62 return false, errors.Wrap(err, errInvalidCheck)
63 }
64
65 p, err := fieldpath.PaveObject(o)
66 if err != nil {
67 return false, errors.Wrap(err, errPaveObject)
68 }
69
70 switch c.Type {
71 case v1beta1.ReadinessCheckTypeNone:
72 return true, nil
73 case v1beta1.ReadinessCheckTypeNonEmpty:
74 if _, err := p.GetValue(*c.FieldPath); err != nil {
75 return false, resource.Ignore(fieldpath.IsNotFound, err)
76 }
77 return true, nil
78 case v1beta1.ReadinessCheckTypeMatchString:
79 val, err := p.GetString(*c.FieldPath)
80 if err != nil {
81 return false, resource.Ignore(fieldpath.IsNotFound, err)
82 }
83 return val == *c.MatchString, nil
84 case v1beta1.ReadinessCheckTypeMatchInteger:
85 val, err := p.GetInteger(*c.FieldPath)
86 if err != nil {
87 return false, resource.Ignore(fieldpath.IsNotFound, err)
88 }
89 return val == *c.MatchInteger, nil
90 case v1beta1.ReadinessCheckTypeMatchCondition:
91 val := o.GetCondition(c.MatchCondition.Type)
92 return val.Status == c.MatchCondition.Status, nil
93 case v1beta1.ReadinessCheckTypeMatchFalse:
94 val, err := p.GetBool(*c.FieldPath)
95 if err != nil {
96 return false, resource.Ignore(fieldpath.IsNotFound, err)
97 }
98 return !val, nil //nolint:gosimple // returning '!val' here as suggested hurts readability
99 case v1beta1.ReadinessCheckTypeMatchTrue:
100 val, err := p.GetBool(*c.FieldPath)
101 if err != nil {
102 return false, resource.Ignore(fieldpath.IsNotFound, err)
103 }
104 return val, nil //nolint:gosimple // returning 'val' here as suggested hurts readability
105 }
106
107 return false, nil
108}

Callers 1

IsReadyFunction · 0.85

Calls 1

ValidateReadinessCheckFunction · 0.85

Tested by

no test coverage detected