Skip to content

Commit

Permalink
fix(notify): remove not exist receivers in receiver group (#1110)
Browse files Browse the repository at this point in the history
Signed-off-by: Feng Kun <[email protected]>
  • Loading branch information
kevinfeng authored Mar 3, 2021
1 parent 8babfed commit 013e7e8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/notify/registry/receivergroup/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -58,7 +60,7 @@ func (Strategy) DefaultGarbageCollectionPolicy(ctx context.Context) rest.Garbage

// PrepareForUpdate is invoked on update before validation to normalize the
// object.
func (Strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
func (s *Strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
oldReceiverGroup := old.(*notify.ReceiverGroup)
receiverGroup, _ := obj.(*notify.ReceiverGroup)
_, tenantID := authentication.UsernameAndTenantID(ctx)
Expand All @@ -72,6 +74,16 @@ func (Strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
if receiverGroup.Name == "" && receiverGroup.GenerateName == "" {
receiverGroup.GenerateName = "recvgrp-"
}
receivers := []string{}
for _, receiverName := range receiverGroup.Spec.Receivers {
receiver, err := s.notifyClient.Receivers().Get(ctx, receiverName, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
continue
} else {
receivers = append(receivers, receiver.Name)
}
}
receiverGroup.Spec.Receivers = receivers
}

// NamespaceScoped is false for receiverGroups.
Expand Down

0 comments on commit 013e7e8

Please sign in to comment.