Skip to content

Commit

Permalink
feat: add support for GCP IPv6 static IP configuration in Nginx contr…
Browse files Browse the repository at this point in the history
…oller
  • Loading branch information
infezek committed Jan 6, 2025
1 parent 6202cc8 commit a2bd313
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions controllers/nginx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,29 @@ func (r *NginxReconciler) reconcileNginx(ctx context.Context, nginx *nginxv1alph
if err := r.reconcileDeployment(ctx, nginx); err != nil {
return err
}

if err := r.reconcileService(ctx, nginx); err != nil {
return err
}

if err := r.reconcileIngress(ctx, nginx); err != nil {
return err
}

if err := r.reconcileGcpIpV6(ctx, nginx); err != nil {
return err
}
return nil
}

func (r *NginxReconciler) reconcileGcpIpV6(ctx context.Context, nginx *nginxv1alpha1.Nginx) error {
if nginx.Spec.Ingress.GCPIpV6StaticIPName == "" {
return nil
}
staticName := nginx.Spec.Ingress.GCPIpV6StaticIPName
newIngress := k8s.NewIngress(nginx)
newIngress.Annotations["kubernetes.io/ingress.global-static-ip-name"] = staticName
newIngress.Name = fmt.Sprintf("%s-ipv6", newIngress.Name)
return r.manageIngressLifecycle(ctx, newIngress, nginx)
}

func (r *NginxReconciler) reconcileDeployment(ctx context.Context, nginx *nginxv1alpha1.Nginx) error {
newDeploy, err := k8s.NewDeployment(nginx)
if err != nil {
Expand Down Expand Up @@ -233,13 +244,7 @@ func (r *NginxReconciler) reconcileService(ctx context.Context, nginx *nginxv1al
return nil
}

func (r *NginxReconciler) reconcileIngress(ctx context.Context, nginx *nginxv1alpha1.Nginx) error {
if nginx == nil {
return fmt.Errorf("nginx cannot be nil")
}

newIngress := k8s.NewIngress(nginx)

func (r *NginxReconciler) manageIngressLifecycle(ctx context.Context, newIngress *networkingv1.Ingress, nginx *nginxv1alpha1.Nginx) error {
var currentIngress networkingv1.Ingress
err := r.Client.Get(ctx, types.NamespacedName{Name: newIngress.Name, Namespace: newIngress.Namespace}, &currentIngress)
if errors.IsNotFound(err) {
Expand Down Expand Up @@ -272,6 +277,15 @@ func (r *NginxReconciler) reconcileIngress(ctx context.Context, nginx *nginxv1al
newIngress.Finalizers = currentIngress.Finalizers

return r.Client.Update(ctx, newIngress)

}

func (r *NginxReconciler) reconcileIngress(ctx context.Context, nginx *nginxv1alpha1.Nginx) error {
if nginx == nil {
return fmt.Errorf("nginx cannot be nil")
}
newIngress := k8s.NewIngress(nginx)
return r.manageIngressLifecycle(ctx, newIngress, nginx)
}

func shouldUpdateIngress(currentIngress, newIngress *networkingv1.Ingress) bool {
Expand Down

0 comments on commit a2bd313

Please sign in to comment.