Skip to content

Commit

Permalink
feat(notify): add clusterID to notify message
Browse files Browse the repository at this point in the history
Signed-off-by: Feng Kun <[email protected]>
  • Loading branch information
kevinfeng authored and tke-robot committed May 30, 2020
1 parent 749851a commit 7914fd8
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 119 deletions.
2 changes: 2 additions & 0 deletions api/notify/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ type MessageSpec struct {
AlarmPolicyType string
// +optional
ReceiverChannelName string
// +optional
ClusterID string
}

// MessageStatus represents information about the status of a message.
Expand Down
3 changes: 2 additions & 1 deletion api/notify/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func AddFieldLabelConversionsForMessage(scheme *runtime.Scheme) error {
"metadata.name",
"spec.alarmPolicyName",
"spec.alarmPolicyType",
"spec.receiverChannelName":
"spec.receiverChannelName",
"spec.clusterID":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
Expand Down
277 changes: 159 additions & 118 deletions api/notify/v1/generated.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions api/notify/v1/generated.proto

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

2 changes: 2 additions & 0 deletions api/notify/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ type MessageSpec struct {
AlarmPolicyType string `json:"alarmPolicyType,omitempty" protobuf:"bytes,10,opt,name=alarmPolicyType"`
// +optional
ReceiverChannelName string `json:"receiverChannelName,omitempty" protobuf:"bytes,11,opt,name=receiverChannelName"`
// +optional
ClusterID string `json:"clusterID,omitempty" protobuf:"bytes,12,opt,name=clusterID"`
}

// MessageStatus represents information about the status of a message.
Expand Down
2 changes: 2 additions & 0 deletions api/notify/v1/zz_generated.conversion.go

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

6 changes: 6 additions & 0 deletions api/openapi/zz_generated.openapi.go

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

10 changes: 10 additions & 0 deletions pkg/notify/controller/messagerequest/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ type sentMessage struct {
alarmPolicyName string
alarmPolicyType string
receiverChannelName string
clusterID string
}

func (c *Controller) sendMessage(ctx context.Context, messageRequest *v1.MessageRequest) (sentMessages []sentMessage, failedReceiverErrors map[string]string) {
Expand Down Expand Up @@ -359,13 +360,17 @@ func (c *Controller) sendMessage(ctx context.Context, messageRequest *v1.Message
var (
alarmPolicyName string
alarmPolicyType string
clusterID string
)
if v, ok := messageRequest.Spec.Variables["alarmPolicyName"]; ok {
alarmPolicyName = v
}
if v, ok := messageRequest.Spec.Variables["alarmPolicyType"]; ok {
alarmPolicyType = v
}
if v, ok := messageRequest.Spec.Variables["clusterID"]; ok {
clusterID = v
}
if channel.Spec.Webhook != nil && template.Spec.Text != nil {
content, err := webhook.Send(channel.Spec.Webhook, template.Spec.Text, receivers, messageRequest.Spec.Variables)
if err != nil {
Expand All @@ -380,6 +385,7 @@ func (c *Controller) sendMessage(ctx context.Context, messageRequest *v1.Message
alarmPolicyName: alarmPolicyName,
alarmPolicyType: alarmPolicyType,
receiverChannelName: channel.Name,
clusterID: clusterID,
})
return
}
Expand Down Expand Up @@ -412,6 +418,7 @@ func (c *Controller) sendMessage(ctx context.Context, messageRequest *v1.Message
alarmPolicyName: alarmPolicyName,
alarmPolicyType: alarmPolicyType,
receiverChannelName: channel.Name,
clusterID: clusterID,
})
}
if template.Spec.Wechat != nil {
Expand Down Expand Up @@ -440,6 +447,7 @@ func (c *Controller) sendMessage(ctx context.Context, messageRequest *v1.Message
alarmPolicyName: alarmPolicyName,
alarmPolicyType: alarmPolicyType,
receiverChannelName: channel.Name,
clusterID: clusterID,
})
}
if template.Spec.Text != nil {
Expand Down Expand Up @@ -468,6 +476,7 @@ func (c *Controller) sendMessage(ctx context.Context, messageRequest *v1.Message
alarmPolicyName: alarmPolicyName,
alarmPolicyType: alarmPolicyType,
receiverChannelName: channel.Name,
clusterID: clusterID,
})
}
if templateCount == 0 {
Expand Down Expand Up @@ -495,6 +504,7 @@ func (c *Controller) archiveMessage(ctx context.Context, messageRequest *v1.Mess
AlarmPolicyName: sentMessage.alarmPolicyName,
AlarmPolicyType: sentMessage.alarmPolicyType,
ReceiverChannelName: sentMessage.receiverChannelName,
ClusterID: sentMessage.clusterID,
},
Status: v1.MessageStatus{
Phase: v1.MessageUnread,
Expand Down
2 changes: 2 additions & 0 deletions pkg/notify/registry/message/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func MatchMessage(label labels.Selector, field fields.Selector) storage.Selectio
"spec.alarmPolicyName",
"spec.alarmPolicyType",
"spec.receiverChannelName",
"spec.clusterID",
},
}
}
Expand All @@ -157,6 +158,7 @@ func ToSelectableFields(message *notify.Message) fields.Set {
"spec.alarmPolicyName": message.Spec.AlarmPolicyName,
"spec.alarmPolicyType": message.Spec.AlarmPolicyType,
"spec.receiverChannelName": message.Spec.ReceiverChannelName,
"spec.clusterID": message.Spec.ClusterID,
}
return genericregistry.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet)
}
Expand Down

0 comments on commit 7914fd8

Please sign in to comment.