mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: use scheme create obj
Signed-off-by: HanMengnan <1448189829@qq.com>
This commit is contained in:
@@ -107,6 +107,7 @@ require (
|
||||
k8s.io/klog/v2 v2.60.1
|
||||
k8s.io/kube-aggregator v0.23.0
|
||||
k8s.io/kubectl v0.23.6
|
||||
k8s.io/kubernetes v1.13.0
|
||||
k8s.io/metrics v0.23.6
|
||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
|
||||
open-cluster-management.io/api v0.7.0
|
||||
|
||||
@@ -3186,6 +3186,7 @@ k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65/go.mod h1:sX9MT8g7NVZM5lV
|
||||
k8s.io/kubectl v0.22.4/go.mod h1:ok2qRT6y2Gy4+y+mniJVyUMKeBHP4OWS9Rdtf/QTM5I=
|
||||
k8s.io/kubectl v0.23.6 h1:ajzrqj88GqlH/gpscMCts+mKNeSJprpkWJEHO8CR2Ss=
|
||||
k8s.io/kubectl v0.23.6/go.mod h1:mMtJhc2QtQiSfvIQoMEUIjGHtZuP4uxMy/ees6j6zx8=
|
||||
k8s.io/kubernetes v1.13.0 h1:qTfB+u5M92k2fCCCVP2iuhgwwSOv1EkAkvQY1tQODD8=
|
||||
k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
|
||||
k8s.io/metrics v0.22.4/go.mod h1:6F/iwuYb1w2QDCoHkeMFLf4pwHBcYKLm4mPtVHKYrIw=
|
||||
k8s.io/metrics v0.23.6 h1:GH9tTTq7l6DNhzFsLW3Q3xG1LWEk/VT853T6r1mo3uI=
|
||||
|
||||
@@ -23,12 +23,12 @@ import (
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/utils/pointer"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||
|
||||
"k8s.io/utils/pointer"
|
||||
|
||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||
)
|
||||
|
||||
@@ -60,7 +60,11 @@ var _ = BeforeSuite(func(done Done) {
|
||||
|
||||
By("new kube client")
|
||||
cfg.Timeout = time.Minute * 2
|
||||
k8sClient, err = client.New(cfg, client.Options{Scheme: common.Scheme})
|
||||
|
||||
scheme := common.Scheme
|
||||
batchv1.AddToScheme(scheme)
|
||||
|
||||
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
|
||||
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(k8sClient).ToNot(BeNil())
|
||||
|
||||
@@ -18,6 +18,7 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -34,6 +35,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
|
||||
types2 "k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
"k8s.io/utils/pointer"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
@@ -1245,9 +1247,35 @@ var _ = Describe("unit-test to e2e test", func() {
|
||||
},
|
||||
},
|
||||
}
|
||||
cronJob1 := batch.CronJob{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "batch/v1",
|
||||
Kind: "CronJob",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "cronjob1",
|
||||
Namespace: "test-namespace",
|
||||
Labels: map[string]string{
|
||||
"app": "cronJob1",
|
||||
},
|
||||
},
|
||||
Spec: batch.CronJobSpec{
|
||||
JobTemplate: batch.JobTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{},
|
||||
Spec: batch.JobSpec{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"app": "cronJob1",
|
||||
},
|
||||
MatchExpressions: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var objectList []client.Object
|
||||
objectList = append(objectList, &deploy1, &deploy1, &rs1, &rs2, &rs3, &rs4, &pod1, &pod2, &pod3, &rs4, &pod4, &pod5)
|
||||
objectList = append(objectList, &deploy1, &deploy1, &rs1, &rs2, &rs3, &rs4, &pod1, &pod2, &pod3, &rs4, &pod4, &pod5, &cronJob1)
|
||||
BeforeEach(func() {
|
||||
Expect(k8sClient.Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "test-namespace"}})).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{}))
|
||||
Expect(k8sClient.Create(ctx, deploy1.DeepCopy())).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{}))
|
||||
@@ -1272,6 +1300,10 @@ var _ = Describe("unit-test to e2e test", func() {
|
||||
},
|
||||
})
|
||||
Expect(k8sClient.Create(ctx, cPod4)).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{}))
|
||||
|
||||
Expect(k8sClient.Create(ctx, pod5.DeepCopy())).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{}))
|
||||
err := k8sClient.Create(ctx, cronJob1.DeepCopy())
|
||||
fmt.Println(err)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
@@ -1321,8 +1353,11 @@ var _ = Describe("unit-test to e2e test", func() {
|
||||
Expect(len(items3)).Should(BeEquivalentTo(1))
|
||||
|
||||
u4 := unstructured.Unstructured{}
|
||||
dec := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
|
||||
_, _, err = dec.Decode([]byte(cronJob), nil, &u4)
|
||||
u4.SetNamespace(cronJob1.Namespace)
|
||||
u4.SetName(cronJob1.Name)
|
||||
u4.SetAPIVersion("batch/v1")
|
||||
u4.SetKind("CronJob")
|
||||
Expect(k8sClient.Get(ctx, types2.NamespacedName{Namespace: u4.GetNamespace(), Name: u4.GetName()}, &u4))
|
||||
Expect(err).Should(BeNil())
|
||||
item4, err := listItemByRule(ctx, k8sClient, ResourceType{APIVersion: "v1", Kind: "Pod"}, u4,
|
||||
cronJobLabelListOption, nil, true)
|
||||
|
||||
Reference in New Issue
Block a user