Skip to content

Commit ea4d6ff

Browse files
authored
Merge pull request #717 from l1b0k/main
controlplane: fix re config logic
2 parents 20d402f + 93ca405 commit ea4d6ff

File tree

1 file changed

+1
-84
lines changed

1 file changed

+1
-84
lines changed

Diff for: pkg/controller/pod/pod_controller.go

+1-84
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,6 @@ func (m *ReconcilePod) parse(ctx context.Context, pod *corev1.Pod, node *corev1.
503503
// 1. update pod uid
504504
// 2. re-generate the target spec
505505
func (m *ReconcilePod) reConfig(ctx context.Context, pod *corev1.Pod, prePodENI *v1beta1.PodENI) (reconcile.Result, error) {
506-
l := log.FromContext(ctx).WithName("re-config")
507-
508506
update := prePodENI.DeepCopy()
509507

510508
if prePodENI.Labels[types.ENIRelatedNodeName] != "" {
@@ -535,88 +533,7 @@ func (m *ReconcilePod) reConfig(ctx context.Context, pod *corev1.Pod, prePodENI
535533
}
536534
update.Annotations[types.PodUID] = string(pod.UID)
537535

538-
if pod.Annotations[types.PodNetworking] != "" {
539-
l.V(5).Info("using podNetworking will not re-config", types.PodNetworking, pod.Annotations[types.PodNetworking])
540-
err := m.client.Update(ctx, update)
541-
542-
return reconcile.Result{Requeue: true}, err
543-
}
544-
545-
if _, ok := prePodENI.Annotations[types.ENIAllocFromPool]; ok {
546-
err := m.client.Update(ctx, update)
547-
548-
return reconcile.Result{Requeue: true}, err
549-
}
550-
551-
// TODO check and update podENI spec
552-
anno, err := controlplane.ParsePodNetworksFromAnnotation(pod)
553-
if err != nil {
554-
return reconcile.Result{}, err
555-
}
556-
557-
targets := make(map[string]int, len(anno.PodNetworks))
558-
for i, n := range anno.PodNetworks {
559-
name := n.Interface
560-
if name == "" {
561-
name = defaultInterface
562-
}
563-
targets[name] = i
564-
}
565-
566-
// del unexpected config
567-
for i := range update.Spec.Allocations {
568-
alloc := update.Spec.Allocations[i]
569-
name := alloc.Interface
570-
if name == "" {
571-
name = defaultInterface
572-
}
573-
574-
if _, ok := targets[name]; ok {
575-
delete(targets, name)
576-
continue
577-
}
578-
delete(targets, name)
579-
l.Info("changed remove eni", "if", name, "eni", alloc.ENI.ID)
580-
581-
if alloc.ENI.ID != "" {
582-
err = m.aliyun.DeleteNetworkInterface(common.WithCtx(context.Background(), &alloc), alloc.ENI.ID)
583-
if err != nil {
584-
m.record.Eventf(prePodENI, corev1.EventTypeWarning, types.EventDeleteENIFailed, err.Error())
585-
return reconcile.Result{}, err
586-
}
587-
}
588-
update.Spec.Allocations = append(update.Spec.Allocations[:i], update.Spec.Allocations[i+1:]...)
589-
}
590-
591-
allocType, err := controlplane.ParsePodIPTypeFromAnnotation(pod)
592-
if err != nil {
593-
return reconcile.Result{}, err
594-
}
595-
// add new config
596-
newAnno := &controlplane.PodNetworksAnnotation{}
597-
for _, i := range targets {
598-
newAnno.PodNetworks = append(newAnno.PodNetworks, anno.PodNetworks[i])
599-
}
600-
601-
node, err := m.getNode(ctx, pod.Spec.NodeName)
602-
if err != nil {
603-
return reconcile.Result{}, fmt.Errorf("error get node %s, %w", node.Name, err)
604-
}
605-
nodeInfo, err := common.NewNodeInfo(node)
606-
if err != nil {
607-
return reconcile.Result{}, err
608-
}
609-
610-
allocs, err := m.ParsePodNetworksFromAnnotation(ctx, nodeInfo.ZoneID, newAnno)
611-
if err != nil {
612-
return reconcile.Result{}, err
613-
}
614-
615-
err = m.createENI(ctx, &allocs, allocType, pod, update)
616-
if err != nil {
617-
return reconcile.Result{}, err
618-
}
619-
err = m.client.Update(ctx, update)
536+
err := m.client.Update(ctx, update)
620537

621538
return reconcile.Result{Requeue: true}, err
622539
}

0 commit comments

Comments
 (0)