mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-10 22:02:09 +08:00
【修改】k8s 配置
This commit is contained in:
69
apps/devops/services/k8s/cronjob/cronjob_common.go
Normal file
69
apps/devops/services/k8s/cronjob/cronjob_common.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package cronjob
|
||||
|
||||
import (
|
||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||
"pandax/apps/devops/services/k8s/common"
|
||||
"pandax/apps/devops/services/k8s/dataselect"
|
||||
)
|
||||
|
||||
// The code below allows to perform complex data section on []batch.CronJob
|
||||
|
||||
type CronJobCell batchv1beta1.CronJob
|
||||
|
||||
func (self CronJobCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue {
|
||||
switch name {
|
||||
case dataselect.NameProperty:
|
||||
return dataselect.StdComparableString(self.ObjectMeta.Name)
|
||||
case dataselect.CreationTimestampProperty:
|
||||
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
|
||||
case dataselect.NamespaceProperty:
|
||||
return dataselect.StdComparableString(self.ObjectMeta.Namespace)
|
||||
default:
|
||||
// if name is not supported then just return a constant dummy value, sort will have no effect.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func ToCells(std []batchv1beta1.CronJob) []dataselect.DataCell {
|
||||
cells := make([]dataselect.DataCell, len(std))
|
||||
for i := range std {
|
||||
cells[i] = CronJobCell(std[i])
|
||||
}
|
||||
return cells
|
||||
}
|
||||
|
||||
func FromCells(cells []dataselect.DataCell) []batchv1beta1.CronJob {
|
||||
std := make([]batchv1beta1.CronJob, len(cells))
|
||||
for i := range std {
|
||||
std[i] = batchv1beta1.CronJob(cells[i].(CronJobCell))
|
||||
}
|
||||
return std
|
||||
}
|
||||
|
||||
func getStatus(list *batchv1beta1.CronJobList) common.ResourceStatus {
|
||||
info := common.ResourceStatus{}
|
||||
if list == nil {
|
||||
return info
|
||||
}
|
||||
|
||||
for _, cronJob := range list.Items {
|
||||
if cronJob.Spec.Suspend != nil && !(*cronJob.Spec.Suspend) {
|
||||
info.Running++
|
||||
} else {
|
||||
info.Failed++
|
||||
}
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
func getContainerImages(cronJob *batchv1beta1.CronJob) []string {
|
||||
podSpec := cronJob.Spec.JobTemplate.Spec.Template.Spec
|
||||
result := make([]string, 0)
|
||||
|
||||
for _, container := range podSpec.Containers {
|
||||
result = append(result, container.Image)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user