package cluster // The built-in kinds that the operator creates, as the types of // k8s.io/api. Each wrapper answers the metadata the way liken's memo // reads it, which the types' own GetObjectMeta does not. import ( appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "github.com/liken-sh/liken/kubernetes/memo" ) type Job struct{ batchv1.Job } func (o *Job) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type CronJob struct{ batchv1.CronJob } func (o *CronJob) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type Secret struct{ corev1.Secret } func (o *Secret) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type ServiceAccount struct{ corev1.ServiceAccount } func (o *ServiceAccount) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type RoleBinding struct{ rbacv1.RoleBinding } func (o *RoleBinding) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type ClusterRoleBinding struct{ rbacv1.ClusterRoleBinding } func (o *ClusterRoleBinding) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type Deployment struct{ appsv1.Deployment } func (o *Deployment) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type PersistentVolumeClaim struct{ corev1.PersistentVolumeClaim } func (o *PersistentVolumeClaim) GetObjectMeta() memo.Meta { return &o.ObjectMeta } type Pod struct{ corev1.Pod } func (o *Pod) GetObjectMeta() memo.Meta { return &o.ObjectMeta } // JobOutcome reads how a Job ended: done is false while it runs. A // Job's conditions say it: SuccessCriteriaMet and FailureTarget come // first, and Complete and Failed follow once its pods are gone. func JobOutcome(job *Job) (done, succeeded bool) { for _, c := range job.Status.Conditions { if c.Status != corev1.ConditionTrue { continue } switch c.Type { case batchv1.JobComplete, batchv1.JobSuccessCriteriaMet: return true, true case batchv1.JobFailed, batchv1.JobFailureTarget: return true, false } } return false, false }