From 8dc067271858ba8ebe7b0b534dc37ec344a6c75f Mon Sep 17 00:00:00 2001 From: Dario Tranchitella Date: Thu, 13 Apr 2023 14:39:20 +0200 Subject: [PATCH] fix: updating ingress status with provided loadbalancer ip --- .../kamaji_v1alpha1_tenantcontrolplane.yaml | 14 +++++------ internal/resources/k8s_ingress_resource.go | 25 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/config/samples/kamaji_v1alpha1_tenantcontrolplane.yaml b/config/samples/kamaji_v1alpha1_tenantcontrolplane.yaml index d88b2b6..eba8ac4 100644 --- a/config/samples/kamaji_v1alpha1_tenantcontrolplane.yaml +++ b/config/samples/kamaji_v1alpha1_tenantcontrolplane.yaml @@ -1,22 +1,22 @@ apiVersion: kamaji.clastix.io/v1alpha1 kind: TenantControlPlane metadata: - name: test + name: k8s-126 spec: controlPlane: deployment: - replicas: 1 + replicas: 2 service: serviceType: LoadBalancer kubernetes: - version: "v1.25.4" + version: "v1.26.0" kubelet: - cgroupfs: cgroupfs - admissionControllers: - - ResourceQuota - - LimitRanger + cgroupfs: systemd networkProfile: port: 6443 addons: coreDNS: {} kubeProxy: {} + konnectivity: + server: + port: 8132 diff --git a/internal/resources/k8s_ingress_resource.go b/internal/resources/k8s_ingress_resource.go index 937a5b6..bc5800c 100644 --- a/internal/resources/k8s_ingress_resource.go +++ b/internal/resources/k8s_ingress_resource.go @@ -26,20 +26,25 @@ type KubernetesIngressResource struct { } func (r *KubernetesIngressResource) ShouldStatusBeUpdated(_ context.Context, tcp *kamajiv1alpha1.TenantControlPlane) bool { - // No update in case of no ingress in spec, neither in status. - if tcp.Spec.ControlPlane.Ingress == nil && tcp.Status.Kubernetes.Ingress == nil { + switch { + case tcp.Spec.ControlPlane.Ingress == nil && tcp.Status.Kubernetes.Ingress == nil: + // No update in case of no ingress in spec, neither in status. return false - } - // Must be updated when TCP is using an Ingress, and status is not tracking it. - if tcp.Spec.ControlPlane.Ingress != nil && tcp.Status.Kubernetes.Ingress == nil { + case tcp.Spec.ControlPlane.Ingress != nil && tcp.Status.Kubernetes.Ingress == nil, + // Must be updated when TCP is using an Ingress, and status is not tracking it + // or + // Must be updated when the status is referring to an Ingress, although spec doesn't. + tcp.Spec.ControlPlane.Ingress == nil && tcp.Status.Kubernetes.Ingress != nil: return true - } - // Must be updated when the status is referring to an Ingress, although spec doesn't. - if tcp.Spec.ControlPlane.Ingress == nil && tcp.Status.Kubernetes.Ingress != nil { + case len(r.resource.Status.LoadBalancer.Ingress) > 0 && tcp.Status.Kubernetes.Ingress == nil || tcp.Status.Kubernetes.Ingress.LoadBalancer.Ingress == nil: + // Must be updated since missing the Ingress status return true + case r.resource.Status.LoadBalancer.Ingress[0].IP != tcp.Status.Kubernetes.Ingress.LoadBalancer.Ingress[0].IP: + // Must bne updated, Ingress load balancer IP is slightly different + return true + default: + return tcp.Status.Kubernetes.Ingress.Name != r.resource.GetName() || tcp.Status.Kubernetes.Ingress.Namespace != r.resource.GetNamespace() } - // In case of status skew, update it. - return tcp.Status.Kubernetes.Ingress.Name != r.resource.GetName() || tcp.Status.Kubernetes.Ingress.Namespace != r.resource.GetNamespace() } func (r *KubernetesIngressResource) ShouldCleanup(tcp *kamajiv1alpha1.TenantControlPlane) bool {