Skip to content

Commit

Permalink
Add event for egress tunnel status changed (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
lou-lan committed Nov 24, 2023
1 parent 5751f5a commit 04076a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/controller/egress_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
k8serr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -81,6 +82,7 @@ type egReconciler struct {
allocatorV4 *ipallocator.Range
allocatorV6 *ipallocator.Range
initDone chan struct{}
recorder record.EventRecorder
}

func (r *egReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
Expand Down Expand Up @@ -629,6 +631,12 @@ func (r *egReconciler) tunnelListCheck(ctx context.Context) error {
r.log.Error(err, "update tunnel status to TunnelHeartbeatTimeout")
continue
}

r.recorder.Event(
tunnel, corev1.EventTypeNormal,
egressv1.ReasonStatusChanged,
"EgressTunnel status changes to HeartbeatTimeout.",
)
}
}
return nil
Expand Down Expand Up @@ -710,5 +718,7 @@ func newEgressTunnelController(mgr manager.Manager, log logr.Logger, cfg *config
return fmt.Errorf("failed to watch Node: %w", err)
}

r.recorder = mgr.GetEventRecorderFor("egress-tunnel")

return nil
}
2 changes: 2 additions & 0 deletions pkg/k8s/apis/v1beta1/egresstunnel_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const (
EgressTunnelReady EgressTunnelPhase = "Ready"
)

var ReasonStatusChanged = "StatusChanged"

func init() {
SchemeBuilder.Register(&EgressTunnel{}, &EgressTunnelList{})
}

1 comment on commit 04076a4

@weizhoublue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.