-
Notifications
You must be signed in to change notification settings - Fork 3
/
is_access_expired.go
53 lines (48 loc) · 1.32 KB
/
is_access_expired.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package requestcontroller
import (
"fmt"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/diranged/oz/internal/api/v1alpha1"
)
func (r *RequestReconciler) isAccessExpired(
rctx *RequestContext,
) (shouldEndReconcile bool, result ctrl.Result, resultErr error) {
rctx.log.V(1).Info("Checking if access has expired...")
conditions := rctx.obj.GetStatus().GetConditions()
cond := meta.FindStatusCondition(*conditions, v1alpha1.ConditionAccessStillValid.String())
if cond == nil {
rctx.log.V(1).Info(
fmt.Sprintf(
"Missing Condition %s, skipping deletion",
v1alpha1.ConditionAccessStillValid,
),
)
shouldEndReconcile = false
resultErr = nil
} else if cond.Status == metav1.ConditionFalse {
rctx.log.Info(
fmt.Sprintf(
"Found Condition %s in state %s, terminating request",
v1alpha1.ConditionAccessStillValid,
cond.Status,
),
)
shouldEndReconcile = true
result = ctrl.Result{}
resultErr = r.Delete(rctx.Context, rctx.obj)
} else {
rctx.log.V(1).Info(
fmt.Sprintf(
"Found Condition %s in state %s, leaving alone",
v1alpha1.ConditionAccessStillValid,
cond.Status,
),
)
shouldEndReconcile = false
result = ctrl.Result{}
resultErr = nil
}
return shouldEndReconcile, result, resultErr
}