Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Add kubernetes deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmt committed Dec 10, 2019
1 parent 8d5e9c8 commit 04d857e
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 12 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.12.7 as builder

RUN apt-get update && apt-get install ca-certificates

WORKDIR /src

COPY go.mod /src/go.mod
COPY go.sum /src/go.sum

RUN go mod download

# Perform the build
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /dist/argocd-notifications-controller ./cmd/main.go

FROM scratch

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /dist/argocd-notifications-controller /app/argocd-notifications-controller
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Notifications for Argo CD.

* [x] Email notifications
* [x] Slack notifications
* [ ] Deployment manifests
* [x] Deployment manifests
* [ ] Documentation
6 changes: 2 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import (
"io/ioutil"
"os"

"github.com/argoproj-labs/argocd-notifications/controller"
"github.com/argoproj-labs/argocd-notifications/notifiers"

"github.com/argoproj-labs/argocd-notifications/triggers"

"gopkg.in/yaml.v2"

"github.com/argoproj-labs/argocd-notifications/controller"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/tools/clientcmd"
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ go 1.12
require (
github.com/antonmedv/expr v1.4.1
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0
github.com/golang/protobuf v1.3.2 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/json-iterator/go v1.1.8 // indirect
github.com/nlopes/slack v0.5.0
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/sirupsen/logrus v1.4.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell v1.1.2/go.mod h1:h3kq4HO9l2On+V9ed8w8ewqQEmGCSSHOgQ+2h8uzurE=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-check/check v1.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
Expand Down
6 changes: 6 additions & 0 deletions manifests/argocd-notifications-cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
config.yaml: ""
38 changes: 38 additions & 0 deletions manifests/argocd-notifications-controller-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: argocd-notifications-controller
spec:
strategy:
type: Recreate
selector:
matchLabels:
app.kubernetes.io/name: argocd-notifications-controller
template:
metadata:
labels:
app.kubernetes.io/name: argocd-notifications-controller
spec:
containers:
- command:
- /app/argocd-notifications-controller
- --config
- /app/config/config.yaml
- --notifiers
- /app/secret/notifiers.yaml
image: alexmt/argocd-notifications:latest
imagePullPolicy: Always
name: argocd-notifications-controller
volumeMounts:
- name: config
mountPath: /app/config
- name: notifiers
mountPath: /app/secret
volumes:
- name: notifiers
secret:
secretName: argocd-notifications-secret
- name: config
configMap:
name: argocd-notifications-cm
serviceAccountName: argocd-notifications-controller
15 changes: 15 additions & 0 deletions manifests/argocd-notifications-controller-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: argocd-notifications-controller
rules:
- apiGroups:
- argoproj.io
resources:
- applications
- appprojects
verbs:
- list
- watch
- update
- patch
11 changes: 11 additions & 0 deletions manifests/argocd-notifications-controller-rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argocd-notifications-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: argocd-notifications-controller
subjects:
- kind: ServiceAccount
name: argocd-notifications-controller
4 changes: 4 additions & 0 deletions manifests/argocd-notifications-controller-sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: argocd-notifications-controller
7 changes: 7 additions & 0 deletions manifests/argocd-notifications-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: argocd-notifications-secret
stringData:
notifiers.yaml: "{}"
type: Opaque
10 changes: 10 additions & 0 deletions manifests/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- argocd-notifications-controller-rolebinding.yaml
- argocd-notifications-controller-sa.yaml
- argocd-notifications-cm.yaml
- argocd-notifications-controller-deployment.yaml
- argocd-notifications-secret.yaml
- argocd-notifications-controller-role.yaml
28 changes: 21 additions & 7 deletions notifiers/slack.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package notifiers

import (
"gomodules.xyz/notify/slack"
"context"
"crypto/tls"
"net/http"

"github.com/nlopes/slack"
)

type SlackOptions struct {
Token string `json:"token"`
Channels []string `json:"channels"`
Token string `json:"token"`
Channels []string `json:"channels"`
InsecureSkipVerify bool `json:"insecureSkipVerify"`
}

type slackNotifier struct {
Expand All @@ -18,8 +23,17 @@ func NewSlackNotifier(opts SlackOptions) Notifier {
}

func (n *slackNotifier) Send(_ string, body string, recipient string) error {
return slack.New(slack.Options{
AuthToken: n.opts.Token,
Channel: n.opts.Channels,
}).WithBody(body).To(recipient).Send()
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: n.opts.InsecureSkipVerify,
},
},
}
s := slack.New(n.opts.Token, slack.OptionHTTPClient(client))
_, _, err := s.PostMessageContext(
context.TODO(),
recipient,
slack.MsgOptionText(body, false))
return err
}

0 comments on commit 04d857e

Please sign in to comment.