Organize code structure
This commit is contained in:
parent
9bde4cb59f
commit
e641a9fa12
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
|
||||
"github.com/mailgun/mailgun-go/v3"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func TestTeams_Send(t *testing.T) {
|
|||
err := notification.K8sClient.Create(context.TODO(), secret)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, teams.Send(notification, v1alpha2.Notification{
|
||||
err := teams.Send(notification, v1alpha2.Notification{
|
||||
Teams: v1alpha2.Teams{
|
||||
URLSecretKeySelector: v1alpha2.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{
|
||||
|
|
@ -94,5 +94,6 @@ func TestTeams_Send(t *testing.T) {
|
|||
Key: testURLSelectorKeyName,
|
||||
},
|
||||
},
|
||||
}))
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/log"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
|
|
@ -70,31 +70,30 @@ type service interface {
|
|||
// Listen is goroutine that listens for incoming messages and sends it
|
||||
func Listen(notification chan *Notification) {
|
||||
for n := range notification {
|
||||
if len(n.Jenkins.Spec.Notifications) > 0 {
|
||||
for _, notificationConfig := range n.Jenkins.Spec.Notifications {
|
||||
var err error
|
||||
var svc service
|
||||
for _, notificationConfig := range n.Jenkins.Spec.Notifications {
|
||||
var err error
|
||||
var svc service
|
||||
|
||||
if notificationConfig.Slack != (v1alpha2.Slack{}) {
|
||||
svc = Slack{}
|
||||
} else if notificationConfig.Teams != (v1alpha2.Teams{}) {
|
||||
svc = Teams{}
|
||||
} else if notificationConfig.Mailgun != (v1alpha2.Mailgun{}) {
|
||||
svc = Mailgun{}
|
||||
} else {
|
||||
n.Logger.V(log.VWarn).Info(fmt.Sprintf("Notification service in `%s` not found or not defined", notificationConfig.Name))
|
||||
continue
|
||||
}
|
||||
if notificationConfig.Slack != (v1alpha2.Slack{}) {
|
||||
svc = Slack{}
|
||||
} else if notificationConfig.Teams != (v1alpha2.Teams{}) {
|
||||
svc = Teams{}
|
||||
} else if notificationConfig.Mailgun != (v1alpha2.Mailgun{}) {
|
||||
svc = Mailgun{}
|
||||
} else {
|
||||
n.Logger.V(log.VWarn).Info(fmt.Sprintf("Notification service in `%s` not found or not defined", notificationConfig.Name))
|
||||
continue
|
||||
}
|
||||
|
||||
err = notify(svc, n, notificationConfig)
|
||||
err = notify(svc, n, notificationConfig)
|
||||
|
||||
if err != nil {
|
||||
n.Logger.V(log.VWarn).Info(fmt.Sprintf("Failed to send notifications. %+v", err))
|
||||
} else {
|
||||
n.Logger.V(log.VDebug).Info("Sent notification")
|
||||
}
|
||||
if err != nil {
|
||||
n.Logger.V(log.VWarn).Info(fmt.Sprintf("Failed to send notifications. %+v", err))
|
||||
} else {
|
||||
n.Logger.V(log.VDebug).Info("Sent notification")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/pkg/errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func TestSlack_Send(t *testing.T) {
|
|||
|
||||
slack := Slack{}
|
||||
|
||||
assert.NoError(t, slack.Send(notification, v1alpha2.Notification{
|
||||
err := slack.Send(notification, v1alpha2.Notification{
|
||||
Slack: v1alpha2.Slack{
|
||||
URLSecretKeySelector: v1alpha2.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{
|
||||
|
|
@ -93,5 +93,7 @@ func TestSlack_Send(t *testing.T) {
|
|||
Key: testURLSelectorKeyName,
|
||||
},
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue