Reissue PAT if roles changed
[ZITADOPER-1]
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
package conditions
|
||||
|
||||
import (
|
||||
zitadelv1alpha1 "bitbucket.org/topmanage-software-engineering/zitadel-k8s-operator/src/api/v1alpha1"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func SetCompleteWithCronJob(c Conditioner, cronJob *batchv1.CronJob) {
|
||||
setScheduled := func() {
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: zitadelv1alpha1.ConditionReasonCronJobScheduled,
|
||||
Message: "Scheduled",
|
||||
})
|
||||
}
|
||||
|
||||
if cronJob.Status.LastScheduleTime == nil || cronJob.Status.LastSuccessfulTime == nil {
|
||||
setScheduled()
|
||||
return
|
||||
}
|
||||
if cronJob.Status.LastSuccessfulTime.Before(cronJob.Status.LastScheduleTime) {
|
||||
if len(cronJob.Status.Active) > 0 {
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: zitadelv1alpha1.ConditionReasonCronJobRunning,
|
||||
Message: "Running",
|
||||
})
|
||||
} else {
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: zitadelv1alpha1.ConditionReasonCronJobFailed,
|
||||
Message: "Failed",
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if cronJob.Status.LastScheduleTime.Equal(cronJob.Status.LastSuccessfulTime) ||
|
||||
cronJob.Status.LastScheduleTime.Before(cronJob.Status.LastSuccessfulTime) {
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionTrue,
|
||||
Reason: zitadelv1alpha1.ConditionReasonCronJobSuccess,
|
||||
Message: "Success",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
setScheduled()
|
||||
}
|
||||
|
||||
func SetCompleteWithJob(c Conditioner, job *batchv1.Job) {
|
||||
switch getJobConditionType(job) {
|
||||
case batchv1.JobFailed:
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionTrue,
|
||||
Reason: zitadelv1alpha1.ConditionReasonJobFailed,
|
||||
Message: "Failed",
|
||||
})
|
||||
case batchv1.JobComplete:
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionTrue,
|
||||
Reason: zitadelv1alpha1.ConditionReasonJobComplete,
|
||||
Message: "Success",
|
||||
})
|
||||
case batchv1.JobSuspended:
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: zitadelv1alpha1.ConditionReasonJobSuspended,
|
||||
Message: "Suspended",
|
||||
})
|
||||
default:
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: zitadelv1alpha1.ConditionReasonJobRunning,
|
||||
Message: "Running",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func SetCompleteFailedWithMessage(c Conditioner, message string) {
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypeComplete,
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: zitadelv1alpha1.ConditionReasonFailed,
|
||||
Message: message,
|
||||
})
|
||||
}
|
||||
|
||||
func SetCompleteFailed(c Conditioner) {
|
||||
SetCompleteFailedWithMessage(c, "Failed")
|
||||
}
|
||||
|
||||
func getJobConditionType(job *batchv1.Job) batchv1.JobConditionType {
|
||||
for _, c := range job.Status.Conditions {
|
||||
if c.Status == corev1.ConditionFalse {
|
||||
continue
|
||||
}
|
||||
return c.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
25
src/pkg/condition/pat.go
Normal file
25
src/pkg/condition/pat.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package conditions
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
zitadelv1alpha1 "bitbucket.org/topmanage-software-engineering/zitadel-k8s-operator/src/api/v1alpha1"
|
||||
)
|
||||
|
||||
func SetPatOutOfDate(c Conditioner) {
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypePATUpToDate,
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: zitadelv1alpha1.ConditionReasonRolesChanged,
|
||||
Message: "PAT out of date",
|
||||
})
|
||||
}
|
||||
|
||||
func SetPatUpToDate(c Conditioner) {
|
||||
c.SetCondition(metav1.Condition{
|
||||
Type: zitadelv1alpha1.ConditionTypePATUpToDate,
|
||||
Status: metav1.ConditionTrue,
|
||||
Reason: zitadelv1alpha1.ConditionReasonPATUpToDate,
|
||||
Message: "PAT up to date",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user