Skip to content

Commit

Permalink
chore: opt circuirbreaker controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Eikykun committed Nov 16, 2023
1 parent 683e5f8 commit da14eba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
4 changes: 1 addition & 3 deletions pkg/manager/controllers/circuitbreaker/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"
)

var (
Expand Down Expand Up @@ -96,7 +94,7 @@ func newDeleteProcessor(c client.Client, ctx context.Context) *deleteProcessor {
if po.DeletionTimestamp != nil {
return nil
}
return deletePodConfig(ctx, &proto.CircuitBreaker{Name: item.ConfigName}, po.Status.PodIP)
return disableConfig(ctx, po.Status.PodIP, item.ConfigName)
},
}
go processor.processLoop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *CircuitBreakerReconciler) Reconcile(ctx context.Context, req ctrl.Reque
defaultPodConfigCache.Delete(po.Namespace, po.Name)
continue
}
if err := deletePodConfig(ctx, &proto.CircuitBreaker{Name: cb.Name}, st.PodIP); err != nil {
if err := disableConfig(ctx, st.PodIP, cb.Name); err != nil {
reconcileErr = errors.Join(reconcileErr, err)
klog.Errorf("failed to delete config in pod %s, %v", st.PodName, err)
failedStatus = append(failedStatus, cb.Status.TargetStatus[i])
Expand Down Expand Up @@ -187,21 +187,6 @@ func (r *CircuitBreakerReconciler) syncPodConfig(ctx context.Context, cb *proto.
return resp.Msg.LimitingSnapshot, nil
}

func deletePodConfig(ctx context.Context, cb *proto.CircuitBreaker, podIp string) error {
cb.Option = proto.CircuitBreaker_DELETE
resp, err := protoClient(podIp).SendConfig(ctx, connect.NewRequest(cb))
if err != nil {
return err
}
if resp.Msg == nil {
return fmt.Errorf("fail to update pod [%s, %s] circuit breaker config, server return nil response", podIp, cb.Name)
}
if resp != nil && !resp.Msg.Success {
return fmt.Errorf("fail to update pod [%s, %s] circuit breaker config, %s", podIp, cb.Name, resp.Msg.Message)
}
return nil
}

func (r *CircuitBreakerReconciler) currentPodStatus(cb *ctrlmeshv1alpha1.CircuitBreaker, podName string) *ctrlmeshv1alpha1.TargetStatus {
for i, state := range cb.Status.TargetStatus {
if state.PodName == podName {
Expand Down Expand Up @@ -269,7 +254,7 @@ func (r *CircuitBreakerReconciler) clear(ctx context.Context, cb *ctrlmeshv1alph
continue
}

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

func (r *CircuitBreakerReconciler) disableConfig(ctx context.Context, podIp string, name string) error {
func disableConfig(ctx context.Context, podIp string, name string) error {
req := &proto.CircuitBreaker{
Option: proto.CircuitBreaker_DELETE,
Name: name,
Expand Down

0 comments on commit da14eba

Please sign in to comment.