mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Merge pull request #102143 from wangyysde/promote-cronjob-integration
Promote cronjob integration test to batch/v1
This commit is contained in:
commit
36a19df91b
@ -99,7 +99,7 @@ run_template_output_tests() {
|
||||
|
||||
# check that "create job" command supports --template output
|
||||
kubectl create "${kube_flags[@]:?}" -f - <<EOF
|
||||
apiVersion: batch/v1beta1
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: pi
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||
@ -43,7 +42,6 @@ import (
|
||||
e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics"
|
||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
@ -108,9 +106,6 @@ var (
|
||||
// This timeout covers two resync/retry periods, and should be added to wait timeouts to account for delays
|
||||
// to the GC controller caused by API changes in other tests.
|
||||
gcInformerResyncRetryTimeout = time.Minute
|
||||
|
||||
// CronJobGroupVersionResource unambiguously identifies a CronJob resource.
|
||||
CronJobGroupVersionResource = schema.GroupVersionResource{Group: batchv1beta1.GroupName, Version: "v1beta1", Resource: "cronjobs"}
|
||||
)
|
||||
|
||||
func getPodTemplateSpec(labels map[string]string) v1.PodTemplateSpec {
|
||||
@ -231,7 +226,7 @@ func verifyRemainingObjects(f *framework.Framework, objects map[string]int) (boo
|
||||
ginkgo.By(fmt.Sprintf("expected %d RCs, got %d RCs", num, len(rcs.Items)))
|
||||
}
|
||||
case "CronJobs":
|
||||
cronJobs, err := f.ClientSet.BatchV1beta1().CronJobs(f.Namespace.Name).List(context.TODO(), metav1.ListOptions{})
|
||||
cronJobs, err := f.ClientSet.BatchV1().CronJobs(f.Namespace.Name).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to list cronjobs: %v", err)
|
||||
}
|
||||
@ -273,19 +268,19 @@ func gatherMetrics(f *framework.Framework) {
|
||||
}
|
||||
}
|
||||
|
||||
func newCronJob(name, schedule string) *batchv1beta1.CronJob {
|
||||
func newCronJob(name, schedule string) *batchv1.CronJob {
|
||||
parallelism := int32(1)
|
||||
completions := int32(1)
|
||||
return &batchv1beta1.CronJob{
|
||||
return &batchv1.CronJob{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "CronJob",
|
||||
},
|
||||
Spec: batchv1beta1.CronJobSpec{
|
||||
Spec: batchv1.CronJobSpec{
|
||||
Schedule: schedule,
|
||||
JobTemplate: batchv1beta1.JobTemplateSpec{
|
||||
JobTemplate: batchv1.JobTemplateSpec{
|
||||
Spec: batchv1.JobSpec{
|
||||
Parallelism: ¶llelism,
|
||||
Completions: &completions,
|
||||
@ -1158,11 +1153,10 @@ var _ = SIGDescribe("Garbage collector", func() {
|
||||
})
|
||||
|
||||
ginkgo.It("should delete jobs and pods created by cronjob", func() {
|
||||
e2eskipper.SkipIfMissingResource(f.DynamicClient, CronJobGroupVersionResource, f.Namespace.Name)
|
||||
|
||||
ginkgo.By("Create the cronjob")
|
||||
cronJob := newCronJob("simple", "*/1 * * * ?")
|
||||
cronJob, err := f.ClientSet.BatchV1beta1().CronJobs(f.Namespace.Name).Create(context.TODO(), cronJob, metav1.CreateOptions{})
|
||||
cronJob, err := f.ClientSet.BatchV1().CronJobs(f.Namespace.Name).Create(context.TODO(), cronJob, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err, "failed to create cronjob: %+v, in namespace: %s", cronJob, f.Namespace.Name)
|
||||
|
||||
ginkgo.By("Wait for the CronJob to create new Job")
|
||||
@ -1178,7 +1172,7 @@ var _ = SIGDescribe("Garbage collector", func() {
|
||||
}
|
||||
|
||||
ginkgo.By("Delete the cronjob")
|
||||
if err := f.ClientSet.BatchV1beta1().CronJobs(f.Namespace.Name).Delete(context.TODO(), cronJob.Name, getBackgroundOptions()); err != nil {
|
||||
if err := f.ClientSet.BatchV1().CronJobs(f.Namespace.Name).Delete(context.TODO(), cronJob.Name, getBackgroundOptions()); err != nil {
|
||||
framework.Failf("Failed to delete the CronJob: %v", err)
|
||||
}
|
||||
ginkgo.By("Verify if cronjob does not leave jobs nor pods behind")
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"time"
|
||||
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
@ -32,7 +31,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
@ -164,20 +162,20 @@ var _ = SIGDescribe("Generated clientset", func() {
|
||||
})
|
||||
})
|
||||
|
||||
func newTestingCronJob(name string, value string) *batchv1beta1.CronJob {
|
||||
func newTestingCronJob(name string, value string) *batchv1.CronJob {
|
||||
parallelism := int32(1)
|
||||
completions := int32(1)
|
||||
return &batchv1beta1.CronJob{
|
||||
return &batchv1.CronJob{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: map[string]string{
|
||||
"time": value,
|
||||
},
|
||||
},
|
||||
Spec: batchv1beta1.CronJobSpec{
|
||||
Spec: batchv1.CronJobSpec{
|
||||
Schedule: "*/1 * * * ?",
|
||||
ConcurrencyPolicy: batchv1beta1.AllowConcurrent,
|
||||
JobTemplate: batchv1beta1.JobTemplateSpec{
|
||||
ConcurrencyPolicy: batchv1.AllowConcurrent,
|
||||
JobTemplate: batchv1.JobTemplateSpec{
|
||||
Spec: batchv1.JobSpec{
|
||||
Parallelism: ¶llelism,
|
||||
Completions: &completions,
|
||||
@ -215,12 +213,8 @@ func newTestingCronJob(name string, value string) *batchv1beta1.CronJob {
|
||||
var _ = SIGDescribe("Generated clientset", func() {
|
||||
f := framework.NewDefaultFramework("clientset")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
e2eskipper.SkipIfMissingResource(f.DynamicClient, CronJobGroupVersionResource, f.Namespace.Name)
|
||||
})
|
||||
|
||||
ginkgo.It("should create v1beta1 cronJobs, delete cronJobs, watch cronJobs", func() {
|
||||
cronJobClient := f.ClientSet.BatchV1beta1().CronJobs(f.Namespace.Name)
|
||||
ginkgo.It("should create v1 cronJobs, delete cronJobs, watch cronJobs", func() {
|
||||
cronJobClient := f.ClientSet.BatchV1().CronJobs(f.Namespace.Name)
|
||||
ginkgo.By("constructing the cronJob")
|
||||
name := "cronjob" + string(uuid.NewUUID())
|
||||
value := strconv.Itoa(time.Now().Nanosecond())
|
||||
|
@ -42,7 +42,6 @@ import (
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
e2ejob "k8s.io/kubernetes/test/e2e/framework/job"
|
||||
e2eresource "k8s.io/kubernetes/test/e2e/framework/resource"
|
||||
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
)
|
||||
|
||||
@ -60,10 +59,6 @@ var _ = SIGDescribe("CronJob", func() {
|
||||
successCommand := []string{"/bin/true"}
|
||||
failureCommand := []string{"/bin/false"}
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
e2eskipper.SkipIfMissingResource(f.DynamicClient, CronJobGroupVersionResourceBeta, f.Namespace.Name)
|
||||
})
|
||||
|
||||
/*
|
||||
Release: v1.21
|
||||
Testname: CronJob AllowConcurrent
|
||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package apps
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
)
|
||||
|
||||
@ -28,9 +27,6 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// CronJobGroupVersionResourceBeta unambiguously identifies a resource of cronjob with beta status
|
||||
CronJobGroupVersionResourceBeta = schema.GroupVersionResource{Group: "batch", Version: "v1beta1", Resource: "cronjobs"}
|
||||
|
||||
// WebserverImage is the fully qualified URI to the Httpd image
|
||||
WebserverImage = imageutils.GetE2EImage(imageutils.Httpd)
|
||||
|
||||
|
@ -1201,7 +1201,7 @@ metadata:
|
||||
|
||||
ginkgo.By("waiting for cronjob to start.")
|
||||
err := wait.PollImmediate(time.Second, time.Minute, func() (bool, error) {
|
||||
cj, err := c.BatchV1beta1().CronJobs(ns).List(context.TODO(), metav1.ListOptions{})
|
||||
cj, err := c.BatchV1().CronJobs(ns).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Failed getting CronJob %s: %v", ns, err)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
apiVersion: batch/v1beta1
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: cronjob-test
|
||||
|
@ -24,13 +24,12 @@ import (
|
||||
"time"
|
||||
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
batchv1beta1 "k8s.io/api/batch/v1beta1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/informers"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
clientbatchv1beta1 "k8s.io/client-go/kubernetes/typed/batch/v1beta1"
|
||||
clientbatchv1 "k8s.io/client-go/kubernetes/typed/batch/v1"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/kubernetes/pkg/controller/cronjob"
|
||||
"k8s.io/kubernetes/pkg/controller/job"
|
||||
@ -57,22 +56,22 @@ func setup(t *testing.T) (*httptest.Server, framework.CloseFunc, *cronjob.Contro
|
||||
return server, closeFn, cjc, jc, informerSet, clientSet, config
|
||||
}
|
||||
|
||||
func newCronJob(name, namespace, schedule string) *batchv1beta1.CronJob {
|
||||
func newCronJob(name, namespace, schedule string) *batchv1.CronJob {
|
||||
zero64 := int64(0)
|
||||
zero32 := int32(0)
|
||||
return &batchv1beta1.CronJob{
|
||||
return &batchv1.CronJob{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "CronJob",
|
||||
APIVersion: "batch/v1beta1",
|
||||
APIVersion: "batch/v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: name,
|
||||
},
|
||||
Spec: batchv1beta1.CronJobSpec{
|
||||
Spec: batchv1.CronJobSpec{
|
||||
Schedule: schedule,
|
||||
SuccessfulJobsHistoryLimit: &zero32,
|
||||
JobTemplate: batchv1beta1.JobTemplateSpec{
|
||||
JobTemplate: batchv1.JobTemplateSpec{
|
||||
Spec: batchv1.JobSpec{
|
||||
Template: corev1.PodTemplateSpec{
|
||||
Spec: corev1.PodSpec{
|
||||
@ -87,7 +86,7 @@ func newCronJob(name, namespace, schedule string) *batchv1beta1.CronJob {
|
||||
}
|
||||
}
|
||||
|
||||
func cleanupCronJobs(t *testing.T, cjClient clientbatchv1beta1.CronJobInterface, name string) {
|
||||
func cleanupCronJobs(t *testing.T, cjClient clientbatchv1.CronJobInterface, name string) {
|
||||
deletePropagation := metav1.DeletePropagationForeground
|
||||
err := cjClient.Delete(context.TODO(), name, metav1.DeleteOptions{PropagationPolicy: &deletePropagation})
|
||||
if err != nil {
|
||||
@ -154,7 +153,7 @@ func TestCronJobLaunchesPodAndCleansUp(t *testing.T) {
|
||||
ns := framework.CreateTestingNamespace(namespaceName, server, t)
|
||||
defer framework.DeleteTestingNamespace(ns, server, t)
|
||||
|
||||
cjClient := clientSet.BatchV1beta1().CronJobs(ns.Name)
|
||||
cjClient := clientSet.BatchV1().CronJobs(ns.Name)
|
||||
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
Loading…
Reference in New Issue
Block a user