Skip to content

Commit 5ddeea2

Browse files
committed
bump to v0.1.1
1 parent daff420 commit 5ddeea2

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

charts/tke-extend-network-controller/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.1.0
18+
version: 0.1.1
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.1.0"
24+
appVersion: "0.1.1"

cmd/app/manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func runManager() {
6868
Client: mgr.GetClient(),
6969
Scheme: mgr.GetScheme(),
7070
APIReader: mgr.GetAPIReader(),
71+
Recorder: mgr.GetEventRecorderFor("dedicatedclblistener-controller"),
7172
}).SetupWithManager(mgr); err != nil {
7273
setupLog.Error(err, "unable to create controller", "controller", "CLBListenerReconciler")
7374
os.Exit(1)

internal/controller/dedicatedclblistener_controller.go

+28-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
apierrors "k8s.io/apimachinery/pkg/api/errors"
2727
"k8s.io/apimachinery/pkg/runtime"
2828
"k8s.io/apimachinery/pkg/types"
29+
"k8s.io/client-go/tools/record"
2930
ctrl "sigs.k8s.io/controller-runtime"
3031
"sigs.k8s.io/controller-runtime/pkg/builder"
3132
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -47,6 +48,7 @@ type DedicatedCLBListenerReconciler struct {
4748
client.Client
4849
Scheme *runtime.Scheme
4950
APIReader client.Reader
51+
Recorder record.EventRecorder
5052
}
5153

5254
// +kubebuilder:rbac:groups=networking.cloud.tencent.com,resources=dedicatedclblisteners,verbs=get;list;watch;create;update;patch;delete
@@ -76,6 +78,7 @@ func (r *DedicatedCLBListenerReconciler) Reconcile(ctx context.Context, req ctrl
7678
lis.Status.State = networkingv1alpha1.DedicatedCLBListenerStatePending
7779
if err := r.Status().Update(ctx, lis); err != nil {
7880
log.Error(err, "failed to update status to Pending")
81+
r.Recorder.Event(lis, corev1.EventTypeWarning, "UpdateStatusFailed", err.Error())
7982
return ctrl.Result{}, err
8083
}
8184
}
@@ -86,6 +89,7 @@ func (r *DedicatedCLBListenerReconciler) Reconcile(ctx context.Context, req ctrl
8689
if !controllerutil.ContainsFinalizer(lis, finalizerName) && controllerutil.AddFinalizer(lis, finalizerName) {
8790
if err := r.Update(ctx, lis); err != nil {
8891
log.Error(err, "failed to add finalizer")
92+
r.Recorder.Event(lis, corev1.EventTypeWarning, "AddFinalizerFailed", err.Error())
8993
}
9094
}
9195
if err := r.sync(ctx, log, lis); err != nil {
@@ -355,9 +359,12 @@ func (r *DedicatedCLBListenerReconciler) ensureListener(ctx context.Context, log
355359
// 监听器已创建,检查监听器
356360
listenerId := lis.Status.ListenerId
357361
if listenerId == "" { // 不应该没有监听器ID,重建监听器
358-
log.Info("listener id not found from status, try to recreate", "state", lis.Status.State)
362+
msg := fmt.Sprintf("listener is %s state but no id not found in status, try to recreate", lis.Status.State)
363+
log.Info(msg)
364+
r.Recorder.Event(lis, corev1.EventTypeWarning, "ListenerIDNotFound", msg)
359365
lis.Status.State = networkingv1alpha1.DedicatedCLBListenerStatePending
360366
if err := r.Status().Update(ctx, lis); err != nil {
367+
r.Recorder.Event(lis, corev1.EventTypeWarning, "UpdateStatusFailed", err.Error())
361368
return err
362369
}
363370
return r.createListener(ctx, log, lis)
@@ -366,16 +373,22 @@ func (r *DedicatedCLBListenerReconciler) ensureListener(ctx context.Context, log
366373
log.V(5).Info("ensure listener", "listenerId", listenerId)
367374
listener, err := clb.GetListenerByPort(ctx, lis.Spec.LbRegion, lis.Spec.LbId, lis.Spec.LbPort, lis.Spec.Protocol)
368375
if err != nil {
376+
r.Recorder.Event(lis, corev1.EventTypeWarning, "GetListenerByPort", err.Error())
369377
return err
370378
}
371379
if listener == nil { // 监听器不存在,重建监听器
372-
log.Info("listener not found, try to recreate", "listenerId", listenerId)
380+
msg := "listener not found, try to recreate"
381+
log.Info(msg, "listenerId", listenerId)
382+
r.Recorder.Event(lis, corev1.EventTypeWarning, "ListenerNotFound", msg)
373383
return r.createListener(ctx, log, lis)
374384
}
375385
if listener.ListenerId != listenerId { // 监听器ID不匹配,更新监听器ID
376-
log.Info("listener id not match, update listenerId in status", "realListenerId", listener.ListenerId)
386+
msg := fmt.Sprintf("listener id from status (%s) is not equal with the real listener id (%s)", listenerId, listener.ListenerId)
387+
log.Info(msg)
388+
r.Recorder.Event(lis, corev1.EventTypeWarning, "ListenerIdNotMatch", msg)
377389
lis.Status.ListenerId = listener.ListenerId
378390
if err := r.Status().Update(ctx, lis); err != nil {
391+
r.Recorder.Event(lis, corev1.EventTypeWarning, "UpdateStatusFailed", err.Error())
379392
return err
380393
}
381394
}
@@ -390,36 +403,46 @@ func (r *DedicatedCLBListenerReconciler) createListener(ctx context.Context, log
390403
if apierrors.IsNotFound(err) {
391404
config = nil
392405
} else {
406+
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
393407
return err
394408
}
395409
}
396410
}
397411
existedLis, err := clb.GetListenerByPort(ctx, lis.Spec.LbRegion, lis.Spec.LbId, lis.Spec.LbPort, lis.Spec.Protocol)
398412
if err != nil {
413+
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
399414
return err
400415
}
401416
var listenerId string
402417
if existedLis != nil { // 端口冲突,如果是控制器创建的,则直接复用,如果不是,则报错引导用户人工确认手动清理冲突的监听器(避免直接重建误删用户有用的监听器)
403418
log = log.WithValues("listenerId", existedLis.ListenerId, "port", lis.Spec.LbPort, "protocol", lis.Spec.Protocol)
404419
log.Info("lb port already existed", "listenerName", existedLis.ListenerName)
405420
if existedLis.ListenerName == clb.TkePodListenerName { // 已经创建了,直接复用
406-
log.Info("reuse already existed listener")
421+
msg := "reuse already existed listener"
422+
log.Info(msg)
423+
r.Recorder.Event(lis, corev1.EventTypeNormal, "CreateListener", msg)
407424
listenerId = existedLis.ListenerId
408425
} else {
409426
err = errors.New("lb port already existed, but not created by tke, please confirm and delete the conficted listener manually")
410427
log.Error(err, "listenerName", existedLis.ListenerName)
428+
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
411429
return err
412430
}
413431
} else { // 没有端口冲突,创建监听器
414432
log.V(5).Info("try to create listener")
415433
id, err := clb.CreateListener(ctx, lis.Spec.LbRegion, config.Spec.CreateListenerRequest(lis.Spec.LbId, lis.Spec.LbPort, lis.Spec.Protocol))
416434
if err != nil {
435+
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
417436
return err
418437
}
438+
msg := "listener successfully created"
419439
log.V(5).Info("listener successfully created", "listenerId", id)
440+
r.Recorder.Event(lis, corev1.EventTypeNormal, "CreateListener", msg)
420441
listenerId = id
421442
}
422-
log.V(5).Info("listener ready, set state to available")
443+
msg := "listener ready, set state to available"
444+
log.V(5).Info(msg)
445+
r.Recorder.Event(lis, corev1.EventTypeNormal, "UpdateStatus", msg)
423446
lis.Status.State = networkingv1alpha1.DedicatedCLBListenerStateAvailable
424447
lis.Status.ListenerId = listenerId
425448
return r.Status().Update(ctx, lis)

0 commit comments

Comments
 (0)