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