@@ -10,8 +10,6 @@ import (
1010 "text/template"
1111 "time"
1212
13- "reflect"
14-
1513 tsv1alpha1 "github.com/akyriako/typesense-operator/api/v1alpha1"
1614 appsv1 "k8s.io/api/apps/v1"
1715 v1 "k8s.io/api/core/v1"
@@ -57,6 +55,8 @@ const (
5755 }`
5856)
5957
58+ const clusterIssuerAnnotationKey = "cert-manager.io/cluster-issuer"
59+
6060func (r * TypesenseClusterReconciler ) ReconcileIngress (ctx context.Context , ts tsv1alpha1.TypesenseCluster ) (err error ) {
6161 r .logger .V (debugLevel ).Info ("reconciling ingress" )
6262
@@ -90,8 +90,8 @@ func (r *TypesenseClusterReconciler) ReconcileIngress(ctx context.Context, ts ts
9090 }
9191 } else {
9292 if ts .Spec .Ingress .Host != ig .Spec .Rules [0 ].Host ||
93- (ts .Spec .Ingress .ClusterIssuer != nil && * ts .Spec .Ingress .ClusterIssuer != ig .Annotations ["cert-manager.io/cluster-issuer" ]) ||
94- ! reflect .DeepEqual (ts .Spec .Ingress .Annotations , r .getIngressAnnotations (ig )) ||
93+ (ts .Spec .Ingress .ClusterIssuer != nil && * ts .Spec .Ingress .ClusterIssuer != ig .Annotations [clusterIssuerAnnotationKey ]) ||
94+ ! apiequality . Semantic .DeepEqual (ts .Spec .Ingress .Annotations , r .getIngressAnnotations (ig )) ||
9595 (ts .Spec .Ingress .TLSSecretName != nil && * ts .Spec .Ingress .TLSSecretName != ig .Spec .TLS [0 ].SecretName ) ||
9696 ts .Spec .Ingress .IngressClassName != * ig .Spec .IngressClassName ||
9797 ts .Spec .Ingress .Path != ig .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths [0 ].Path ||
@@ -173,12 +173,12 @@ func (r *TypesenseClusterReconciler) ReconcileIngress(ctx context.Context, ts ts
173173 }
174174 } else {
175175 desiredResources := ts .Spec .Ingress .GetReverseProxyResources ()
176- deploymentResourcesNeedUpdate := ! reflect .DeepEqual (desiredResources , deployment .Spec .Template .Spec .Containers [0 ].Resources )
176+ deploymentResourcesNeedUpdate := ! apiequality . Semantic .DeepEqual (desiredResources , deployment .Spec .Template .Spec .Containers [0 ].Resources )
177177 if deploymentResourcesNeedUpdate {
178178 deployment .Spec .Template .Spec .Containers [0 ].Resources = desiredResources
179179 }
180180
181- deploymentImageNeedUpdate := ! reflect .DeepEqual (ts .Spec .Ingress .Image , deployment .Spec .Template .Spec .Containers [0 ].Image )
181+ deploymentImageNeedUpdate := ! apiequality . Semantic .DeepEqual (ts .Spec .Ingress .Image , deployment .Spec .Template .Spec .Containers [0 ].Image )
182182 if deploymentImageNeedUpdate {
183183 deployment .Spec .Template .Spec .Containers [0 ].Image = ts .Spec .Ingress .Image
184184 }
@@ -199,7 +199,7 @@ func (r *TypesenseClusterReconciler) ReconcileIngress(ctx context.Context, ts ts
199199 }
200200 }
201201
202- if ! reflect .DeepEqual (securityContext , deployment .Spec .Template .Spec .Containers [0 ].SecurityContext ) {
202+ if ! apiequality . Semantic .DeepEqual (securityContext , deployment .Spec .Template .Spec .Containers [0 ].SecurityContext ) {
203203 readOnlyRootFilesystemSpecsNeedUpdate = true
204204 deployment .Spec .Template .Spec .Containers [0 ].SecurityContext = securityContext
205205 }
@@ -282,7 +282,7 @@ func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key clie
282282 var tlsSecretName string
283283
284284 if ts .Spec .Ingress .ClusterIssuer != nil {
285- annotations ["cert-manager.io/cluster-issuer" ] = * ts .Spec .Ingress .ClusterIssuer
285+ annotations [clusterIssuerAnnotationKey ] = * ts .Spec .Ingress .ClusterIssuer
286286 tlsSecretName = fmt .Sprintf ("%s-reverse-proxy-%s-certificate-tls" , ts .Name , * ts .Spec .Ingress .ClusterIssuer )
287287 }
288288
@@ -358,7 +358,7 @@ func (r *TypesenseClusterReconciler) updateIngress(ctx context.Context, ig netwo
358358 var tlsSecretName string
359359
360360 if ts .Spec .Ingress .ClusterIssuer != nil {
361- annotations ["cert-manager.io/cluster-issuer" ] = * ts .Spec .Ingress .ClusterIssuer
361+ annotations [clusterIssuerAnnotationKey ] = * ts .Spec .Ingress .ClusterIssuer
362362 tlsSecretName = fmt .Sprintf ("%s-reverse-proxy-%s-certificate-tls" , ts .Name , * ts .Spec .Ingress .ClusterIssuer )
363363 }
364364
@@ -389,17 +389,8 @@ func (r *TypesenseClusterReconciler) deleteIngress(ctx context.Context, ig *netw
389389}
390390
391391func (r * TypesenseClusterReconciler ) getIngressAnnotations (ig * networkingv1.Ingress ) map [string ]string {
392- annotations := make (map [string ]string , len (ig .Annotations ))
393- for k , v := range ig .Annotations {
394- annotations [k ] = v
395- }
396-
397- delete (annotations , "cert-manager.io/cluster-issuer" )
398- if len (annotations ) == 0 {
399- annotations = nil
400- }
401-
402- return annotations
392+ filtered := filterAnnotations (ig .Annotations , clusterIssuerAnnotationKey , rancherDomainAnnotationKey )
393+ return filtered
403394}
404395
405396func (r * TypesenseClusterReconciler ) createIngressConfigMap (ctx context.Context , key client.ObjectKey , ts * tsv1alpha1.TypesenseCluster , ig * networkingv1.Ingress ) (* v1.ConfigMap , error ) {
0 commit comments