Skip to content

Commit da14eba

Browse files
committed
chore: opt circuirbreaker controller
1 parent 683e5f8 commit da14eba

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

pkg/manager/controllers/circuitbreaker/cache.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import (
2626
"k8s.io/apimachinery/pkg/util/sets"
2727
"k8s.io/client-go/util/workqueue"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
29-
30-
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"
3129
)
3230

3331
var (
@@ -96,7 +94,7 @@ func newDeleteProcessor(c client.Client, ctx context.Context) *deleteProcessor {
9694
if po.DeletionTimestamp != nil {
9795
return nil
9896
}
99-
return deletePodConfig(ctx, &proto.CircuitBreaker{Name: item.ConfigName}, po.Status.PodIP)
97+
return disableConfig(ctx, po.Status.PodIP, item.ConfigName)
10098
},
10199
}
102100
go processor.processLoop()

pkg/manager/controllers/circuitbreaker/circuitbreaker_controller.go

+3-18
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (r *CircuitBreakerReconciler) Reconcile(ctx context.Context, req ctrl.Reque
144144
defaultPodConfigCache.Delete(po.Namespace, po.Name)
145145
continue
146146
}
147-
if err := deletePodConfig(ctx, &proto.CircuitBreaker{Name: cb.Name}, st.PodIP); err != nil {
147+
if err := disableConfig(ctx, st.PodIP, cb.Name); err != nil {
148148
reconcileErr = errors.Join(reconcileErr, err)
149149
klog.Errorf("failed to delete config in pod %s, %v", st.PodName, err)
150150
failedStatus = append(failedStatus, cb.Status.TargetStatus[i])
@@ -187,21 +187,6 @@ func (r *CircuitBreakerReconciler) syncPodConfig(ctx context.Context, cb *proto.
187187
return resp.Msg.LimitingSnapshot, nil
188188
}
189189

190-
func deletePodConfig(ctx context.Context, cb *proto.CircuitBreaker, podIp string) error {
191-
cb.Option = proto.CircuitBreaker_DELETE
192-
resp, err := protoClient(podIp).SendConfig(ctx, connect.NewRequest(cb))
193-
if err != nil {
194-
return err
195-
}
196-
if resp.Msg == nil {
197-
return fmt.Errorf("fail to update pod [%s, %s] circuit breaker config, server return nil response", podIp, cb.Name)
198-
}
199-
if resp != nil && !resp.Msg.Success {
200-
return fmt.Errorf("fail to update pod [%s, %s] circuit breaker config, %s", podIp, cb.Name, resp.Msg.Message)
201-
}
202-
return nil
203-
}
204-
205190
func (r *CircuitBreakerReconciler) currentPodStatus(cb *ctrlmeshv1alpha1.CircuitBreaker, podName string) *ctrlmeshv1alpha1.TargetStatus {
206191
for i, state := range cb.Status.TargetStatus {
207192
if state.PodName == podName {
@@ -269,7 +254,7 @@ func (r *CircuitBreakerReconciler) clear(ctx context.Context, cb *ctrlmeshv1alph
269254
continue
270255
}
271256

272-
if localErr := r.disableConfig(ctx, state.PodIP, cb.Name); localErr != nil {
257+
if localErr := disableConfig(ctx, state.PodIP, cb.Name); localErr != nil {
273258
err = errors.Join(err, localErr)
274259
} else {
275260
defaultPodConfigCache.Delete(cb.Namespace, state.PodName, cb.Name)
@@ -278,7 +263,7 @@ func (r *CircuitBreakerReconciler) clear(ctx context.Context, cb *ctrlmeshv1alph
278263
return err
279264
}
280265

281-
func (r *CircuitBreakerReconciler) disableConfig(ctx context.Context, podIp string, name string) error {
266+
func disableConfig(ctx context.Context, podIp string, name string) error {
282267
req := &proto.CircuitBreaker{
283268
Option: proto.CircuitBreaker_DELETE,
284269
Name: name,

0 commit comments

Comments
 (0)