update notification manager to v2.0 (#5030)
Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
This commit is contained in:
@@ -26,20 +26,19 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
k8sinformers "k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
fakek8s "k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"kubesphere.io/api/cluster/v1alpha1"
|
||||
"kubesphere.io/api/notification/v2beta2"
|
||||
"kubesphere.io/api/types/v1beta1"
|
||||
"kubesphere.io/api/types/v1beta2"
|
||||
"sigs.k8s.io/controller-runtime/pkg/cache"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
|
||||
|
||||
"kubesphere.io/api/cluster/v1alpha1"
|
||||
"kubesphere.io/api/notification/v2beta1"
|
||||
"kubesphere.io/api/types/v1beta1"
|
||||
|
||||
k8sinformers "k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/apis"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
)
|
||||
@@ -52,12 +51,13 @@ func TestSource(t *testing.T) {
|
||||
|
||||
var (
|
||||
_ = Describe("Secret", func() {
|
||||
v2beta1.AddToScheme(scheme.Scheme)
|
||||
apis.AddToScheme(scheme.Scheme)
|
||||
_ = v2beta2.AddToScheme(scheme.Scheme)
|
||||
_ = apis.AddToScheme(scheme.Scheme)
|
||||
_ = v1beta2.AddToScheme(scheme.Scheme)
|
||||
|
||||
secret := &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Name: "secret-foo",
|
||||
Namespace: constants.NotificationSecretNamespace,
|
||||
Labels: map[string]string{
|
||||
constants.NotificationManagedLabel: "true",
|
||||
@@ -65,24 +65,39 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
config := &v2beta1.Config{
|
||||
config := &v2beta2.Config{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Name: "config-foo",
|
||||
Labels: map[string]string{
|
||||
"type": "global",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
receiver := &v2beta1.Receiver{
|
||||
receiver := &v2beta2.Receiver{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Name: "receiver-foo",
|
||||
Labels: map[string]string{
|
||||
"type": "default",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
router := &v2beta2.Router{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "router-foo",
|
||||
},
|
||||
}
|
||||
|
||||
silence := &v2beta2.Silence{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "silence-foo",
|
||||
Labels: map[string]string{
|
||||
"type": "global",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
host := &v1alpha1.Cluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host",
|
||||
@@ -144,7 +159,7 @@ var (
|
||||
Expect(cl.Create(context.Background(), config)).Should(Succeed())
|
||||
Expect(r.reconcile(config)).Should(Succeed())
|
||||
|
||||
fedConfig := &v1beta1.FederatedNotificationConfig{}
|
||||
fedConfig := &v1beta2.FederatedNotificationConfig{}
|
||||
By("Expecting to create federated object successfully")
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: config.Name}, fedConfig)
|
||||
Expect(err).Should(Succeed())
|
||||
@@ -166,7 +181,7 @@ var (
|
||||
Expect(cl.Create(context.Background(), receiver)).Should(Succeed())
|
||||
Expect(r.reconcile(receiver)).Should(Succeed())
|
||||
|
||||
fedReceiver := &v1beta1.FederatedNotificationReceiver{}
|
||||
fedReceiver := &v1beta2.FederatedNotificationReceiver{}
|
||||
By("Expecting to create federated object successfully")
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: receiver.Name}, fedReceiver)
|
||||
Expect(err).Should(Succeed())
|
||||
@@ -185,6 +200,52 @@ var (
|
||||
Expect(err).Should(Succeed())
|
||||
Expect(fedReceiver.Spec.Template.Labels["foo"]).Should(Equal("bar"))
|
||||
|
||||
// Create a router
|
||||
Expect(cl.Create(context.Background(), router)).Should(Succeed())
|
||||
Expect(r.reconcile(router)).Should(Succeed())
|
||||
|
||||
fedRouter := &v1beta2.FederatedNotificationRouter{}
|
||||
By("Expecting to create federated object successfully")
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: router.Name}, fedRouter)
|
||||
Expect(err).Should(Succeed())
|
||||
Expect(fedRouter.Name).Should(Equal(router.Name))
|
||||
|
||||
// Update a receiver
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: router.Name}, router)
|
||||
Expect(err).Should(Succeed())
|
||||
router.Labels = map[string]string{"foo": "bar"}
|
||||
Expect(cl.Update(context.Background(), router)).Should(Succeed())
|
||||
Expect(r.reconcile(router)).Should(Succeed())
|
||||
|
||||
By("Expecting to update federated object successfully")
|
||||
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: router.Name}, fedRouter)
|
||||
Expect(err).Should(Succeed())
|
||||
Expect(fedRouter.Spec.Template.Labels["foo"]).Should(Equal("bar"))
|
||||
|
||||
// Create a receiver
|
||||
Expect(cl.Create(context.Background(), silence)).Should(Succeed())
|
||||
Expect(r.reconcile(silence)).Should(Succeed())
|
||||
|
||||
fedSilence := &v1beta2.FederatedNotificationSilence{}
|
||||
By("Expecting to create federated object successfully")
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: silence.Name}, fedSilence)
|
||||
Expect(err).Should(Succeed())
|
||||
Expect(fedSilence.Name).Should(Equal(silence.Name))
|
||||
|
||||
// Update a receiver
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: silence.Name}, silence)
|
||||
Expect(err).Should(Succeed())
|
||||
silence.Labels = map[string]string{"foo": "bar"}
|
||||
Expect(cl.Update(context.Background(), silence)).Should(Succeed())
|
||||
Expect(r.reconcile(silence)).Should(Succeed())
|
||||
|
||||
By("Expecting to update federated object successfully")
|
||||
|
||||
err = ksCache.Get(context.Background(), client.ObjectKey{Name: silence.Name}, fedSilence)
|
||||
Expect(err).Should(Succeed())
|
||||
Expect(fedSilence.Spec.Template.Labels["foo"]).Should(Equal("bar"))
|
||||
|
||||
// Add a cluster
|
||||
Expect(cl.Create(informerCacheCtx, host)).Should(Succeed())
|
||||
Expect(r.reconcile(secret)).Should(Succeed())
|
||||
@@ -220,24 +281,24 @@ type fakeCache struct {
|
||||
}
|
||||
|
||||
// GetInformerForKind returns the informer for the GroupVersionKind
|
||||
func (f *fakeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind) (cache.Informer, error) {
|
||||
func (f *fakeCache) GetInformerForKind(_ context.Context, _ schema.GroupVersionKind) (cache.Informer, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetInformer returns the informer for the obj
|
||||
func (f *fakeCache) GetInformer(ctx context.Context, obj client.Object) (cache.Informer, error) {
|
||||
func (f *fakeCache) GetInformer(_ context.Context, _ client.Object) (cache.Informer, error) {
|
||||
fakeInformerFactory := k8sinformers.NewSharedInformerFactory(f.K8sClient, defaultResync)
|
||||
return fakeInformerFactory.Core().V1().Namespaces().Informer(), nil
|
||||
}
|
||||
|
||||
func (f *fakeCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error {
|
||||
func (f *fakeCache) IndexField(_ context.Context, _ client.Object, _ string, _ client.IndexerFunc) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeCache) Start(ctx context.Context) error {
|
||||
func (f *fakeCache) Start(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeCache) WaitForCacheSync(ctx context.Context) bool {
|
||||
func (f *fakeCache) WaitForCacheSync(_ context.Context) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user