feat: kubesphere 4.0 (#6115)

* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

---------

Signed-off-by: ci-bot <ci-bot@kubesphere.io>
Co-authored-by: ks-ci-bot <ks-ci-bot@example.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
KubeSphere CI Bot
2024-09-06 11:05:52 +08:00
committed by GitHub
parent b5015ec7b9
commit 447a51f08b
8557 changed files with 546695 additions and 1146174 deletions

View File

@@ -1,18 +1,7 @@
/*
Copyright 2019 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
* Please refer to the LICENSE file in the root directory of the project.
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
*/
package workloads
@@ -22,12 +11,13 @@ import (
"strings"
"time"
v1 "k8s.io/api/batch/v1"
batchv1 "k8s.io/api/batch/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)
const retryTimes = 3
@@ -37,16 +27,16 @@ type JobRunner interface {
}
type jobRunner struct {
client kubernetes.Interface
client runtimeclient.Client
}
func NewJobRunner(client kubernetes.Interface) JobRunner {
func NewJobRunner(client runtimeclient.Client) JobRunner {
return &jobRunner{client: client}
}
func (r *jobRunner) JobReRun(namespace, jobName, resourceVersion string) error {
job, err := r.client.BatchV1().Jobs(namespace).Get(context.Background(), jobName, metav1.GetOptions{})
if err != nil {
job := &batchv1.Job{}
if err := r.client.Get(context.Background(), types.NamespacedName{Namespace: namespace, Name: jobName}, job); err != nil {
return err
}
// do not rerun job if resourceVersion not match
@@ -60,23 +50,25 @@ func (r *jobRunner) JobReRun(namespace, jobName, resourceVersion string) error {
newJob := *job
newJob.ResourceVersion = ""
newJob.Status = v1.JobStatus{}
newJob.Status = batchv1.JobStatus{}
newJob.ObjectMeta.UID = ""
newJob.Annotations["revisions"] = strings.Replace(job.Annotations["revisions"], "running", "unfinished", -1)
delete(newJob.Spec.Selector.MatchLabels, "controller-uid")
delete(newJob.Spec.Selector.MatchLabels, "batch.kubernetes.io/controller-uid")
delete(newJob.Spec.Template.ObjectMeta.Labels, "controller-uid")
delete(newJob.Spec.Template.ObjectMeta.Labels, "batch.kubernetes.io/controller-uid")
delete(newJob.Spec.Template.ObjectMeta.Labels, "job-name")
delete(newJob.Spec.Template.ObjectMeta.Labels, "batch.kubernetes.io/job-name")
err = r.deleteJob(namespace, jobName)
if err != nil {
if err := r.deleteJob(namespace, jobName); err != nil {
klog.Errorf("failed to rerun job %s, reason: %s", jobName, err)
return fmt.Errorf("failed to rerun job %s", jobName)
}
var err error
for i := 0; i < retryTimes; i++ {
_, err = r.client.BatchV1().Jobs(namespace).Create(context.Background(), &newJob, metav1.CreateOptions{})
if err != nil {
if err = r.client.Create(context.Background(), &newJob); err != nil {
time.Sleep(time.Second)
continue
}
@@ -92,6 +84,6 @@ func (r *jobRunner) JobReRun(namespace, jobName, resourceVersion string) error {
}
func (r *jobRunner) deleteJob(namespace, job string) error {
err := r.client.BatchV1().Jobs(namespace).Delete(context.Background(), job, metav1.DeleteOptions{})
return err
return r.client.Delete(context.Background(),
&batchv1.Job{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: job}})
}