Skip to content

Commit

Permalink
Merge pull request #465 from yolgun/yolgun/send-deleted-event
Browse files Browse the repository at this point in the history
send an event when the cluster is deleted
  • Loading branch information
yolgun authored Sep 16, 2022
2 parents b5bcff3 + ec3aa6a commit f35654a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions controllers/flinkcluster/flinkcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (handler *FlinkClusterHandler) reconcile(ctx context.Context,
request: request,
context: context,
log: log,
recorder: handler.recorder,
history: history,
}
err = observer.observe(observed)
Expand Down
22 changes: 22 additions & 0 deletions controllers/flinkcluster/flinkcluster_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package flinkcluster
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"strings"
"time"

Expand Down Expand Up @@ -49,6 +51,7 @@ type ClusterStateObserver struct {
context context.Context
log logr.Logger
history history.Interface
recorder record.EventRecorder
}

// ObservedClusterState holds observed state of a cluster.
Expand Down Expand Up @@ -141,6 +144,7 @@ func (observer *ClusterStateObserver) observe(
return err
}
log.Info("Observed cluster", "cluster", "nil")
observer.sendDeletedEvent()
observedCluster = nil
} else {
log.Info("Observed cluster", "cluster", *observedCluster)
Expand Down Expand Up @@ -312,6 +316,24 @@ func (observer *ClusterStateObserver) observe(
return nil
}

func (observer *ClusterStateObserver) sendDeletedEvent() {
var eventCluster = &v1beta1.FlinkCluster{
TypeMeta: metav1.TypeMeta{
Kind: "FlinkCluster",
APIVersion: "flinkoperator.k8s.io/v1beta1",
},
ObjectMeta: metav1.ObjectMeta{
Name: observer.request.Name,
Namespace: observer.request.Namespace,
},
}
observer.recorder.Event(
eventCluster,
"Normal",
"StatusUpdate",
fmt.Sprintf("Cluster status: Deleted"))
}

func (observer *ClusterStateObserver) observeJob(
observed *ObservedClusterState) error {
// Either the cluster has been deleted or it is a session cluster.
Expand Down

0 comments on commit f35654a

Please sign in to comment.