Skip to content

Commit

Permalink
🎉 [minor] Add Microsoft Teams reporter (#28)
Browse files Browse the repository at this point in the history
* 🎉 Sending message with ms teams

* 🎉 Add ms teams reporter

* 🍱 Update ms teams message

* ✅ Add ms teams reporter test

* 💬 Format ms teams message

* 🍱 Add configuration for ms teams credential

* 🍱 Support group and channel name

* 💡 Make swag

* 💄 Format time string and change color

* ✅ Add ms teams util test

* 🐛 Fix data race

* 👌 Update report messages

* 💬 Update report messages

* 💄 Change warning color
  • Loading branch information
Pohfy123 authored Apr 23, 2020
1 parent 90d2525 commit 33d9a5a
Show file tree
Hide file tree
Showing 32 changed files with 2,185 additions and 157 deletions.
37 changes: 26 additions & 11 deletions api/v1beta1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ type ConfigReporter struct {
// +optional
Slack *Slack `json:"slack,omitempty"`
// +optional
MSTeams *MSTeams `json:"msTeams,omitempty"`
// +optional
Rest *Rest `json:"rest,omitempty"`
// +optional
Shell *Shell `json:"cmd,omitempty"`
Expand All @@ -173,26 +175,26 @@ type ReportOption struct {
Value string `json:"value"`
}

// SlackInterval represents how often of sending component upgrade notification within a retry cycle
type SlackInterval string
// ReporterInterval represents how often of sending component upgrade notification within a retry cycle
type ReporterInterval string

const (
// IntervalEveryTime means sending slack notification in every component upgrade runs
IntervalEveryTime SlackInterval = "everytime"
IntervalEveryTime ReporterInterval = "everytime"
// IntervalRetry means sending slack notification after retry only
IntervalRetry SlackInterval = "retry"
IntervalRetry ReporterInterval = "retry"
)

// SlackCriteria represents a criteria of sending component upgrade notification
type SlackCriteria string
// ReporterCriteria represents a criteria of sending component upgrade notification
type ReporterCriteria string

const (
// CriteriaSuccess means sending slack notification when component upgrade is success only
CriteriaSuccess SlackCriteria = "success"
CriteriaSuccess ReporterCriteria = "success"
// CriteriaFailure means sending slack notification when component upgrade is failure only
CriteriaFailure SlackCriteria = "failure"
CriteriaFailure ReporterCriteria = "failure"
// CriteriaBoth means sending slack notification whether component upgrade is success or failure
CriteriaBoth SlackCriteria = "both"
CriteriaBoth ReporterCriteria = "both"
)

// Slack defines a configuration of slack
Expand All @@ -202,12 +204,25 @@ type Slack struct {
ComponentUpgrade *ConfigComponentUpgrade `json:"componentUpgrade,omitempty"`
}

// MSTeams defines a configuration of Microsoft Teams
type MSTeams struct {
Groups []MSTeamsGroup `json:"groups"`
// +optional
ComponentUpgrade *ConfigComponentUpgrade `json:"componentUpgrade,omitempty"`
}

// MSTeamsGroup defines group name/id and channel name/id of Microsoft Teams
type MSTeamsGroup struct {
GroupNameOrID string `json:"groupNameOrID"`
ChannelNameOrIDs []string `json:"channelNameOrIDs"`
}

// ConfigComponentUpgrade defines a configuration of component upgrade report
type ConfigComponentUpgrade struct {
// +optional
Interval SlackInterval `json:"interval,omitempty"`
Interval ReporterInterval `json:"interval,omitempty"`
// +optional
Criteria SlackCriteria `json:"criteria,omitempty"`
Criteria ReporterCriteria `json:"criteria,omitempty"`
}

// Rest defines a configuration of http rest
Expand Down
52 changes: 52 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions cmd/samsahai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func startCtrlCmd() *cobra.Command {
}

configs := s2h.SamsahaiConfig{
// TODO: move to credential
TeamcityURL: viper.GetString(s2h.VKTeamcityURL),
SamsahaiURL: fmt.Sprintf("%s://%s.%s:%s",
viper.GetString(s2h.VKS2HServiceScheme),
Expand All @@ -161,6 +162,13 @@ func startCtrlCmd() *cobra.Command {
SlackToken: viper.GetString(s2h.VKSlackToken),
TeamcityUsername: viper.GetString(s2h.VKTeamcityUsername),
TeamcityPassword: viper.GetString(s2h.VKTeamcityPassword),
MSTeams: s2h.MSTeamsCredential{
TenantID: viper.GetString(s2h.VKMSTeamsTenantID),
ClientID: viper.GetString(s2h.VKMSTeamsClientID),
ClientSecret: viper.GetString(s2h.VKMSTeamsClientSecret),
Username: viper.GetString(s2h.VKMSTeamsUsername),
Password: viper.GetString(s2h.VKMSTeamsPassword),
},
},
}

Expand Down Expand Up @@ -233,9 +241,14 @@ func startCtrlCmd() *cobra.Command {
cmd.Flags().String(s2h.VKS2HServiceScheme, "http", "Scheme to use for connecting to Samsahai.")
cmd.Flags().String(s2h.VKS2HServiceName, "samsahai", "Service name for connecting to Samsahai.")
cmd.Flags().String(s2h.VKS2HExternalURL, "http://localhost:8080", "External url for Samsahai.")
cmd.Flags().String(s2h.VKTeamcityURL, "", "Teamcity Base URL.")
cmd.Flags().String(s2h.VKTeamcityUsername, "", "Teamcity Username.")
cmd.Flags().String(s2h.VKTeamcityPassword, "", "Teamcity Password.")
cmd.Flags().String(s2h.VKTeamcityURL, "", "Teamcity base URL used for initializing Teamcity test runner.")
cmd.Flags().String(s2h.VKTeamcityUsername, "", "Teamcity username used for initializing Teamcity test runner.")
cmd.Flags().String(s2h.VKTeamcityPassword, "", "Teamcity password used for initializing Teamcity test runner.")
cmd.Flags().String(s2h.VKMSTeamsTenantID, "", "Microsoft Teams tenant ID used for initializing Microsoft Teams reporter.")
cmd.Flags().String(s2h.VKMSTeamsClientID, "", "Microsoft Teams client ID used for initializing Microsoft Teams reporter.")
cmd.Flags().String(s2h.VKMSTeamsClientSecret, "", "Microsoft Teams client secret used for initializing Microsoft Teams reporter.")
cmd.Flags().String(s2h.VKMSTeamsUsername, "", "Microsoft Teams username used for initializing Microsoft Teams reporter.")
cmd.Flags().String(s2h.VKMSTeamsPassword, "", "Microsoft Teams password used for initializing Microsoft Teams reporter.")
cmd.Flags().Int(s2h.VKActivePromotionConcurrences, 1, "Concurrent active promotions.")
cmd.Flags().Duration(s2h.VKActivePromotionTimeout, 30*time.Minute, "Active promotion timeout.")
cmd.Flags().Duration(s2h.VKActivePromotionDemotionTimeout, 3*time.Minute, "Active demotion timeout.")
Expand Down
39 changes: 37 additions & 2 deletions config/crds/env.samsahai.io_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,41 @@ spec:
- command
type: object
type: object
msTeams:
description: MSTeams defines a configuration of Microsoft Teams
properties:
componentUpgrade:
description: ConfigComponentUpgrade defines a configuration
of component upgrade report
properties:
criteria:
description: ReporterCriteria represents a criteria of sending
component upgrade notification
type: string
interval:
description: ReporterInterval represents how often of sending
component upgrade notification within a retry cycle
type: string
type: object
groups:
items:
description: MSTeamsGroup defines group name/id and channel
name/id of Microsoft Teams
properties:
channelNameOrIDs:
items:
type: string
type: array
groupNameOrID:
type: string
required:
- channelNameOrIDs
- groupNameOrID
type: object
type: array
required:
- groups
type: object
optionals:
items:
description: ReportOption defines an optional configuration of
Expand Down Expand Up @@ -305,11 +340,11 @@ spec:
of component upgrade report
properties:
criteria:
description: SlackCriteria represents a criteria of sending
description: ReporterCriteria represents a criteria of sending
component upgrade notification
type: string
interval:
description: SlackInterval represents how often of sending
description: ReporterInterval represents how often of sending
component upgrade notification within a retry cycle
type: string
type: object
Expand Down
37 changes: 36 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2020-04-16 13:30:12.640214 +0700 +07 m=+0.112977605
// 2020-04-22 16:18:21.330435 +0700 +07 m=+0.282554246

package docs

Expand Down Expand Up @@ -974,6 +974,11 @@ var doc = `{
"type": "object",
"$ref": "#/definitions/v1beta1.Shell"
},
"msTeams": {
"description": "+optional",
"type": "object",
"$ref": "#/definitions/v1beta1.MSTeams"
},
"optionals": {
"description": "+optional",
"type": "array",
Expand Down Expand Up @@ -1121,6 +1126,36 @@ var doc = `{
}
}
},
"v1beta1.MSTeams": {
"type": "object",
"properties": {
"componentUpgrade": {
"description": "+optional",
"type": "object",
"$ref": "#/definitions/v1beta1.ConfigComponentUpgrade"
},
"groups": {
"type": "array",
"items": {
"$ref": "#/definitions/v1beta1.MSTeamsGroup"
}
}
}
},
"v1beta1.MSTeamsGroup": {
"type": "object",
"properties": {
"channelNameOrIDs": {
"type": "array",
"items": {
"type": "string"
}
},
"groupNameOrID": {
"type": "string"
}
}
},
"v1beta1.OutdatedNotification": {
"type": "object",
"properties": {
Expand Down
35 changes: 35 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@
"type": "object",
"$ref": "#/definitions/v1beta1.Shell"
},
"msTeams": {
"description": "+optional",
"type": "object",
"$ref": "#/definitions/v1beta1.MSTeams"
},
"optionals": {
"description": "+optional",
"type": "array",
Expand Down Expand Up @@ -1100,6 +1105,36 @@
}
}
},
"v1beta1.MSTeams": {
"type": "object",
"properties": {
"componentUpgrade": {
"description": "+optional",
"type": "object",
"$ref": "#/definitions/v1beta1.ConfigComponentUpgrade"
},
"groups": {
"type": "array",
"items": {
"$ref": "#/definitions/v1beta1.MSTeamsGroup"
}
}
}
},
"v1beta1.MSTeamsGroup": {
"type": "object",
"properties": {
"channelNameOrIDs": {
"type": "array",
"items": {
"type": "string"
}
},
"groupNameOrID": {
"type": "string"
}
}
},
"v1beta1.OutdatedNotification": {
"type": "object",
"properties": {
Expand Down
24 changes: 24 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ definitions:
$ref: '#/definitions/v1beta1.Shell'
description: +optional
type: object
msTeams:
$ref: '#/definitions/v1beta1.MSTeams'
description: +optional
type: object
optionals:
description: +optional
items:
Expand Down Expand Up @@ -411,6 +415,26 @@ definitions:
tag:
type: string
type: object
v1beta1.MSTeams:
properties:
componentUpgrade:
$ref: '#/definitions/v1beta1.ConfigComponentUpgrade'
description: +optional
type: object
groups:
items:
$ref: '#/definitions/v1beta1.MSTeamsGroup'
type: array
type: object
v1beta1.MSTeamsGroup:
properties:
channelNameOrIDs:
items:
type: string
type: array
groupNameOrID:
type: string
type: object
v1beta1.OutdatedNotification:
properties:
exceedDuration:
Expand Down
2 changes: 1 addition & 1 deletion internal/config/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func GetEnvComponentValues(config *s2hv1beta1.ConfigSpec, compName string, envTy

baseValues := map[string]interface{}{}
for _, url := range urls {
valuesBytes, err := http.Get(url, opts...)
_, valuesBytes, err := http.Get(url, opts...)
if err != nil {
return nil, errors.Wrapf(err,
"cannot get values file of %s env from url %s", envType, url)
Expand Down
5 changes: 5 additions & 0 deletions internal/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const (
VKTeamcityUsername = "teamcity-username"
VKTeamcityPassword = "teamcity-password"
VKSlackToken = "slack-token"
VKMSTeamsTenantID = "ms-teams-tenant-id"
VKMSTeamsClientID = "ms-teams-client-id"
VKMSTeamsClientSecret = "ms-teams-client-secret"
VKMSTeamsUsername = "ms-teams-username"
VKMSTeamsPassword = "ms-teams-password"
VKActivePromotionConcurrences = "active-promotion-concurrences"
VKActivePromotionTimeout = "active-promotion-timeout"
VKActivePromotionDemotionTimeout = "active-demotion-timeout"
Expand Down
Loading

0 comments on commit 33d9a5a

Please sign in to comment.