提交 d4a8f9bf 编写于 作者: W wanjunlei

resolve conversation

Signed-off-by: Nwanjunlei <wanjunlei@yunify.com>
上级 f9213fcd
...@@ -40,6 +40,7 @@ type DingTalkConfigStatus struct { ...@@ -40,6 +40,7 @@ type DingTalkConfigStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=dc // +kubebuilder:resource:scope=Cluster,shortName=dc
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// DingTalkConfig is the Schema for the dingtalkconfigs API // DingTalkConfig is the Schema for the dingtalkconfigs API
......
...@@ -55,6 +55,7 @@ type DingTalkReceiverStatus struct { ...@@ -55,6 +55,7 @@ type DingTalkReceiverStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=dr // +kubebuilder:resource:scope=Cluster,shortName=dr
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// DingTalkReceiver is the Schema for the dingtalkreceivers API // DingTalkReceiver is the Schema for the dingtalkreceivers API
......
...@@ -52,6 +52,7 @@ type EmailConfigStatus struct { ...@@ -52,6 +52,7 @@ type EmailConfigStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=ec // +kubebuilder:resource:scope=Cluster,shortName=ec
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// EmailConfig is the Schema for the emailconfigs API // EmailConfig is the Schema for the emailconfigs API
......
...@@ -36,6 +36,7 @@ type EmailReceiverStatus struct { ...@@ -36,6 +36,7 @@ type EmailReceiverStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=er // +kubebuilder:resource:scope=Cluster,shortName=er
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// EmailReceiver is the Schema for the emailreceivers API // EmailReceiver is the Schema for the emailreceivers API
......
...@@ -186,6 +186,7 @@ type NotificationManagerStatus struct { ...@@ -186,6 +186,7 @@ type NotificationManagerStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=nm // +kubebuilder:resource:scope=Cluster,shortName=nm
// +kubebuilder:subresource:status
// NotificationManager is the Schema for the notificationmanagers API // NotificationManager is the Schema for the notificationmanagers API
type NotificationManager struct { type NotificationManager struct {
......
...@@ -32,6 +32,7 @@ type SlackConfigStatus struct { ...@@ -32,6 +32,7 @@ type SlackConfigStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=sc // +kubebuilder:resource:scope=Cluster,shortName=sc
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// SlackConfig is the Schema for the slackconfigs API // SlackConfig is the Schema for the slackconfigs API
......
...@@ -36,6 +36,7 @@ type SlackReceiverStatus struct { ...@@ -36,6 +36,7 @@ type SlackReceiverStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=sr // +kubebuilder:resource:scope=Cluster,shortName=sr
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// SlackReceiver is the Schema for the slackreceivers API // SlackReceiver is the Schema for the slackreceivers API
......
...@@ -30,6 +30,7 @@ type WebhookConfigStatus struct { ...@@ -30,6 +30,7 @@ type WebhookConfigStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wc // +kubebuilder:resource:scope=Cluster,shortName=wc
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// WebhookConfig is the Schema for the webhookconfigs API // WebhookConfig is the Schema for the webhookconfigs API
......
...@@ -134,6 +134,7 @@ type WebhookReceiverStatus struct { ...@@ -134,6 +134,7 @@ type WebhookReceiverStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wr // +kubebuilder:resource:scope=Cluster,shortName=wr
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// WebhookReceiver is the Schema for the webhookreceivers API // WebhookReceiver is the Schema for the webhookreceivers API
......
...@@ -38,6 +38,7 @@ type WechatConfigStatus struct { ...@@ -38,6 +38,7 @@ type WechatConfigStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wcc // +kubebuilder:resource:scope=Cluster,shortName=wcc
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// WechatConfig is the Schema for the wechatconfigs API // WechatConfig is the Schema for the wechatconfigs API
......
...@@ -38,6 +38,7 @@ type WechatReceiverStatus struct { ...@@ -38,6 +38,7 @@ type WechatReceiverStatus struct {
// +kubebuilder:object:root=true // +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,shortName=wcr // +kubebuilder:resource:scope=Cluster,shortName=wcr
// +kubebuilder:subresource:status
// +genclient // +genclient
// +genclient:nonNamespaced // +genclient:nonNamespaced
// WechatReceiver is the Schema for the wechatreceivers API // WechatReceiver is the Schema for the wechatreceivers API
......
...@@ -126,9 +126,9 @@ const ( ...@@ -126,9 +126,9 @@ const (
ApplicationVersion = "app.kubernetes.io/version" ApplicationVersion = "app.kubernetes.io/version"
AlertingTag = "Alerting" AlertingTag = "Alerting"
NotificationTag = "Notification" NotificationTag = "Notification"
KubeSphereNotificationNamespace = "kubesphere-notification-system" NotificationSecretNamespace = "kubesphere-monitoring-federated"
NotificationManagedLabel = "notification-manager/managed" NotificationManagedLabel = "notification-manager/managed"
) )
var ( var (
......
...@@ -222,7 +222,7 @@ func (c *Controller) reconcile(obj interface{}) error { ...@@ -222,7 +222,7 @@ func (c *Controller) reconcile(obj interface{}) error {
// Only reconcile the secret which created by notification manager. // Only reconcile the secret which created by notification manager.
if secret, ok := obj.(*corev1.Secret); ok { if secret, ok := obj.(*corev1.Secret); ok {
if secret.Namespace != constants.KubeSphereNotificationNamespace || secret.Labels[constants.NotificationManagedLabel] != "true" { if secret.Namespace != constants.NotificationSecretNamespace || secret.Labels[constants.NotificationManagedLabel] != "true" {
klog.V(8).Infof("No need to reconcile secret %s/%s", accessor.GetNamespace(), accessor.GetName()) klog.V(8).Infof("No need to reconcile secret %s/%s", accessor.GetNamespace(), accessor.GetName())
return nil return nil
} }
...@@ -919,12 +919,12 @@ func (c *Controller) syncFederatedSecret(obj *corev1.Secret) error { ...@@ -919,12 +919,12 @@ func (c *Controller) syncFederatedSecret(obj *corev1.Secret) error {
func (c *Controller) ensureNotificationNamespaceExist() error { func (c *Controller) ensureNotificationNamespaceExist() error {
ns := corev1.Namespace{} ns := corev1.Namespace{}
if err := c.Get(context.Background(), client.ObjectKey{Name: constants.KubeSphereNotificationNamespace}, &ns); err != nil { if err := c.Get(context.Background(), client.ObjectKey{Name: constants.NotificationSecretNamespace}, &ns); err != nil {
return err return err
} }
fedNs := v1beta1.FederatedNamespace{} fedNs := v1beta1.FederatedNamespace{}
if err := c.Get(context.Background(), client.ObjectKey{Name: constants.KubeSphereNotificationNamespace, Namespace: constants.KubeSphereNotificationNamespace}, &fedNs); err != nil { if err := c.Get(context.Background(), client.ObjectKey{Name: constants.NotificationSecretNamespace, Namespace: constants.NotificationSecretNamespace}, &fedNs); err != nil {
if errors.IsAlreadyExists(err) { if errors.IsAlreadyExists(err) {
return nil return nil
} }
...@@ -936,8 +936,8 @@ func (c *Controller) ensureNotificationNamespaceExist() error { ...@@ -936,8 +936,8 @@ func (c *Controller) ensureNotificationNamespaceExist() error {
APIVersion: v1beta1.SchemeGroupVersion.String(), APIVersion: v1beta1.SchemeGroupVersion.String(),
}, },
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: constants.KubeSphereNotificationNamespace, Name: constants.NotificationSecretNamespace,
Namespace: constants.KubeSphereNotificationNamespace, Namespace: constants.NotificationSecretNamespace,
}, },
Spec: v1beta1.FederatedNamespaceSpec{ Spec: v1beta1.FederatedNamespaceSpec{
Placement: v1beta1.GenericPlacementFields{ Placement: v1beta1.GenericPlacementFields{
......
...@@ -39,14 +39,14 @@ var ( ...@@ -39,14 +39,14 @@ var (
namespace := &corev1.Namespace{ namespace := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: constants.KubeSphereNotificationNamespace, Name: constants.NotificationSecretNamespace,
}, },
} }
secret := &corev1.Secret{ secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "foo", Name: "foo",
Namespace: constants.KubeSphereNotificationNamespace, Namespace: constants.NotificationSecretNamespace,
Labels: map[string]string{constants.NotificationManagedLabel: "true"}, Labels: map[string]string{constants.NotificationManagedLabel: "true"},
}, },
} }
...@@ -101,12 +101,12 @@ var ( ...@@ -101,12 +101,12 @@ var (
fedSecret := &v1beta1.FederatedSecret{} fedSecret := &v1beta1.FederatedSecret{}
By("Expecting to create federated secret successfully") By("Expecting to create federated secret successfully")
Eventually(func() bool { Eventually(func() bool {
err := ksCache.Get(context.Background(), client.ObjectKey{Name: secret.Name, Namespace: constants.KubeSphereNotificationNamespace}, fedSecret) err := ksCache.Get(context.Background(), client.ObjectKey{Name: secret.Name, Namespace: constants.NotificationSecretNamespace}, fedSecret)
Expect(err).Should(Succeed()) Expect(err).Should(Succeed())
return !fedSecret.CreationTimestamp.IsZero() return !fedSecret.CreationTimestamp.IsZero()
}, timeout, interval).Should(BeTrue()) }, timeout, interval).Should(BeTrue())
err := ksCache.Get(context.Background(), client.ObjectKey{Name: secret.Name, Namespace: constants.KubeSphereNotificationNamespace}, secret) err := ksCache.Get(context.Background(), client.ObjectKey{Name: secret.Name, Namespace: constants.NotificationSecretNamespace}, secret)
Expect(err).Should(Succeed()) Expect(err).Should(Succeed())
secret.StringData = map[string]string{"foo": "bar"} secret.StringData = map[string]string{"foo": "bar"}
Expect(cl.Update(context.Background(), secret)).Should(Succeed()) Expect(cl.Update(context.Background(), secret)).Should(Succeed())
...@@ -114,7 +114,7 @@ var ( ...@@ -114,7 +114,7 @@ var (
By("Expecting to update federated secret successfully") By("Expecting to update federated secret successfully")
Eventually(func() bool { Eventually(func() bool {
err := ksCache.Get(context.Background(), client.ObjectKey{Name: secret.Name, Namespace: constants.KubeSphereNotificationNamespace}, fedSecret) err := ksCache.Get(context.Background(), client.ObjectKey{Name: secret.Name, Namespace: constants.NotificationSecretNamespace}, fedSecret)
Expect(err).Should(Succeed()) Expect(err).Should(Succeed())
return string(fedSecret.Spec.Template.Data["foo"]) == "bar" return string(fedSecret.Spec.Template.Data["foo"]) == "bar"
}, timeout, interval).Should(BeTrue()) }, timeout, interval).Should(BeTrue())
...@@ -130,9 +130,9 @@ var ( ...@@ -130,9 +130,9 @@ var (
obj := &v2.DingTalkConfig{ obj := &v2.DingTalkConfig{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "foo", Name: "foo",
Namespace: constants.KubeSphereNotificationNamespace, Namespace: constants.NotificationSecretNamespace,
Labels: map[string]string{ Labels: map[string]string{
"tyep": "default", "type": "default",
}, },
}, },
} }
......
...@@ -55,8 +55,8 @@ func AddToContainer( ...@@ -55,8 +55,8 @@ func AddToContainer(
To(h.ListSecret). To(h.ListSecret).
Doc("list the secrets"). Doc("list the secrets").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)). Param(ws.QueryParameter(query.ParameterName, "name used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used to do filtering").Required(false)). Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")). Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")).
Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)). Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)).
Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")). Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")).
...@@ -93,11 +93,11 @@ func AddToContainer( ...@@ -93,11 +93,11 @@ func AddToContainer(
// apis for global notification config and receiver // apis for global notification config and receiver
ws.Route(ws.GET("/{resources}"). ws.Route(ws.GET("/{resources}").
To(h.ListResource). To(h.ListResource).
Doc("list the notification config or receiver"). Doc("list the notification configs or receivers").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resources", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)). Param(ws.QueryParameter(query.ParameterName, "name used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used to do filtering").Required(false)). Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")). Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")).
Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)). Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)).
Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")). Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")).
...@@ -108,7 +108,7 @@ func AddToContainer( ...@@ -108,7 +108,7 @@ func AddToContainer(
To(h.GetResource). To(h.GetResource).
Doc("get the specified notification config or receiver"). Doc("get the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resources", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.PathParameter("name", "the name of the resource")). Param(ws.PathParameter("name", "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, nil)) Returns(http.StatusOK, api.StatusOK, nil))
...@@ -116,14 +116,14 @@ func AddToContainer( ...@@ -116,14 +116,14 @@ func AddToContainer(
To(h.CreateResource). To(h.CreateResource).
Doc("create a notification config or receiver"). Doc("create a notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resource", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resource", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Returns(http.StatusOK, api.StatusOK, nil)) Returns(http.StatusOK, api.StatusOK, nil))
ws.Route(ws.PUT("/{resources}/{name}"). ws.Route(ws.PUT("/{resources}/{name}").
To(h.UpdateResource). To(h.UpdateResource).
Doc("update the specified notification config or receiver"). Doc("update the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resources", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.PathParameter("name", "the name of the resource")). Param(ws.PathParameter("name", "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, nil)) Returns(http.StatusOK, api.StatusOK, nil))
...@@ -131,18 +131,19 @@ func AddToContainer( ...@@ -131,18 +131,19 @@ func AddToContainer(
To(h.DeleteResource). To(h.DeleteResource).
Doc("delete the specified notification config or receiver"). Doc("delete the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("resources", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resources", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.PathParameter("name", "the name of the resource")). Param(ws.PathParameter("name", "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, errors.None)) Returns(http.StatusOK, api.StatusOK, errors.None))
// apis for tenant notification config and receiver // apis for tenant notification config and receiver
ws.Route(ws.GET("/users/{user}/{resources}"). ws.Route(ws.GET("/users/{user}/{resources}").
To(h.ListResource). To(h.ListResource).
Doc("list the notification config or receiver"). Doc("list the notification configs or receivers").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")). Param(ws.PathParameter("user", "user name")).
Param(ws.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)). Param(ws.PathParameter("resources", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used to do filtering").Required(false)). Param(ws.QueryParameter(query.ParameterName, "name used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector used for filtering").Required(false)).
Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")). Param(ws.QueryParameter(query.ParameterPage, "page").Required(false).DataFormat("page=%d").DefaultValue("page=1")).
Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)). Param(ws.QueryParameter(query.ParameterLimit, "limit").Required(false)).
Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")). Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")).
...@@ -154,7 +155,7 @@ func AddToContainer( ...@@ -154,7 +155,7 @@ func AddToContainer(
Doc("get the specified notification config or receiver"). Doc("get the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")). Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resources", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.PathParameter("name", "the name of the resource")). Param(ws.PathParameter("name", "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, nil)) Returns(http.StatusOK, api.StatusOK, nil))
...@@ -170,7 +171,7 @@ func AddToContainer( ...@@ -170,7 +171,7 @@ func AddToContainer(
Doc("update the specified notification config or receiver"). Doc("update the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")). Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resources", "notification configs or receivers, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.PathParameter("name", "the name of the resource")). Param(ws.PathParameter("name", "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, nil)) Returns(http.StatusOK, api.StatusOK, nil))
...@@ -179,7 +180,7 @@ func AddToContainer( ...@@ -179,7 +180,7 @@ func AddToContainer(
Doc("delete the specified notification config or receiver"). Doc("delete the specified notification config or receiver").
Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}).
Param(ws.PathParameter("user", "user name")). Param(ws.PathParameter("user", "user name")).
Param(ws.PathParameter("resources", "notification config or receiver, known values are dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")). Param(ws.PathParameter("resources", "notification config or receiver, known values include dingtalkconfigs, dingtalkreceivers, emailconfigs. emailreceivers, slackconfigs, slackreceivers, webhookconfigs, webhookreceivers, wechatconfigs, wechatreceivers")).
Param(ws.PathParameter("name", "the name of the resource")). Param(ws.PathParameter("name", "the name of the resource")).
Returns(http.StatusOK, api.StatusOK, errors.None)) Returns(http.StatusOK, api.StatusOK, errors.None))
......
...@@ -55,9 +55,8 @@ func NewOperator( ...@@ -55,9 +55,8 @@ func NewOperator(
} }
} }
// List objects, if the user is nil, it will return the global object. // List objects. Only global objects will be returned if the user is nil.
// If the user it not nil, it will return tenant object which the tenant specified in the labels of object // If the user is not nil, only tenant objects whose tenant label matches the user will be returned.
// equal to this user.
func (o *operator) List(user, resource string, q *query.Query) (*api.ListResult, error) { func (o *operator) List(user, resource string, q *query.Query) (*api.ListResult, error) {
// If user is nil, it will list all global object. // If user is nil, it will list all global object.
...@@ -86,8 +85,8 @@ func (o *operator) Get(user, resource, name string) (runtime.Object, error) { ...@@ -86,8 +85,8 @@ func (o *operator) Get(user, resource, name string) (runtime.Object, error) {
return obj, nil return obj, nil
} }
// Create a object, if the user is nil, it only can create a global object. // Create an object. A global object will be created if the user is nil.
// If the user is not nil, it only can create a tenant object. // A tenant object will be created if the user is not nil.
func (o *operator) Create(user, resource string, obj runtime.Object) (runtime.Object, error) { func (o *operator) Create(user, resource string, obj runtime.Object) (runtime.Object, error) {
if err := authorizer(user, obj); err != nil { if err := authorizer(user, obj); err != nil {
...@@ -120,9 +119,8 @@ func (o *operator) Create(user, resource string, obj runtime.Object) (runtime.Ob ...@@ -120,9 +119,8 @@ func (o *operator) Create(user, resource string, obj runtime.Object) (runtime.Ob
} }
} }
// Delete a object, if the user is nil, it only can delete the global object. // Delete an object. A global object will be deleted if the user is nil.
// If the user is not nil, it only can delete the tenant object which the tenant // If the user is not nil, a tenant object whose tenant label matches the user will be deleted.
// specified in the labels of the object equal to this user.
func (o *operator) Delete(user, resource, name string) error { func (o *operator) Delete(user, resource, name string) error {
if obj, err := o.Get(user, resource, name); err != nil { if obj, err := o.Get(user, resource, name); err != nil {
...@@ -159,9 +157,8 @@ func (o *operator) Delete(user, resource, name string) error { ...@@ -159,9 +157,8 @@ func (o *operator) Delete(user, resource, name string) error {
} }
} }
// Update a object, if the user is nil, it only can update the global object. // Update an object, only a global object will be updated if the user is nil.
// If the user is not nil, it only can delete the tenant object which the tenant // If the user is not nil, a tenant object whose tenant label matches the user will be updated.
// specified in the labels of the object equal to this user.
func (o *operator) Update(user, resource string, obj runtime.Object) (runtime.Object, error) { func (o *operator) Update(user, resource string, obj runtime.Object) (runtime.Object, error) {
name, err := getName(obj) name, err := getName(obj)
...@@ -206,11 +203,11 @@ func (o *operator) Update(user, resource string, obj runtime.Object) (runtime.Ob ...@@ -206,11 +203,11 @@ func (o *operator) Update(user, resource string, obj runtime.Object) (runtime.Ob
func (o *operator) ListSecret(q *query.Query) (*api.ListResult, error) { func (o *operator) ListSecret(q *query.Query) (*api.ListResult, error) {
appendManagedLabel(q) appendManagedLabel(q)
return o.resourceGetter.List("secrets", constants.KubeSphereNotificationNamespace, q) return o.resourceGetter.List("secrets", constants.NotificationSecretNamespace, q)
} }
func (o *operator) GetSecret(name string) (interface{}, error) { func (o *operator) GetSecret(name string) (interface{}, error) {
obj, err := o.resourceGetter.Get("secrets", constants.KubeSphereNotificationNamespace, name) obj, err := o.resourceGetter.Get("secrets", constants.NotificationSecretNamespace, name)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -225,15 +222,15 @@ func (o *operator) GetSecret(name string) (interface{}, error) { ...@@ -225,15 +222,15 @@ func (o *operator) GetSecret(name string) (interface{}, error) {
func (o *operator) CreateOrUpdateSecret(obj *corev1.Secret) (*corev1.Secret, error) { func (o *operator) CreateOrUpdateSecret(obj *corev1.Secret) (*corev1.Secret, error) {
obj.Namespace = constants.KubeSphereNotificationNamespace obj.Namespace = constants.NotificationSecretNamespace
if obj.Labels == nil { if obj.Labels == nil {
obj.Labels = make(map[string]string) obj.Labels = make(map[string]string)
} }
obj.Labels[constants.NotificationManagedLabel] = "true" obj.Labels[constants.NotificationManagedLabel] = "true"
if obj.ResourceVersion == "" { if obj.ResourceVersion == "" {
return o.k8sClient.CoreV1().Secrets(constants.KubeSphereNotificationNamespace).Create(context.Background(), obj, v1.CreateOptions{}) return o.k8sClient.CoreV1().Secrets(constants.NotificationSecretNamespace).Create(context.Background(), obj, v1.CreateOptions{})
} else { } else {
return o.k8sClient.CoreV1().Secrets(constants.KubeSphereNotificationNamespace).Update(context.Background(), obj, v1.UpdateOptions{}) return o.k8sClient.CoreV1().Secrets(constants.NotificationSecretNamespace).Update(context.Background(), obj, v1.UpdateOptions{})
} }
} }
...@@ -243,7 +240,7 @@ func (o *operator) DeleteSecret(name string) error { ...@@ -243,7 +240,7 @@ func (o *operator) DeleteSecret(name string) error {
return err return err
} }
return o.k8sClient.CoreV1().Secrets(constants.KubeSphereNotificationNamespace).Delete(context.Background(), name, v1.DeleteOptions{}) return o.k8sClient.CoreV1().Secrets(constants.NotificationSecretNamespace).Delete(context.Background(), name, v1.DeleteOptions{})
} }
func (o *operator) GetObject(resource string) runtime.Object { func (o *operator) GetObject(resource string) runtime.Object {
......
...@@ -109,7 +109,7 @@ func TestOperator_CreateOrUpdateSecret(t *testing.T) { ...@@ -109,7 +109,7 @@ func TestOperator_CreateOrUpdateSecret(t *testing.T) {
result: &corev1.Secret{ result: &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "test", Name: "test",
Namespace: constants.KubeSphereNotificationNamespace, Namespace: constants.NotificationSecretNamespace,
Labels: map[string]string{constants.NotificationManagedLabel: "true"}, Labels: map[string]string{constants.NotificationManagedLabel: "true"},
}, },
}, },
...@@ -168,7 +168,7 @@ var ( ...@@ -168,7 +168,7 @@ var (
secret1 = &corev1.Secret{ secret1 = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "foo1", Name: "foo1",
Namespace: constants.KubeSphereNotificationNamespace, Namespace: constants.NotificationSecretNamespace,
Labels: map[string]string{constants.NotificationManagedLabel: "true"}, Labels: map[string]string{constants.NotificationManagedLabel: "true"},
}, },
} }
...@@ -176,7 +176,7 @@ var ( ...@@ -176,7 +176,7 @@ var (
secret2 = &corev1.Secret{ secret2 = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "foo2", Name: "foo2",
Namespace: constants.KubeSphereNotificationNamespace, Namespace: constants.NotificationSecretNamespace,
Labels: map[string]string{constants.NotificationManagedLabel: "true"}, Labels: map[string]string{constants.NotificationManagedLabel: "true"},
}, },
} }
...@@ -184,7 +184,7 @@ var ( ...@@ -184,7 +184,7 @@ var (
secret3 = &corev1.Secret{ secret3 = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "foo3", Name: "foo3",
Namespace: constants.KubeSphereNotificationNamespace, Namespace: constants.NotificationSecretNamespace,
Labels: map[string]string{constants.NotificationManagedLabel: "true"}, Labels: map[string]string{constants.NotificationManagedLabel: "true"},
}, },
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册