Skip to content

Commit

Permalink
Merge pull request #2155 from spidernet-io/robot/cherrypick/pr2152/re…
Browse files Browse the repository at this point in the history
…lease-v0.6

title:	clean up spidercoordinator.status if phase is NotReady
  • Loading branch information
weizhoublue authored Aug 8, 2023
2 parents 15be3f6 + ebe3760 commit e56362b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
8 changes: 7 additions & 1 deletion cmd/spiderpool-agent/cmd/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ package cmd

import (
"fmt"

"github.com/go-openapi/runtime/middleware"
"github.com/spidernet-io/spiderpool/api/v1/agent/models"
"github.com/spidernet-io/spiderpool/api/v1/agent/server/restapi/daemonset"
"github.com/spidernet-io/spiderpool/pkg/constant"
"github.com/spidernet-io/spiderpool/pkg/coordinatormanager"
spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
corev1 "k8s.io/api/core/v1"
)
Expand All @@ -31,6 +33,11 @@ func (g *_unixGetCoordinatorConfig) Handle(params daemonset.GetCoordinatorConfig
if len(coordList.Items) == 0 {
return daemonset.NewGetCoordinatorConfigFailure().WithPayload(models.Error("coordinator config not found"))
}
coord := coordList.Items[0]

if coord.Status.Phase != coordinatormanager.Synced {
return daemonset.NewGetCoordinatorConfigFailure().WithPayload(models.Error(fmt.Sprintf("spidercoordinator: %s no ready", coord.Name)))
}

var pod *corev1.Pod
var err error
Expand All @@ -39,7 +46,6 @@ func (g *_unixGetCoordinatorConfig) Handle(params daemonset.GetCoordinatorConfig
return daemonset.NewGetCoordinatorConfigFailure().WithPayload(models.Error(fmt.Sprintf("failed to get coordinator config: pod %s/%s not found", params.GetCoordinatorConfig.PodNamespace, params.GetCoordinatorConfig.PodName)))
}

coord := coordList.Items[0]
var prefix string
if coord.Spec.PodMACPrefix != nil {
prefix = *coord.Spec.PodMACPrefix
Expand Down
4 changes: 2 additions & 2 deletions pkg/coordinatormanager/calico_ippool_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (r *calicoIPPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{Requeue: true}, err
}

if coordinator.Status.Phase == synced && reflect.DeepEqual(coordinator.Status.OverlayPodCIDR, podCIDR) {
if coordinator.Status.Phase == Synced && reflect.DeepEqual(coordinator.Status.OverlayPodCIDR, podCIDR) {
return ctrl.Result{}, nil
}

origin := coordinator.DeepCopy()
coordinator.Status.Phase = synced
coordinator.Status.Phase = Synced
coordinator.Status.OverlayPodCIDR = podCIDR
if err := r.client.Status().Patch(ctx, &coordinator, client.MergeFrom(origin)); err != nil {
return ctrl.Result{Requeue: true}, err
Expand Down
38 changes: 24 additions & 14 deletions pkg/coordinatormanager/coordinator_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const (
)

const (
notReady = "NotReady"
synced = "Synced"
NotReady = "NotReady"
Synced = "Synced"
)

const messageEnqueueCoordiantor = "Enqueue Coordinator"
Expand Down Expand Up @@ -314,8 +314,10 @@ func (cc *CoordinatorController) syncHandler(ctx context.Context, coordinatorNam
err.Error(),
)

if coordCopy.Status.Phase != notReady {
coordCopy.Status.Phase = notReady
if coordCopy.Status.Phase != NotReady {
coordCopy.Status.Phase = NotReady
coordCopy.Status.OverlayPodCIDR = []string{}
coordCopy.Status.ServiceCIDR = []string{}
if err := cc.Client.Status().Patch(ctx, coordCopy, client.MergeFrom(coord)); err != nil {
return err
}
Expand All @@ -332,8 +334,10 @@ func (cc *CoordinatorController) syncHandler(ctx context.Context, coordinatorNam
msg,
)

if coordCopy.Status.Phase != notReady {
coordCopy.Status.Phase = notReady
if coordCopy.Status.Phase != NotReady {
coordCopy.Status.Phase = NotReady
coordCopy.Status.OverlayPodCIDR = []string{}
coordCopy.Status.ServiceCIDR = []string{}
if err := cc.Client.Status().Patch(ctx, coordCopy, client.MergeFrom(coord)); err != nil {
return err
}
Expand All @@ -349,7 +353,7 @@ func (cc *CoordinatorController) syncHandler(ctx context.Context, coordinatorNam
cc.caliCtrlCanncel()
cc.caliCtrlCanncel = nil
}
coordCopy.Status.Phase = synced
coordCopy.Status.Phase = Synced
coordCopy.Status.OverlayPodCIDR = k8sPodCIDR
case calico:
if _, err := cc.ConfigmapLister.ConfigMaps(metav1.NamespaceSystem).Get(calicoConfig); err != nil {
Expand All @@ -361,8 +365,10 @@ func (cc *CoordinatorController) syncHandler(ctx context.Context, coordinatorNam
"Calico needs to be installed first",
)
}
if coordCopy.Status.Phase != notReady {
coordCopy.Status.Phase = notReady
if coordCopy.Status.Phase != NotReady {
coordCopy.Status.Phase = NotReady
coordCopy.Status.OverlayPodCIDR = []string{}
coordCopy.Status.ServiceCIDR = []string{}
if err := cc.Client.Status().Patch(ctx, coordCopy, client.MergeFrom(coord)); err != nil {
return err
}
Expand Down Expand Up @@ -407,8 +413,10 @@ func (cc *CoordinatorController) syncHandler(ctx context.Context, coordinatorNam
"Cilium needs to be installed first",
)
}
if coordCopy.Status.Phase != notReady {
coordCopy.Status.Phase = notReady
if coordCopy.Status.Phase != NotReady {
coordCopy.Status.Phase = NotReady
coordCopy.Status.OverlayPodCIDR = []string{}
coordCopy.Status.ServiceCIDR = []string{}
if err := cc.Client.Status().Patch(ctx, coordCopy, client.MergeFrom(coord)); err != nil {
return err
}
Expand All @@ -418,15 +426,17 @@ func (cc *CoordinatorController) syncHandler(ctx context.Context, coordinatorNam
ipam, ciliumPodCIDR, err := extractCiliumCIDR(ccm)
if err != nil {
logger.Sugar().Warnf("Failed to gather Pod CIDR form Cilium: %v", err)
if coordCopy.Status.Phase != notReady {
coordCopy.Status.Phase = notReady
if coordCopy.Status.Phase != NotReady {
coordCopy.Status.Phase = NotReady
coordCopy.Status.OverlayPodCIDR = []string{}
coordCopy.Status.ServiceCIDR = []string{}
if err := cc.Client.Status().Patch(ctx, coordCopy, client.MergeFrom(coord)); err != nil {
return err
}
}
break
}
coordCopy.Status.Phase = synced
coordCopy.Status.Phase = Synced
coordCopy.Status.OverlayPodCIDR = ciliumPodCIDR
if ipam == "kubernetes" {
coordCopy.Status.OverlayPodCIDR = k8sPodCIDR
Expand Down

0 comments on commit e56362b

Please sign in to comment.