diff --git a/README.md b/README.md index 4f456c59..02e7b710 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,6 @@ spec: authPassword: key: password name: default-email-secret - namespace: kubesphere-monitoring-system authUsername: sender1 from: sender1@xyz.com requireTLS: true @@ -178,7 +177,6 @@ spec: authPassword: key: password name: default-email-secret - namespace: kubesphere-monitoring-system authUsername: sender1 from: sender1@xyz.com requireTLS: true @@ -376,7 +374,6 @@ spec: authPassword: key: password name: default-email-secret - namespace: default authUsername: sender1 from: sender1@xyz.com requireTLS: true @@ -427,7 +424,6 @@ spec: authPassword: key: password name: user1-email-secret - namespace: default authUsername: sender1 from: sender1@xyz.com requireTLS: true diff --git a/config/bundle.yaml b/config/bundle.yaml index d0a45e79..2e39f147 100644 --- a/config/bundle.yaml +++ b/config/bundle.yaml @@ -39,29 +39,35 @@ spec: authentications. properties: key: + description: The key of the secret to select from. Must be a valid + secret key. type: string name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string - namespace: - type: string + optional: + description: Specify whether the Secret or its key must be defined + type: boolean required: - key - - name - - namespace type: object authSecret: description: The secret contains the SMTP secret for CRAM-MD5 authentication. properties: key: + description: The key of the secret to select from. Must be a valid + secret key. type: string name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string - namespace: - type: string + optional: + description: Specify whether the Secret or its key must be defined + type: boolean required: - key - - name - - namespace type: object authUsername: description: The username for CRAM-MD5, LOGIN and PLAIN authentications. diff --git a/config/crd/bases/notification.kubesphere.io_emailconfigs.yaml b/config/crd/bases/notification.kubesphere.io_emailconfigs.yaml index 6f41c51f..3d694e80 100644 --- a/config/crd/bases/notification.kubesphere.io_emailconfigs.yaml +++ b/config/crd/bases/notification.kubesphere.io_emailconfigs.yaml @@ -42,29 +42,35 @@ spec: authentications. properties: key: + description: The key of the secret to select from. Must be a valid + secret key. type: string name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string - namespace: - type: string + optional: + description: Specify whether the Secret or its key must be defined + type: boolean required: - key - - name - - namespace type: object authSecret: description: The secret contains the SMTP secret for CRAM-MD5 authentication. properties: key: + description: The key of the secret to select from. Must be a valid + secret key. type: string name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string - namespace: - type: string + optional: + description: Specify whether the Secret or its key must be defined + type: boolean required: - key - - name - - namespace type: object authUsername: description: The username for CRAM-MD5, LOGIN and PLAIN authentications. diff --git a/config/samples/bundle.yaml b/config/samples/bundle.yaml index c8ea2dbe..724a5c03 100644 --- a/config/samples/bundle.yaml +++ b/config/samples/bundle.yaml @@ -21,7 +21,6 @@ spec: authPassword: key: password name: default-email-secret - namespace: kubesphere-monitoring-system authUsername: sender1 from: sender1@xyz.com requireTLS: true @@ -42,7 +41,6 @@ spec: authPassword: key: password name: default-email-secret - namespace: kubesphere-monitoring-system authUsername: sender1 from: sender1@xyz.com requireTLS: true diff --git a/config/samples/email_default_config.yaml b/config/samples/email_default_config.yaml index 3e5b3222..0a83cbf4 100644 --- a/config/samples/email_default_config.yaml +++ b/config/samples/email_default_config.yaml @@ -11,7 +11,6 @@ spec: port: "25" authUsername: sender1 authPassword: - namespace: kubesphere-monitoring-system name: default-email-secret key: password requireTLS: true diff --git a/config/samples/email_tenant_config.yaml b/config/samples/email_tenant_config.yaml index 6b78b6b5..b9a7faca 100644 --- a/config/samples/email_tenant_config.yaml +++ b/config/samples/email_tenant_config.yaml @@ -12,7 +12,6 @@ spec: port: "25" authUsername: sender1 authPassword: - namespace: kubesphere-monitoring-system name: default-email-secret key: password requireTLS: true diff --git a/helm/crds/emailconfigs.yaml b/helm/crds/emailconfigs.yaml index 25007aa8..1da5f148 100644 --- a/helm/crds/emailconfigs.yaml +++ b/helm/crds/emailconfigs.yaml @@ -38,29 +38,35 @@ spec: authentications. properties: key: + description: The key of the secret to select from. Must be a valid + secret key. type: string name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string - namespace: - type: string + optional: + description: Specify whether the Secret or its key must be defined + type: boolean required: - key - - name - - namespace type: object authSecret: description: The secret contains the SMTP secret for CRAM-MD5 authentication. properties: key: + description: The key of the secret to select from. Must be a valid + secret key. type: string name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' type: string - namespace: - type: string + optional: + description: Specify whether the Secret or its key must be defined + type: boolean required: - key - - name - - namespace type: object authUsername: description: The username for CRAM-MD5, LOGIN and PLAIN authentications. diff --git a/pkg/apis/v1alpha1/emailconfig_types.go b/pkg/apis/v1alpha1/emailconfig_types.go index 7590cca5..828b6cf6 100644 --- a/pkg/apis/v1alpha1/emailconfig_types.go +++ b/pkg/apis/v1alpha1/emailconfig_types.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1 import ( + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -33,9 +34,9 @@ type EmailConfigSpec struct { // The identity for PLAIN authentication. AuthIdentify *string `json:"authIdentify,omitempty"` // The secret contains the SMTP password for LOGIN and PLAIN authentications. - AuthPassword *SecretKeyRef `json:"authPassword,omitempty"` + AuthPassword *v1.SecretKeySelector `json:"authPassword,omitempty"` // The secret contains the SMTP secret for CRAM-MD5 authentication. - AuthSecret *SecretKeyRef `json:"authSecret,omitempty"` + AuthSecret *v1.SecretKeySelector `json:"authSecret,omitempty"` // The default SMTP TLS requirement. RequireTLS *bool `json:"requireTLS,omitempty"` } @@ -45,12 +46,6 @@ type HostPort struct { Port string `json:"port"` } -type SecretKeyRef struct { - Namespace string `json:"namespace"` - Name string `json:"name"` - Key string `json:"key"` -} - // EmailConfigStatus defines the observed state of EmailConfig type EmailConfigStatus struct { } diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go index ef721709..ab1c6c18 100644 --- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go @@ -21,8 +21,8 @@ limitations under the License. package v1alpha1 import ( - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -106,13 +106,13 @@ func (in *EmailConfigSpec) DeepCopyInto(out *EmailConfigSpec) { } if in.AuthPassword != nil { in, out := &in.AuthPassword, &out.AuthPassword - *out = new(SecretKeyRef) - **out = **in + *out = new(v1.SecretKeySelector) + (*in).DeepCopyInto(*out) } if in.AuthSecret != nil { in, out := &in.AuthSecret, &out.AuthSecret - *out = new(SecretKeyRef) - **out = **in + *out = new(v1.SecretKeySelector) + (*in).DeepCopyInto(*out) } if in.RequireTLS != nil { in, out := &in.RequireTLS, &out.RequireTLS @@ -235,7 +235,7 @@ func (in *EmailReceiverSpec) DeepCopyInto(out *EmailReceiverSpec) { } if in.EmailConfigSelector != nil { in, out := &in.EmailConfigSelector, &out.EmailConfigSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } } @@ -370,7 +370,7 @@ func (in *NotificationManagerSpec) DeepCopyInto(out *NotificationManagerSpec) { } if in.ImagePullPolicy != nil { in, out := &in.ImagePullPolicy, &out.ImagePullPolicy - *out = new(corev1.PullPolicy) + *out = new(v1.PullPolicy) **out = **in } if in.Replicas != nil { @@ -387,19 +387,19 @@ func (in *NotificationManagerSpec) DeepCopyInto(out *NotificationManagerSpec) { } if in.Affinity != nil { in, out := &in.Affinity, &out.Affinity - *out = new(corev1.Affinity) + *out = new(v1.Affinity) (*in).DeepCopyInto(*out) } if in.Tolerations != nil { in, out := &in.Tolerations, &out.Tolerations - *out = make([]corev1.Toleration, len(*in)) + *out = make([]v1.Toleration, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.DefaultConfigSelector != nil { in, out := &in.DefaultConfigSelector, &out.DefaultConfigSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } if in.Receivers != nil { @@ -484,12 +484,12 @@ func (in *ReceiversSpec) DeepCopyInto(out *ReceiversSpec) { *out = *in if in.GlobalReceiverSelector != nil { in, out := &in.GlobalReceiverSelector, &out.GlobalReceiverSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } if in.TenantReceiverSelector != nil { in, out := &in.TenantReceiverSelector, &out.TenantReceiverSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } if in.Options != nil { @@ -509,21 +509,6 @@ func (in *ReceiversSpec) DeepCopy() *ReceiversSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SecretKeyRef) DeepCopyInto(out *SecretKeyRef) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretKeyRef. -func (in *SecretKeyRef) DeepCopy() *SecretKeyRef { - if in == nil { - return nil - } - out := new(SecretKeyRef) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SlackConfig) DeepCopyInto(out *SlackConfig) { *out = *in @@ -588,7 +573,7 @@ func (in *SlackConfigSpec) DeepCopyInto(out *SlackConfigSpec) { *out = *in if in.SlackTokenSecret != nil { in, out := &in.SlackTokenSecret, &out.SlackTokenSecret - *out = new(corev1.SecretKeySelector) + *out = new(v1.SecretKeySelector) (*in).DeepCopyInto(*out) } } @@ -702,7 +687,7 @@ func (in *SlackReceiverSpec) DeepCopyInto(out *SlackReceiverSpec) { *out = *in if in.SlackConfigSelector != nil { in, out := &in.SlackConfigSelector, &out.SlackConfigSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } } @@ -796,7 +781,7 @@ func (in *WebhookConfigSpec) DeepCopyInto(out *WebhookConfigSpec) { *out = *in if in.UrlSecret != nil { in, out := &in.UrlSecret, &out.UrlSecret - *out = new(corev1.SecretKeySelector) + *out = new(v1.SecretKeySelector) (*in).DeepCopyInto(*out) } if in.Url != nil { @@ -806,7 +791,7 @@ func (in *WebhookConfigSpec) DeepCopyInto(out *WebhookConfigSpec) { } if in.HttpConfigSelector != nil { in, out := &in.HttpConfigSelector, &out.HttpConfigSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } } @@ -920,7 +905,7 @@ func (in *WebhookReceiverSpec) DeepCopyInto(out *WebhookReceiverSpec) { *out = *in if in.WebhookConfigSelector != nil { in, out := &in.WebhookConfigSelector, &out.WebhookConfigSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } } @@ -1014,7 +999,7 @@ func (in *WechatConfigSpec) DeepCopyInto(out *WechatConfigSpec) { *out = *in if in.WechatApiSecret != nil { in, out := &in.WechatApiSecret, &out.WechatApiSecret - *out = new(corev1.SecretKeySelector) + *out = new(v1.SecretKeySelector) (*in).DeepCopyInto(*out) } } @@ -1128,7 +1113,7 @@ func (in *WechatReceiverSpec) DeepCopyInto(out *WechatReceiverSpec) { *out = *in if in.WechatConfigSelector != nil { in, out := &in.WechatConfigSelector, &out.WechatConfigSelector - *out = new(v1.LabelSelector) + *out = new(metav1.LabelSelector) (*in).DeepCopyInto(*out) } } diff --git a/pkg/notify/config/config.go b/pkg/notify/config/config.go index b3bc8089..05dbf00c 100644 --- a/pkg/notify/config/config.go +++ b/pkg/notify/config/config.go @@ -1187,7 +1187,7 @@ func (c *Config) generateEmail(mc *nmv1alpha1.EmailConfig) *Email { if mc.Spec.AuthPassword != nil { authPassword := v1.Secret{} - if err := c.cache.Get(c.ctx, types.NamespacedName{Namespace: mc.Spec.AuthPassword.Namespace, Name: mc.Spec.AuthPassword.Name}, &authPassword); err != nil { + if err := c.cache.Get(c.ctx, types.NamespacedName{Namespace: mc.Namespace, Name: mc.Spec.AuthPassword.Name}, &authPassword); err != nil { _ = level.Error(c.logger).Log("msg", "Unable to get AuthPassword secret", "err", err) return nil } @@ -1196,7 +1196,7 @@ func (c *Config) generateEmail(mc *nmv1alpha1.EmailConfig) *Email { if mc.Spec.AuthSecret != nil { authSecret := v1.Secret{} - if err := c.cache.Get(c.ctx, types.NamespacedName{Namespace: mc.Spec.AuthSecret.Namespace, Name: mc.Spec.AuthSecret.Name}, &authSecret); err != nil { + if err := c.cache.Get(c.ctx, types.NamespacedName{Namespace: mc.Namespace, Name: mc.Spec.AuthSecret.Name}, &authSecret); err != nil { _ = level.Error(c.logger).Log("msg", "Unable to get AuthSecret secret", "err", err) return nil }