chore: upgrade v1beta1 cronjob to v1

This commit is contained in:
yangk 2022-09-26 17:37:00 +08:00 committed by yangkaa
parent c7e7edd9df
commit 5a06d037fb
9 changed files with 19 additions and 25 deletions

View File

@ -15,7 +15,6 @@ import (
appv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -203,7 +202,7 @@ func (c *clusterAction) AppYamlResourceDetailed(yamlResource api_model.YamlResou
c.PodTemplateSpecResource(parameter)
case api_model.CronJob:
cjJSON, _ := json.Marshal(buildResource.Resource)
var cjObject v1beta1.CronJob
var cjObject batchv1.CronJob
json.Unmarshal(cjJSON, &cjObject)
memory, cpu := cjObject.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Resources.Requests.Memory().Value(), cjObject.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Resources.Requests.Cpu().MilliValue()
if memory == 0 {

View File

@ -1,4 +1,4 @@
FROM golang:1.13-alpine
FROM golang:1.17-alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk --no-cache add pkgconfig gcc musl-dev

View File

@ -1,4 +1,4 @@
FROM golang:1.13
FROM golang:1.17
RUN apt update && apt-get install -y libzmq3-dev

View File

@ -64,7 +64,7 @@ build::binary() {
elif [ "$1" = "chaos" ]; then
build_dir="./cmd/builder"
elif [ "$1" = "gateway" ]; then
build_image="golang:1.13-alpine"
build_image="golang:1.17-alpine"
elif [ "$1" = "monitor" ]; then
CGO_ENABLED=0
fi

View File

@ -150,7 +150,7 @@ func (s *startController) startOne(app v1.AppService) error {
}
}
if cronjob := app.GetCronJob(); cronjob != nil {
_, err = s.manager.client.BatchV1beta1().CronJobs(app.GetNamespace()).Create(s.ctx, cronjob, metav1.CreateOptions{})
_, err = s.manager.client.BatchV1().CronJobs(app.GetNamespace()).Create(s.ctx, cronjob, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("create cronjob failure:%s;", err.Error())
}

View File

@ -27,17 +27,15 @@ import (
apimodel "github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/api/handler/app_governance_mode/adaptor"
"github.com/sirupsen/logrus"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/batch/v1beta1"
"github.com/goodrain/rainbond/db"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/util"
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"github.com/jinzhu/gorm"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@ -250,7 +248,7 @@ func initBaseJob(as *v1.AppService, service *dbmodel.TenantServices) {
}, injectLabels)
var js *apimodel.JobStrategy
if service.JobStrategy != ""{
if service.JobStrategy != "" {
err := json.Unmarshal([]byte(service.JobStrategy), &js)
if err != nil {
logrus.Error("job strategy json unmarshal error", err)
@ -290,17 +288,17 @@ func initBaseCronJob(as *v1.AppService, service *dbmodel.TenantServices) {
as.ServiceType = v1.TypeCronJob
cronJob := as.GetCronJob()
if cronJob == nil {
cronJob = &v1beta1.CronJob{}
cronJob = &batchv1.CronJob{}
}
injectLabels := getInjectLabels(as)
jobTemp := v1beta1.JobTemplateSpec{}
jobTemp := batchv1.JobTemplateSpec{}
jobTemp.Name = as.GetK8sWorkloadName()
jobTemp.Namespace = as.GetNamespace()
jobTemp.Labels = as.GetCommonLabels(jobTemp.Labels, map[string]string{
"name": service.ServiceAlias,
"version": service.DeployVersion,
}, injectLabels)
if service.JobStrategy != ""{
if service.JobStrategy != "" {
var js *apimodel.JobStrategy
err := json.Unmarshal([]byte(service.JobStrategy), &js)
if err != nil {

View File

@ -24,7 +24,6 @@ import (
appsv1 "k8s.io/client-go/listers/apps/v1"
autoscalingv2 "k8s.io/client-go/listers/autoscaling/v2beta2"
v1 "k8s.io/client-go/listers/batch/v1"
v1beta1 "k8s.io/client-go/listers/batch/v1beta1"
corev1 "k8s.io/client-go/listers/core/v1"
networkingv1 "k8s.io/client-go/listers/networking/v1"
betav1 "k8s.io/client-go/listers/networking/v1beta1"
@ -52,5 +51,5 @@ type Lister struct {
ComponentDefinition v1alpha1.ComponentDefinitionLister
ThirdComponent v1alpha1.ThirdComponentLister
Job v1.JobLister
CronJob v1beta1.CronJobLister
CronJob v1.CronJobLister
}

View File

@ -22,7 +22,6 @@ import (
"context"
"fmt"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/batch/v1beta1"
betav1 "k8s.io/api/networking/v1beta1"
"os"
"sync"
@ -248,8 +247,8 @@ func NewStore(
store.informers.ComponentDefinition.AddEventHandlerWithResyncPeriod(componentdefinition.GetComponentDefinitionBuilder(), time.Second*300)
store.informers.Job = infFactory.Batch().V1().Jobs().Informer()
store.listers.Job = infFactory.Batch().V1().Jobs().Lister()
store.informers.CronJob = infFactory.Batch().V1beta1().CronJobs().Informer()
store.listers.CronJob = infFactory.Batch().V1beta1().CronJobs().Lister()
store.informers.CronJob = infFactory.Batch().V1().CronJobs().Informer()
store.listers.CronJob = infFactory.Batch().V1().CronJobs().Lister()
// Endpoint Event Handler
epEventHandler := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
@ -456,7 +455,7 @@ func (a *appRuntimeStore) OnAdd(obj interface{}) {
}
}
if cjob, ok := obj.(*v1beta1.CronJob); ok {
if cjob, ok := obj.(*batchv1.CronJob); ok {
serviceID := cjob.Labels["service_id"]
version := cjob.Labels["version"]
createrID := cjob.Labels["creater_id"]

View File

@ -37,7 +37,6 @@ import (
v1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
storagev1 "k8s.io/api/storage/v1"
@ -164,7 +163,7 @@ type AppService struct {
statefulset *v1.StatefulSet
deployment *v1.Deployment
job *batchv1.Job
cronjob *v1beta1.CronJob
cronjob *batchv1.CronJob
workload client.Object
hpas []*autoscalingv2.HorizontalPodAutoscaler
delHPAs []*autoscalingv2.HorizontalPodAutoscaler
@ -236,7 +235,7 @@ func (a *AppService) DeleteJob(d *batchv1.Job) {
}
//DeleteCronJob delete kubernetes cronjob model
func (a *AppService) DeleteCronJob(d *v1beta1.CronJob) {
func (a *AppService) DeleteCronJob(d *batchv1.CronJob) {
a.cronjob = nil
}
@ -272,12 +271,12 @@ func (a *AppService) SetJob(d *batchv1.Job) {
}
//GetCronJob get kubernetes cronjob model
func (a AppService) GetCronJob() *v1beta1.CronJob {
func (a AppService) GetCronJob() *batchv1.CronJob {
return a.cronjob
}
//SetCronJob set kubernetes cronjob model
func (a *AppService) SetCronJob(d *v1beta1.CronJob) {
func (a *AppService) SetCronJob(d *batchv1.CronJob) {
a.cronjob = d
a.workload = d
if v, ok := d.Spec.JobTemplate.Labels["version"]; ok && v != "" {