Skip to content

Commit

Permalink
fix: only add address as loadbalancerIP if svc type is LoadBalancer (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
winston0410 authored Jul 17, 2024
1 parent e1e7646 commit 56a609d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/controllers/wireguard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,7 @@ func (r *WireguardReconciler) serviceForWireguard(m *v1alpha1.Wireguard, service
Labels: labels,
},
Spec: corev1.ServiceSpec{
LoadBalancerIP: m.Spec.Address,
Selector: labels,
Selector: labels,
Ports: []corev1.ServicePort{{
Protocol: corev1.ProtocolUDP,
NodePort: m.Spec.NodePort,
Expand All @@ -696,6 +695,10 @@ func (r *WireguardReconciler) serviceForWireguard(m *v1alpha1.Wireguard, service
},
}

if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
svc.Spec.LoadBalancerIP = m.Spec.Address
}

if err := ctrl.SetControllerReference(m, svc, r.Scheme); err != nil {
return nil, fmt.Errorf("set controller reference: %w", err)
}
Expand Down

0 comments on commit 56a609d

Please sign in to comment.