Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions cmd/kops-controller/controllers/awsipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ func (r *AWSIPAMReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}

ipv6Address := aws.ToString(eni.NetworkInterfaces[0].Ipv6Prefixes[0].Ipv6Prefix)
if err := patchNodePodCIDRs(r.coreV1Client, ctx, node, ipv6Address); err != nil {
podCIDRs := []string{ipv6Address}
if err := patchNodePodCIDRs(r.coreV1Client, ctx, node, podCIDRs); err != nil {
return ctrl.Result{}, err
}
}
Expand All @@ -162,26 +163,28 @@ type nodePatchSpec struct {
PodCIDRs []string `json:"podCIDRs,omitempty"`
}

// patchNodePodCIDRs patches the node podCIDR to the specified value.
func patchNodePodCIDRs(client *corev1client.CoreV1Client, ctx context.Context, node *corev1.Node, cidr string) error {
klog.Infof("assigning cidr %q to node %q", cidr, node.ObjectMeta.Name)
// patchNodePodCIDRs patches the node podCIDRs to the specified value(s).
func patchNodePodCIDRs(client *corev1client.CoreV1Client, ctx context.Context, node *corev1.Node, podCIDRs []string) error {
klog.Infof("assigning podCIDRs %v to node %q", podCIDRs, node.ObjectMeta.Name)
nodePatchSpec := &nodePatchSpec{
PodCIDR: cidr,
PodCIDRs: []string{cidr},
PodCIDRs: podCIDRs,
}
if len(podCIDRs) > 0 {
nodePatchSpec.PodCIDR = podCIDRs[0]
}
nodePatch := &nodePatch{
Spec: nodePatchSpec,
}
nodePatchJson, err := json.Marshal(nodePatch)
if err != nil {
return fmt.Errorf("error building node patch: %v", err)
return fmt.Errorf("building node patch: %w", err)
}

klog.V(2).Infof("sending patch for node %q: %q", node.Name, string(nodePatchJson))

_, err = client.Nodes().Patch(ctx, node.Name, types.StrategicMergePatchType, nodePatchJson, metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("error applying patch to node: %v", err)
return fmt.Errorf("applying patch to node: %w", err)
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion cmd/kops-controller/controllers/gceipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func (r *GCEIPAMReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}

ipv6Address := ipv6Addresses[0]
if err := patchNodePodCIDRs(r.coreV1Client, ctx, node, ipv6Address); err != nil {
podCIDRs := []string{ipv6Address}
if err := patchNodePodCIDRs(r.coreV1Client, ctx, node, podCIDRs); err != nil {
return ctrl.Result{}, err
}
}
Expand Down