diff --git a/pkg/apis/notification/v2/dingtalkconfig_types.go b/pkg/apis/notification/v2/dingtalkconfig_types.go index cd630c158..615468b54 100644 --- a/pkg/apis/notification/v2/dingtalkconfig_types.go +++ b/pkg/apis/notification/v2/dingtalkconfig_types.go @@ -40,6 +40,7 @@ type DingTalkConfigStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=dc +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // DingTalkConfig is the Schema for the dingtalkconfigs API diff --git a/pkg/apis/notification/v2/dingtalkreceiver_types.go b/pkg/apis/notification/v2/dingtalkreceiver_types.go index 9bc52095d..9e2696ccb 100644 --- a/pkg/apis/notification/v2/dingtalkreceiver_types.go +++ b/pkg/apis/notification/v2/dingtalkreceiver_types.go @@ -55,6 +55,7 @@ type DingTalkReceiverStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=dr +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // DingTalkReceiver is the Schema for the dingtalkreceivers API diff --git a/pkg/apis/notification/v2/emailconfig_types.go b/pkg/apis/notification/v2/emailconfig_types.go index b4035f8ad..fba4529f9 100644 --- a/pkg/apis/notification/v2/emailconfig_types.go +++ b/pkg/apis/notification/v2/emailconfig_types.go @@ -52,6 +52,7 @@ type EmailConfigStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=ec +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // EmailConfig is the Schema for the emailconfigs API diff --git a/pkg/apis/notification/v2/emailreceiver_types.go b/pkg/apis/notification/v2/emailreceiver_types.go index 497aac34c..9bf31ac5b 100644 --- a/pkg/apis/notification/v2/emailreceiver_types.go +++ b/pkg/apis/notification/v2/emailreceiver_types.go @@ -36,6 +36,7 @@ type EmailReceiverStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=er +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // EmailReceiver is the Schema for the emailreceivers API diff --git a/pkg/apis/notification/v2/notificationmanager_types.go b/pkg/apis/notification/v2/notificationmanager_types.go index 4deb6a736..5af543fc6 100644 --- a/pkg/apis/notification/v2/notificationmanager_types.go +++ b/pkg/apis/notification/v2/notificationmanager_types.go @@ -186,6 +186,7 @@ type NotificationManagerStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=nm +// +kubebuilder:subresource:status // NotificationManager is the Schema for the notificationmanagers API type NotificationManager struct { diff --git a/pkg/apis/notification/v2/slackconfig_types.go b/pkg/apis/notification/v2/slackconfig_types.go index 05e7f670a..eb1b75619 100644 --- a/pkg/apis/notification/v2/slackconfig_types.go +++ b/pkg/apis/notification/v2/slackconfig_types.go @@ -32,6 +32,7 @@ type SlackConfigStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=sc +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // SlackConfig is the Schema for the slackconfigs API diff --git a/pkg/apis/notification/v2/slackreceiver_types.go b/pkg/apis/notification/v2/slackreceiver_types.go index 61a5f3e68..bbe78d73f 100644 --- a/pkg/apis/notification/v2/slackreceiver_types.go +++ b/pkg/apis/notification/v2/slackreceiver_types.go @@ -36,6 +36,7 @@ type SlackReceiverStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=sr +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // SlackReceiver is the Schema for the slackreceivers API diff --git a/pkg/apis/notification/v2/webhookconfig_types.go b/pkg/apis/notification/v2/webhookconfig_types.go index 0670cdcf8..d79f519da 100644 --- a/pkg/apis/notification/v2/webhookconfig_types.go +++ b/pkg/apis/notification/v2/webhookconfig_types.go @@ -30,6 +30,7 @@ type WebhookConfigStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=wc +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // WebhookConfig is the Schema for the webhookconfigs API diff --git a/pkg/apis/notification/v2/webhookreceiver_types.go b/pkg/apis/notification/v2/webhookreceiver_types.go index 12f6eb206..19e27b423 100644 --- a/pkg/apis/notification/v2/webhookreceiver_types.go +++ b/pkg/apis/notification/v2/webhookreceiver_types.go @@ -134,6 +134,7 @@ type WebhookReceiverStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=wr +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // WebhookReceiver is the Schema for the webhookreceivers API diff --git a/pkg/apis/notification/v2/wechatconfig_types.go b/pkg/apis/notification/v2/wechatconfig_types.go index 5a6eb6f1f..60bb31ce8 100644 --- a/pkg/apis/notification/v2/wechatconfig_types.go +++ b/pkg/apis/notification/v2/wechatconfig_types.go @@ -38,6 +38,7 @@ type WechatConfigStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=wcc +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // WechatConfig is the Schema for the wechatconfigs API diff --git a/pkg/apis/notification/v2/wechatreceiver_types.go b/pkg/apis/notification/v2/wechatreceiver_types.go index 99198460e..916c0b912 100644 --- a/pkg/apis/notification/v2/wechatreceiver_types.go +++ b/pkg/apis/notification/v2/wechatreceiver_types.go @@ -38,6 +38,7 @@ type WechatReceiverStatus struct { // +kubebuilder:object:root=true // +kubebuilder:resource:scope=Cluster,shortName=wcr +// +kubebuilder:subresource:status // +genclient // +genclient:nonNamespaced // WechatReceiver is the Schema for the wechatreceivers API diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 70affdf96..900093628 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -126,9 +126,9 @@ const ( ApplicationVersion = "app.kubernetes.io/version" AlertingTag = "Alerting" - NotificationTag = "Notification" - KubeSphereNotificationNamespace = "kubesphere-notification-system" - NotificationManagedLabel = "notification-manager/managed" + NotificationTag = "Notification" + NotificationSecretNamespace = "kubesphere-monitoring-federated" + NotificationManagedLabel = "notification-manager/managed" ) var ( diff --git a/pkg/controller/notification/notification_controller.go b/pkg/controller/notification/notification_controller.go index 34d6e5ad3..403189ca6 100644 --- a/pkg/controller/notification/notification_controller.go +++ b/pkg/controller/notification/notification_controller.go @@ -222,7 +222,7 @@ func (c *Controller) reconcile(obj interface{}) error { // Only reconcile the secret which created by notification manager. 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()) return nil } @@ -919,12 +919,12 @@ func (c *Controller) syncFederatedSecret(obj *corev1.Secret) error { func (c *Controller) ensureNotificationNamespaceExist() error { 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 } 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) { return nil } @@ -936,8 +936,8 @@ func (c *Controller) ensureNotificationNamespaceExist() error { APIVersion: v1beta1.SchemeGroupVersion.String(), }, ObjectMeta: metav1.ObjectMeta{ - Name: constants.KubeSphereNotificationNamespace, - Namespace: constants.KubeSphereNotificationNamespace, + Name: constants.NotificationSecretNamespace, + Namespace: constants.NotificationSecretNamespace, }, Spec: v1beta1.FederatedNamespaceSpec{ Placement: v1beta1.GenericPlacementFields{ diff --git a/pkg/controller/notification/notification_controller_test.go b/pkg/controller/notification/notification_controller_test.go index ef2f0fd23..64b4e3882 100644 --- a/pkg/controller/notification/notification_controller_test.go +++ b/pkg/controller/notification/notification_controller_test.go @@ -39,14 +39,14 @@ var ( namespace := &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ - Name: constants.KubeSphereNotificationNamespace, + Name: constants.NotificationSecretNamespace, }, } secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", - Namespace: constants.KubeSphereNotificationNamespace, + Namespace: constants.NotificationSecretNamespace, Labels: map[string]string{constants.NotificationManagedLabel: "true"}, }, } @@ -101,12 +101,12 @@ var ( fedSecret := &v1beta1.FederatedSecret{} By("Expecting to create federated secret successfully") 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()) return !fedSecret.CreationTimestamp.IsZero() }, 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()) secret.StringData = map[string]string{"foo": "bar"} Expect(cl.Update(context.Background(), secret)).Should(Succeed()) @@ -114,7 +114,7 @@ var ( By("Expecting to update federated secret successfully") 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()) return string(fedSecret.Spec.Template.Data["foo"]) == "bar" }, timeout, interval).Should(BeTrue()) @@ -130,9 +130,9 @@ var ( obj := &v2.DingTalkConfig{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", - Namespace: constants.KubeSphereNotificationNamespace, + Namespace: constants.NotificationSecretNamespace, Labels: map[string]string{ - "tyep": "default", + "type": "default", }, }, } diff --git a/pkg/kapis/notification/v2/register.go b/pkg/kapis/notification/v2/register.go index abd62d142..07ddf65ee 100644 --- a/pkg/kapis/notification/v2/register.go +++ b/pkg/kapis/notification/v2/register.go @@ -55,8 +55,8 @@ func AddToContainer( To(h.ListSecret). Doc("list the secrets"). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). - Param(ws.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)). - 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.ParameterLimit, "limit").Required(false)). Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")). @@ -93,11 +93,11 @@ func AddToContainer( // apis for global notification config and receiver ws.Route(ws.GET("/{resources}"). To(h.ListResource). - Doc("list the notification config or receiver"). + Doc("list the notification configs or receivers"). 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.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)). - Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector 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.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.ParameterLimit, "limit").Required(false)). Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")). @@ -108,7 +108,7 @@ func AddToContainer( To(h.GetResource). Doc("get the specified notification config or receiver"). 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")). Returns(http.StatusOK, api.StatusOK, nil)) @@ -116,14 +116,14 @@ func AddToContainer( To(h.CreateResource). Doc("create a notification config or receiver"). 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)) ws.Route(ws.PUT("/{resources}/{name}"). To(h.UpdateResource). Doc("update the specified notification config or receiver"). 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")). Returns(http.StatusOK, api.StatusOK, nil)) @@ -131,18 +131,19 @@ func AddToContainer( To(h.DeleteResource). Doc("delete the specified notification config or receiver"). 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")). Returns(http.StatusOK, api.StatusOK, errors.None)) // apis for tenant notification config and receiver ws.Route(ws.GET("/users/{user}/{resources}"). To(h.ListResource). - Doc("list the notification config or receiver"). + Doc("list the notification configs or receivers"). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). Param(ws.PathParameter("user", "user name")). - Param(ws.QueryParameter(query.ParameterName, "name used to do filtering").Required(false)). - Param(ws.QueryParameter(query.ParameterLabelSelector, "label selector 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.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.ParameterLimit, "limit").Required(false)). Param(ws.QueryParameter(query.ParameterAscending, "sort parameters, e.g. ascending=false").Required(false).DefaultValue("ascending=false")). @@ -154,7 +155,7 @@ func AddToContainer( Doc("get the specified notification config or receiver"). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). 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")). Returns(http.StatusOK, api.StatusOK, nil)) @@ -170,7 +171,7 @@ func AddToContainer( Doc("update the specified notification config or receiver"). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). 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")). Returns(http.StatusOK, api.StatusOK, nil)) @@ -179,7 +180,7 @@ func AddToContainer( Doc("delete the specified notification config or receiver"). Metadata(KeyOpenAPITags, []string{constants.NotificationTag}). 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")). Returns(http.StatusOK, api.StatusOK, errors.None)) diff --git a/pkg/models/notification/notification.go b/pkg/models/notification/notification.go index c8969773a..885d40968 100644 --- a/pkg/models/notification/notification.go +++ b/pkg/models/notification/notification.go @@ -55,9 +55,8 @@ func NewOperator( } } -// List objects, if the user is nil, it will return the global object. -// If the user it not nil, it will return tenant object which the tenant specified in the labels of object -// equal to this user. +// List objects. Only global objects will be returned if the user is nil. +// If the user is not nil, only tenant objects whose tenant label matches the user will be returned. func (o *operator) List(user, resource string, q *query.Query) (*api.ListResult, error) { // 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) { return obj, nil } -// Create a object, if the user is nil, it only can create a global object. -// If the user is not nil, it only can create a tenant object. +// Create an object. A global object will be created if the user is nil. +// 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) { if err := authorizer(user, obj); err != nil { @@ -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. -// If the user is not nil, it only can delete the tenant object which the tenant -// specified in the labels of the object equal to this user. +// Delete an object. A global object will be deleted if the user is nil. +// If the user is not nil, a tenant object whose tenant label matches the user will be deleted. func (o *operator) Delete(user, resource, name string) error { if obj, err := o.Get(user, resource, name); err != nil { @@ -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. -// If the user is not nil, it only can delete the tenant object which the tenant -// specified in the labels of the object equal to this user. +// Update an object, only a global object will be updated if the user is nil. +// If the user is not nil, a tenant object whose tenant label matches the user will be updated. func (o *operator) Update(user, resource string, obj runtime.Object) (runtime.Object, error) { name, err := getName(obj) @@ -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) { 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) { - obj, err := o.resourceGetter.Get("secrets", constants.KubeSphereNotificationNamespace, name) + obj, err := o.resourceGetter.Get("secrets", constants.NotificationSecretNamespace, name) if err != nil { return nil, err } @@ -225,15 +222,15 @@ func (o *operator) GetSecret(name string) (interface{}, error) { func (o *operator) CreateOrUpdateSecret(obj *corev1.Secret) (*corev1.Secret, error) { - obj.Namespace = constants.KubeSphereNotificationNamespace + obj.Namespace = constants.NotificationSecretNamespace if obj.Labels == nil { obj.Labels = make(map[string]string) } obj.Labels[constants.NotificationManagedLabel] = "true" 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 { - 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 { 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 { diff --git a/pkg/models/notification/notification_test.go b/pkg/models/notification/notification_test.go index 6a97dc5d5..9ebfb2008 100644 --- a/pkg/models/notification/notification_test.go +++ b/pkg/models/notification/notification_test.go @@ -109,7 +109,7 @@ func TestOperator_CreateOrUpdateSecret(t *testing.T) { result: &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "test", - Namespace: constants.KubeSphereNotificationNamespace, + Namespace: constants.NotificationSecretNamespace, Labels: map[string]string{constants.NotificationManagedLabel: "true"}, }, }, @@ -168,7 +168,7 @@ var ( secret1 = &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "foo1", - Namespace: constants.KubeSphereNotificationNamespace, + Namespace: constants.NotificationSecretNamespace, Labels: map[string]string{constants.NotificationManagedLabel: "true"}, }, } @@ -176,7 +176,7 @@ var ( secret2 = &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "foo2", - Namespace: constants.KubeSphereNotificationNamespace, + Namespace: constants.NotificationSecretNamespace, Labels: map[string]string{constants.NotificationManagedLabel: "true"}, }, } @@ -184,7 +184,7 @@ var ( secret3 = &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "foo3", - Namespace: constants.KubeSphereNotificationNamespace, + Namespace: constants.NotificationSecretNamespace, Labels: map[string]string{constants.NotificationManagedLabel: "true"}, }, }