@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user