Integrate all receivers into one crd, and all configs into another crd

Signed-off-by: wanjunlei <wanjunlei@yunify.com>
This commit is contained in:
wanjunlei
2021-03-10 18:36:54 +08:00
parent d6d2cf002f
commit e3cf58e84b
130 changed files with 3980 additions and 13850 deletions

View File

@@ -23,22 +23,23 @@ import (
"kubesphere.io/kubesphere/pkg/apiserver/query"
ksinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
"strings"
)
type dingtalkConfigGetter struct {
type configGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewDingTalkConfigGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &dingtalkConfigGetter{ksInformer: informer}
func NewNotificationConfigGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &configGetter{ksInformer: informer}
}
func (g *dingtalkConfigGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().DingTalkConfigs().Lister().Get(name)
func (g *configGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2beta1().Configs().Lister().Get(name)
}
func (g *dingtalkConfigGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().DingTalkConfigs().Lister().List(query.Selector())
func (g *configGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2beta1().Configs().Lister().List(query.Selector())
if err != nil {
return nil, err
}
@@ -50,220 +51,20 @@ func (g *dingtalkConfigGetter) List(_ string, query *query.Query) (*api.ListResu
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type dingtalkReceiverGetter struct {
type receiverGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewDingTalkReceiverGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &dingtalkReceiverGetter{ksInformer: informer}
func NewNotificationReceiverGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &receiverGetter{ksInformer: informer}
}
func (g *dingtalkReceiverGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().DingTalkReceivers().Lister().Get(name)
func (g *receiverGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2beta1().Receivers().Lister().Get(name)
}
func (g *dingtalkReceiverGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().DingTalkReceivers().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type emailConfigGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewEmailConfigGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &emailConfigGetter{ksInformer: informer}
}
func (g *emailConfigGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().EmailConfigs().Lister().Get(name)
}
func (g *emailConfigGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().EmailConfigs().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type emailReceiverGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewEmailReceiverGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &emailReceiverGetter{ksInformer: informer}
}
func (g *emailReceiverGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().EmailReceivers().Lister().Get(name)
}
func (g *emailReceiverGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().EmailReceivers().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type slackConfigGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewSlackConfigGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &slackConfigGetter{ksInformer: informer}
}
func (g *slackConfigGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().SlackConfigs().Lister().Get(name)
}
func (g *slackConfigGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().SlackConfigs().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type slackReceiverGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewSlackReceiverGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &slackReceiverGetter{ksInformer: informer}
}
func (g *slackReceiverGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().SlackReceivers().Lister().Get(name)
}
func (g *slackReceiverGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().SlackReceivers().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type webhookConfigGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewWebhookConfigGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &webhookConfigGetter{ksInformer: informer}
}
func (g *webhookConfigGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().WebhookConfigs().Lister().Get(name)
}
func (g *webhookConfigGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().WebhookConfigs().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type webhookReceiverGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewWebhookReceiverGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &webhookReceiverGetter{ksInformer: informer}
}
func (g *webhookReceiverGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().WebhookReceivers().Lister().Get(name)
}
func (g *webhookReceiverGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().WebhookReceivers().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type wechatConfigGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewWechatConfigGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &wechatConfigGetter{ksInformer: informer}
}
func (g *wechatConfigGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().WechatConfigs().Lister().Get(name)
}
func (g *wechatConfigGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().WechatConfigs().Lister().List(query.Selector())
if err != nil {
return nil, err
}
var result []runtime.Object
for _, obj := range objs {
result = append(result, obj)
}
return v1alpha3.DefaultList(result, query, compare, filter), nil
}
type wechatReceiverGetter struct {
ksInformer ksinformers.SharedInformerFactory
}
func NewWechatReceiverGetter(informer ksinformers.SharedInformerFactory) v1alpha3.Interface {
return &wechatReceiverGetter{ksInformer: informer}
}
func (g *wechatReceiverGetter) Get(_, name string) (runtime.Object, error) {
return g.ksInformer.Notification().V2alpha1().WechatReceivers().Lister().Get(name)
}
func (g *wechatReceiverGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2alpha1().WechatReceivers().Lister().List(query.Selector())
func (g *receiverGetter) List(_ string, query *query.Query) (*api.ListResult, error) {
objs, err := g.ksInformer.Notification().V2beta1().Receivers().Lister().List(query.Selector())
if err != nil {
return nil, err
}
@@ -298,5 +99,17 @@ func filter(object runtime.Object, filter query.Filter) bool {
return false
}
return v1alpha3.DefaultObjectMetaFilter(meta.AsPartialObjectMetadata(accessor).ObjectMeta, filter)
switch filter.Field {
case query.FieldNames:
for _, name := range strings.Split(string(filter.Value), ",") {
if accessor.GetName() == name {
return true
}
}
return false
case query.FieldName:
return strings.Contains(accessor.GetName(), string(filter.Value))
default:
return true
}
}

View File

@@ -23,7 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apis/notification/v2alpha1"
"kubesphere.io/kubesphere/pkg/apis/notification/v2beta1"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/fake"
ksinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions"
@@ -47,43 +47,11 @@ func TestListObjects(t *testing.T) {
}{
{
"test name filter",
v2alpha1.ResourcesPluralDingTalkConfig,
v2beta1.ResourcesPluralConfig,
},
{
"test name filter",
v2alpha1.ResourcesPluralDingTalkReceiver,
},
{
"test name filter",
v2alpha1.ResourcesPluralEmailConfig,
},
{
"test name filter",
v2alpha1.ResourcesPluralEmailReceiver,
},
{
"test name filter",
v2alpha1.ResourcesPluralSlackConfig,
},
{
"test name filter",
v2alpha1.ResourcesPluralSlackReceiver,
},
{
"test name filter",
v2alpha1.ResourcesPluralWebhookConfig,
},
{
"test name filter",
v2alpha1.ResourcesPluralWebhookReceiver,
},
{
"test name filter",
v2alpha1.ResourcesPluralWechatConfig,
},
{
"test name filter",
v2alpha1.ResourcesPluralWechatReceiver,
v2beta1.ResourcesPluralReceiver,
},
}
@@ -128,46 +96,14 @@ func prepare(key string) (v1alpha3.Interface, []interface{}, error) {
var indexer cache.Indexer
var getter func(informer ksinformers.SharedInformerFactory) v1alpha3.Interface
switch key {
case v2alpha1.ResourcesPluralDingTalkConfig:
indexer = informer.Notification().V2alpha1().DingTalkConfigs().Informer().GetIndexer()
getter = NewDingTalkConfigGetter
obj = &v2alpha1.DingTalkConfig{}
case v2alpha1.ResourcesPluralDingTalkReceiver:
indexer = informer.Notification().V2alpha1().DingTalkReceivers().Informer().GetIndexer()
getter = NewDingTalkReceiverGetter
obj = &v2alpha1.DingTalkReceiver{}
case v2alpha1.ResourcesPluralEmailConfig:
indexer = informer.Notification().V2alpha1().EmailConfigs().Informer().GetIndexer()
getter = NewEmailConfigGetter
obj = &v2alpha1.EmailConfig{}
case v2alpha1.ResourcesPluralEmailReceiver:
indexer = informer.Notification().V2alpha1().EmailReceivers().Informer().GetIndexer()
getter = NewEmailReceiverGetter
obj = &v2alpha1.EmailReceiver{}
case v2alpha1.ResourcesPluralSlackConfig:
indexer = informer.Notification().V2alpha1().SlackConfigs().Informer().GetIndexer()
getter = NewSlackConfigGetter
obj = &v2alpha1.SlackConfig{}
case v2alpha1.ResourcesPluralSlackReceiver:
indexer = informer.Notification().V2alpha1().SlackReceivers().Informer().GetIndexer()
getter = NewSlackReceiverGetter
obj = &v2alpha1.SlackReceiver{}
case v2alpha1.ResourcesPluralWebhookConfig:
indexer = informer.Notification().V2alpha1().WebhookConfigs().Informer().GetIndexer()
getter = NewWebhookConfigGetter
obj = &v2alpha1.WebhookConfig{}
case v2alpha1.ResourcesPluralWebhookReceiver:
indexer = informer.Notification().V2alpha1().WebhookReceivers().Informer().GetIndexer()
getter = NewWebhookReceiverGetter
obj = &v2alpha1.WebhookReceiver{}
case v2alpha1.ResourcesPluralWechatConfig:
indexer = informer.Notification().V2alpha1().WechatConfigs().Informer().GetIndexer()
getter = NewWechatConfigGetter
obj = &v2alpha1.WechatConfig{}
case v2alpha1.ResourcesPluralWechatReceiver:
indexer = informer.Notification().V2alpha1().WechatReceivers().Informer().GetIndexer()
getter = NewWechatReceiverGetter
obj = &v2alpha1.WechatReceiver{}
case v2beta1.ResourcesPluralConfig:
indexer = informer.Notification().V2beta1().Configs().Informer().GetIndexer()
getter = NewNotificationConfigGetter
obj = &v2beta1.Config{}
case v2beta1.ResourcesPluralReceiver:
indexer = informer.Notification().V2beta1().Receivers().Informer().GetIndexer()
getter = NewNotificationReceiverGetter
obj = &v2beta1.Receiver{}
default:
return nil, nil, errors.New("unowned type %s", key)
}

View File

@@ -26,7 +26,7 @@ import (
devopsv1alpha3 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
iamv1alpha2 "kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
networkv1alpha1 "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1"
notificationv2alpha1 "kubesphere.io/kubesphere/pkg/apis/notification/v2alpha1"
notificationv2beta1 "kubesphere.io/kubesphere/pkg/apis/notification/v2beta1"
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
tenantv1alpha2 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha2"
typesv1beta1 "kubesphere.io/kubesphere/pkg/apis/types/v1beta1"
@@ -126,16 +126,8 @@ func NewResourceGetter(factory informers.InformerFactory, cache cache.Cache) *Re
getters[schema.GroupVersionResource{Group: "cluster.kubesphere.io", Version: "v1alpha1", Resource: "clusters"}] = cluster.New(factory.KubeSphereSharedInformerFactory())
getters[schema.GroupVersionResource{Group: "apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions"}] = customresourcedefinition.New(factory.ApiExtensionSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralDingTalkConfig)] = notification.NewDingTalkConfigGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralDingTalkReceiver)] = notification.NewDingTalkReceiverGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralEmailConfig)] = notification.NewEmailConfigGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralEmailReceiver)] = notification.NewEmailReceiverGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralSlackConfig)] = notification.NewSlackConfigGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralSlackReceiver)] = notification.NewSlackReceiverGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralWebhookConfig)] = notification.NewWebhookConfigGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralWebhookReceiver)] = notification.NewWebhookReceiverGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralWechatConfig)] = notification.NewWechatConfigGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2alpha1.SchemeGroupVersion.WithResource(notificationv2alpha1.ResourcesPluralWechatReceiver)] = notification.NewWechatReceiverGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2beta1.SchemeGroupVersion.WithResource(notificationv2beta1.ResourcesPluralConfig)] = notification.NewNotificationConfigGetter(factory.KubeSphereSharedInformerFactory())
getters[notificationv2beta1.SchemeGroupVersion.WithResource(notificationv2beta1.ResourcesPluralReceiver)] = notification.NewNotificationReceiverGetter(factory.KubeSphereSharedInformerFactory())
// federated resources
getters[typesv1beta1.SchemeGroupVersion.WithResource(typesv1beta1.ResourcePluralFederatedNamespace)] = federatednamespace.New(factory.KubeSphereSharedInformerFactory())