Skip to content

Commit

Permalink
bump to v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Aug 9, 2024
1 parent daff420 commit 5ddeea2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions charts/tke-extend-network-controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
version: 0.1.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.0"
appVersion: "0.1.1"
1 change: 1 addition & 0 deletions cmd/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func runManager() {
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
APIReader: mgr.GetAPIReader(),
Recorder: mgr.GetEventRecorderFor("dedicatedclblistener-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CLBListenerReconciler")
os.Exit(1)
Expand Down
33 changes: 28 additions & 5 deletions internal/controller/dedicatedclblistener_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -47,6 +48,7 @@ type DedicatedCLBListenerReconciler struct {
client.Client
Scheme *runtime.Scheme
APIReader client.Reader
Recorder record.EventRecorder
}

// +kubebuilder:rbac:groups=networking.cloud.tencent.com,resources=dedicatedclblisteners,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -76,6 +78,7 @@ func (r *DedicatedCLBListenerReconciler) Reconcile(ctx context.Context, req ctrl
lis.Status.State = networkingv1alpha1.DedicatedCLBListenerStatePending
if err := r.Status().Update(ctx, lis); err != nil {
log.Error(err, "failed to update status to Pending")
r.Recorder.Event(lis, corev1.EventTypeWarning, "UpdateStatusFailed", err.Error())
return ctrl.Result{}, err
}
}
Expand All @@ -86,6 +89,7 @@ func (r *DedicatedCLBListenerReconciler) Reconcile(ctx context.Context, req ctrl
if !controllerutil.ContainsFinalizer(lis, finalizerName) && controllerutil.AddFinalizer(lis, finalizerName) {
if err := r.Update(ctx, lis); err != nil {
log.Error(err, "failed to add finalizer")
r.Recorder.Event(lis, corev1.EventTypeWarning, "AddFinalizerFailed", err.Error())
}
}
if err := r.sync(ctx, log, lis); err != nil {
Expand Down Expand Up @@ -355,9 +359,12 @@ func (r *DedicatedCLBListenerReconciler) ensureListener(ctx context.Context, log
// 监听器已创建,检查监听器
listenerId := lis.Status.ListenerId
if listenerId == "" { // 不应该没有监听器ID,重建监听器
log.Info("listener id not found from status, try to recreate", "state", lis.Status.State)
msg := fmt.Sprintf("listener is %s state but no id not found in status, try to recreate", lis.Status.State)
log.Info(msg)
r.Recorder.Event(lis, corev1.EventTypeWarning, "ListenerIDNotFound", msg)
lis.Status.State = networkingv1alpha1.DedicatedCLBListenerStatePending
if err := r.Status().Update(ctx, lis); err != nil {
r.Recorder.Event(lis, corev1.EventTypeWarning, "UpdateStatusFailed", err.Error())
return err
}
return r.createListener(ctx, log, lis)
Expand All @@ -366,16 +373,22 @@ func (r *DedicatedCLBListenerReconciler) ensureListener(ctx context.Context, log
log.V(5).Info("ensure listener", "listenerId", listenerId)
listener, err := clb.GetListenerByPort(ctx, lis.Spec.LbRegion, lis.Spec.LbId, lis.Spec.LbPort, lis.Spec.Protocol)
if err != nil {
r.Recorder.Event(lis, corev1.EventTypeWarning, "GetListenerByPort", err.Error())
return err
}
if listener == nil { // 监听器不存在,重建监听器
log.Info("listener not found, try to recreate", "listenerId", listenerId)
msg := "listener not found, try to recreate"
log.Info(msg, "listenerId", listenerId)
r.Recorder.Event(lis, corev1.EventTypeWarning, "ListenerNotFound", msg)
return r.createListener(ctx, log, lis)
}
if listener.ListenerId != listenerId { // 监听器ID不匹配,更新监听器ID
log.Info("listener id not match, update listenerId in status", "realListenerId", listener.ListenerId)
msg := fmt.Sprintf("listener id from status (%s) is not equal with the real listener id (%s)", listenerId, listener.ListenerId)
log.Info(msg)
r.Recorder.Event(lis, corev1.EventTypeWarning, "ListenerIdNotMatch", msg)
lis.Status.ListenerId = listener.ListenerId
if err := r.Status().Update(ctx, lis); err != nil {
r.Recorder.Event(lis, corev1.EventTypeWarning, "UpdateStatusFailed", err.Error())
return err
}
}
Expand All @@ -390,36 +403,46 @@ func (r *DedicatedCLBListenerReconciler) createListener(ctx context.Context, log
if apierrors.IsNotFound(err) {
config = nil
} else {
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
return err
}
}
}
existedLis, err := clb.GetListenerByPort(ctx, lis.Spec.LbRegion, lis.Spec.LbId, lis.Spec.LbPort, lis.Spec.Protocol)
if err != nil {
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
return err
}
var listenerId string
if existedLis != nil { // 端口冲突,如果是控制器创建的,则直接复用,如果不是,则报错引导用户人工确认手动清理冲突的监听器(避免直接重建误删用户有用的监听器)
log = log.WithValues("listenerId", existedLis.ListenerId, "port", lis.Spec.LbPort, "protocol", lis.Spec.Protocol)
log.Info("lb port already existed", "listenerName", existedLis.ListenerName)
if existedLis.ListenerName == clb.TkePodListenerName { // 已经创建了,直接复用
log.Info("reuse already existed listener")
msg := "reuse already existed listener"
log.Info(msg)
r.Recorder.Event(lis, corev1.EventTypeNormal, "CreateListener", msg)
listenerId = existedLis.ListenerId
} else {
err = errors.New("lb port already existed, but not created by tke, please confirm and delete the conficted listener manually")
log.Error(err, "listenerName", existedLis.ListenerName)
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
return err
}
} else { // 没有端口冲突,创建监听器
log.V(5).Info("try to create listener")
id, err := clb.CreateListener(ctx, lis.Spec.LbRegion, config.Spec.CreateListenerRequest(lis.Spec.LbId, lis.Spec.LbPort, lis.Spec.Protocol))
if err != nil {
r.Recorder.Event(lis, corev1.EventTypeWarning, "CreateListener", err.Error())
return err
}
msg := "listener successfully created"
log.V(5).Info("listener successfully created", "listenerId", id)
r.Recorder.Event(lis, corev1.EventTypeNormal, "CreateListener", msg)
listenerId = id
}
log.V(5).Info("listener ready, set state to available")
msg := "listener ready, set state to available"
log.V(5).Info(msg)
r.Recorder.Event(lis, corev1.EventTypeNormal, "UpdateStatus", msg)
lis.Status.State = networkingv1alpha1.DedicatedCLBListenerStateAvailable
lis.Status.ListenerId = listenerId
return r.Status().Update(ctx, lis)
Expand Down

0 comments on commit 5ddeea2

Please sign in to comment.