Skip to content

Commit

Permalink
feat: add lark notification support
Browse files Browse the repository at this point in the history
Signed-off-by: Zufar Dhiyaullhaq <[email protected]>
  • Loading branch information
zufardhiyaulhaq committed Oct 9, 2024
1 parent eed714d commit 8ec842f
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 34 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# istio-upgrade-worker

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github main branch build](https://img.shields.io/github/workflow/status/gopaytech/istio-upgrade-worker/Main)](https://github.com/gopaytech/istio-upgrade-worker/actions/workflows/main.yml) [![GitHub issues](https://img.shields.io/github/issues/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/pulls)[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/istio-upgrade-worker)](https://artifacthub.io/packages/search?repo=istio-upgrade-worker)
![Version: 1.1.0](https://img.shields.io/badge/Version-1.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github main branch build](https://img.shields.io/github/workflow/status/gopaytech/istio-upgrade-worker/Main)](https://github.com/gopaytech/istio-upgrade-worker/actions/workflows/main.yml) [![GitHub issues](https://img.shields.io/github/issues/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/pulls)[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/istio-upgrade-worker)](https://artifacthub.io/packages/search?repo=istio-upgrade-worker)

## Installing

Expand All @@ -21,6 +21,7 @@ helm install my-istio-upgrade-worker istio-upgrade-worker/istio-upgrade-worker -
| configuration.enableRolloutAtWeekend | bool | `false` | |
| configuration.istioNamespaceCanaryLabel | string | `"istio.io/rev=default"` | |
| configuration.istioNamespaceLabel | string | `"istio-injection=enabled"` | |
| configuration.larkWebhookSecretName | string | `"lark-webhook-secret"` | |
| configuration.maximumIteration | int | `5` | |
| configuration.maximumPercentageRolloutInSingleExecution | int | `20` | |
| configuration.notificationMode | string | `"slack"` | |
Expand All @@ -34,7 +35,7 @@ helm install my-istio-upgrade-worker istio-upgrade-worker/istio-upgrade-worker -
| configuration.timeLocation | string | `"Asia/Jakarta"` | |
| cronjob.image | string | `"ghcr.io/gopaytech/istio-upgrade-worker"` | |
| cronjob.schedule | string | `"32 5 * * *"` | |
| cronjob.tag | string | `"v1.0.0"` | |
| cronjob.tag | string | `"v1.1.0"` | |
| cronjob.timeZone | string | `"Asia/Jakarta"` | |
| podLabels | object | `{}` | |
| resources.limits.cpu | string | `"1024m"` | |
Expand Down
4 changes: 2 additions & 2 deletions charts/istio-upgrade-worker/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
apiVersion: v2
name: istio-upgrade-worker
version: 1.0.0
appVersion: 1.0.0
version: 1.1.0
appVersion: 1.1.0
type: application
home: https://github.com/gopaytech/istio-upgrade-worker

Expand Down
5 changes: 3 additions & 2 deletions charts/istio-upgrade-worker/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# istio-upgrade-worker

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github main branch build](https://img.shields.io/github/workflow/status/gopaytech/istio-upgrade-worker/Main)](https://github.com/gopaytech/istio-upgrade-worker/actions/workflows/main.yml) [![GitHub issues](https://img.shields.io/github/issues/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/pulls)[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/istio-upgrade-worker)](https://artifacthub.io/packages/search?repo=istio-upgrade-worker)
![Version: 1.1.0](https://img.shields.io/badge/Version-1.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.1.0](https://img.shields.io/badge/AppVersion-1.1.0-informational?style=flat-square) [![made with Go](https://img.shields.io/badge/made%20with-Go-brightgreen)](http://golang.org) [![Github main branch build](https://img.shields.io/github/workflow/status/gopaytech/istio-upgrade-worker/Main)](https://github.com/gopaytech/istio-upgrade-worker/actions/workflows/main.yml) [![GitHub issues](https://img.shields.io/github/issues/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/issues) [![GitHub pull requests](https://img.shields.io/github/issues-pr/gopaytech/istio-upgrade-worker)](https://github.com/gopaytech/istio-upgrade-worker/pulls)[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/istio-upgrade-worker)](https://artifacthub.io/packages/search?repo=istio-upgrade-worker)

## Installing

Expand All @@ -21,6 +21,7 @@ helm install my-istio-upgrade-worker istio-upgrade-worker/istio-upgrade-worker -
| configuration.enableRolloutAtWeekend | bool | `false` | |
| configuration.istioNamespaceCanaryLabel | string | `"istio.io/rev=default"` | |
| configuration.istioNamespaceLabel | string | `"istio-injection=enabled"` | |
| configuration.larkWebhookSecretName | string | `"lark-webhook-secret"` | |
| configuration.maximumIteration | int | `5` | |
| configuration.maximumPercentageRolloutInSingleExecution | int | `20` | |
| configuration.notificationMode | string | `"slack"` | |
Expand All @@ -34,7 +35,7 @@ helm install my-istio-upgrade-worker istio-upgrade-worker/istio-upgrade-worker -
| configuration.timeLocation | string | `"Asia/Jakarta"` | |
| cronjob.image | string | `"ghcr.io/gopaytech/istio-upgrade-worker"` | |
| cronjob.schedule | string | `"32 5 * * *"` | |
| cronjob.tag | string | `"v1.0.0"` | |
| cronjob.tag | string | `"v1.1.0"` | |
| cronjob.timeZone | string | `"Asia/Jakarta"` | |
| podLabels | object | `{}` | |
| resources.limits.cpu | string | `"1024m"` | |
Expand Down
4 changes: 4 additions & 0 deletions charts/istio-upgrade-worker/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ spec:
- secretRef:
name: {{ .Values.configuration.slackWebhookSecretName }}
{{ end }}
{{ if eq .Values.configuration.notificationMode "lark" }}
- secretRef:
name: {{ .Values.configuration.larkWebhookSecretName }}
{{ end }}
resources: {{ .Values.resources | toYaml | nindent 14 }}
restartPolicy: OnFailure
3 changes: 2 additions & 1 deletion charts/istio-upgrade-worker/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cronjob:
image: "ghcr.io/gopaytech/istio-upgrade-worker"
tag: "v1.0.0"
tag: "v1.1.0"
schedule: "32 5 * * *"
timeZone: 'Asia/Jakarta'

Expand Down Expand Up @@ -39,6 +39,7 @@ configuration:

notificationMode: slack
slackWebhookSecretName: slack-webhook-secret
larkWebhookSecretName: lark-webhook-secret

istioNamespaceCanaryLabel: istio.io/rev=default
istioNamespaceLabel: istio-injection=enabled
Expand Down
18 changes: 16 additions & 2 deletions charts/releases/index.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
apiVersion: v1
entries:
istio-upgrade-worker:
- apiVersion: v2
appVersion: 1.1.0
created: "2024-10-09T18:57:08.469686+07:00"
digest: 3ef20783cc1231f3e6ec8a4e53667ec59ad8bd838cd0c99f679bf45d8fa6c183
home: https://github.com/gopaytech/istio-upgrade-worker
maintainers:
- email: [email protected]
name: Zufar Dhiyaulhaq
url: https://zufardhiyaulhaq.com
name: istio-upgrade-worker
type: application
urls:
- istio-upgrade-worker-1.1.0.tgz
version: 1.1.0
- apiVersion: v2
appVersion: 1.0.0
created: "2024-10-04T14:53:02.46348+07:00"
created: "2024-10-09T18:57:08.469351+07:00"
digest: 6385974636e6b37cb53188476bdc4585fb84ed9e1a24d431d2a4b2d8612ba7e1
home: https://github.com/gopaytech/istio-upgrade-worker
maintainers:
Expand All @@ -15,4 +29,4 @@ entries:
urls:
- istio-upgrade-worker-1.0.0.tgz
version: 1.0.0
generated: "2024-10-04T14:53:02.462735+07:00"
generated: "2024-10-09T18:57:08.468845+07:00"
Binary file added charts/releases/istio-upgrade-worker-1.1.0.tgz
Binary file not shown.
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module github.com/gopaytech/istio-upgrade-worker
go 1.22

require (
github.com/go-lark/lark v1.15.0
github.com/hashicorp/go-version v1.7.0
github.com/parnurzeal/gorequest v0.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/slack-go/slack v0.14.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.29.1
k8s.io/apimachinery v0.29.1
Expand All @@ -13,7 +15,6 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
Expand All @@ -27,15 +28,10 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/slack-go/slack v0.14.0 // indirect
github.com/smartystreets/goconvey v1.8.1 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.18.0 // indirect
Expand Down
25 changes: 7 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 h1:m62nsMU279qRD9PQSWD1l66kmkXzuYcnVJqL4XLeV2M=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/go-lark/lark v1.15.0 h1:wzfzK9j85BrbFYcjxGZSjJiXbOxHQYkKjIClUwyT9XU=
github.com/go-lark/lark v1.15.0/go.mod h1:6ltbSztPZRT6IaO9ZIQyVaY5pVp/KeMizDYtfZkU+vM=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
Expand All @@ -17,6 +16,7 @@ github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand All @@ -38,19 +38,17 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand All @@ -69,36 +67,26 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/parnurzeal/gorequest v0.3.0 h1:SoFyqCDC9COr1xuS6VA8fC8RU7XyrJZN2ona1kEX7FI=
github.com/parnurzeal/gorequest v0.3.0/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/slack-go/slack v0.14.0 h1:6c0UTfbRnvRssZUsZ2qe0Iu07VAMPjRqOa6oX8ewF4k=
github.com/slack-go/slack v0.14.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
Expand Down Expand Up @@ -162,6 +150,7 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.29.1 h1:DAjwWX/9YT7NQD4INu49ROJuZAAAP/Ijki48GUPzxqw=
Expand Down
5 changes: 5 additions & 0 deletions services/notification/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package notification
import (
"fmt"

"github.com/gopaytech/istio-upgrade-worker/services/notification/lark"
"github.com/gopaytech/istio-upgrade-worker/services/notification/slack"
"github.com/gopaytech/istio-upgrade-worker/settings"
)
Expand All @@ -12,5 +13,9 @@ func NotificationFactory(settings settings.Settings) (NotificationInterface, err
return slack.NewNotificationSlack(settings), nil
}

if settings.NotificationMode == "lark" {
return lark.NewNotificationLark(settings), nil
}

return nil, fmt.Errorf("notification is not supported")
}
37 changes: 37 additions & 0 deletions services/notification/lark/lark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package lark

import (
"context"
"log"

golark "github.com/go-lark/lark"
"github.com/gopaytech/istio-upgrade-worker/settings"
"github.com/gopaytech/istio-upgrade-worker/types"
)

func NewNotificationLark(settings settings.Settings) Lark {
return Lark{
Settings: settings,
}
}

type Lark struct {
Settings settings.Settings
}

func (s Lark) Send(ctx context.Context, upgrade types.Notification) error {
bot := golark.NewNotificationBot(s.Settings.NotificationLarkWebhook)
content := golark.NewPostBuilder().
Title(upgrade.Title).
TextTag(upgrade.Message, 1, true).
Render()
buffer := golark.NewMsgBuffer(golark.MsgPost).Post(content).Build()

_, err := bot.PostMessage(buffer)
if err != nil {
log.Printf("failed to send slack notification: %v\n", err.Error())
return err
}

return nil
}
2 changes: 2 additions & 0 deletions services/notification/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package slack
import (
"context"
"encoding/json"
"log"
"strconv"
"time"

Expand Down Expand Up @@ -35,6 +36,7 @@ func (s Slack) Send(ctx context.Context, upgrade types.Notification) error {

err := slack.PostWebhook(s.Settings.NotificationSlackWebhook, &msg)
if err != nil {
log.Printf("failed to send slack notification: %v\n", err.Error())
return err
}

Expand Down

0 comments on commit 8ec842f

Please sign in to comment.