@@ -93,9 +93,13 @@ func (r *TypesenseClusterReconciler) ReconcileIngress(ctx context.Context, ts *t
9393 return err
9494 }
9595 } else {
96+ lbls := r .getIngressLabels (ig , ts , ingressObjectKey )
97+ anons := r .getIngressAnnotations (ig , ts )
98+
9699 if ts .Spec .Ingress .Host != ig .Spec .Rules [0 ].Host ||
97100 (ts .Spec .Ingress .ClusterIssuer != nil && * ts .Spec .Ingress .ClusterIssuer != ig .Annotations [clusterIssuerAnnotationKey ]) ||
98- ! apiequality .Semantic .DeepEqual (ts .Spec .Ingress .Annotations , r .getIngressAnnotations (ig , ts )) ||
101+ ! apiequality .Semantic .DeepEqual (ts .Spec .Ingress .Labels , lbls ) ||
102+ ! apiequality .Semantic .DeepEqual (ts .Spec .Ingress .Annotations , anons ) ||
99103 (ts .Spec .Ingress .TLSSecretName != nil && * ts .Spec .Ingress .TLSSecretName != ig .Spec .TLS [0 ].SecretName ) ||
100104 ts .Spec .Ingress .IngressClassName != * ig .Spec .IngressClassName ||
101105 ts .Spec .Ingress .Path != ig .Spec .Rules [0 ].IngressRuleValue .HTTP .Paths [0 ].Path ||
@@ -278,10 +282,7 @@ func (r *TypesenseClusterReconciler) ReconcileIngress(ctx context.Context, ts *t
278282}
279283
280284func (r * TypesenseClusterReconciler ) createIngress (ctx context.Context , key client.ObjectKey , ts * tsv1alpha1.TypesenseCluster ) (* networkingv1.Ingress , error ) {
281- if ts .Spec .Ingress .ClusterIssuer != nil && ts .Spec .Ingress .TLSSecretName == nil {
282- return nil , fmt .Errorf ("tls secret name is required, skipping ingress creation" )
283- }
284-
285+ labels := map [string ]string {}
285286 annotations := map [string ]string {}
286287 var tlsSecretName string
287288
@@ -290,6 +291,10 @@ func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key clie
290291 tlsSecretName = fmt .Sprintf ("%s-reverse-proxy-%s-certificate-tls" , ts .Name , * ts .Spec .Ingress .ClusterIssuer )
291292 }
292293
294+ if ts .Spec .Ingress .Labels != nil {
295+ maps .Copy (labels , ts .Spec .Ingress .Labels )
296+ }
297+
293298 if ts .Spec .Ingress .Annotations != nil {
294299 maps .Copy (annotations , ts .Spec .Ingress .Annotations )
295300 }
@@ -299,7 +304,7 @@ func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key clie
299304 }
300305
301306 ingress := & networkingv1.Ingress {
302- ObjectMeta : getObjectMeta (ts , & key .Name , annotations ),
307+ ObjectMeta : getIngressObjectMeta (ts , & key .Name , ts . Spec . Ingress . Labels , ts . Spec . Ingress . Annotations ),
303308 Spec : networkingv1.IngressSpec {
304309 IngressClassName : ptr .To (ts .Spec .Ingress .IngressClassName ),
305310 TLS : []networkingv1.IngressTLS {
@@ -348,9 +353,6 @@ func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key clie
348353}
349354
350355func (r * TypesenseClusterReconciler ) updateIngress (ctx context.Context , ig networkingv1.Ingress , ts * tsv1alpha1.TypesenseCluster ) (* networkingv1.Ingress , error ) {
351- if ts .Spec .Ingress .ClusterIssuer != nil && ts .Spec .Ingress .TLSSecretName == nil {
352- return nil , fmt .Errorf ("tls secret name is required, skipping ingress update" )
353- }
354356 patch := client .MergeFrom (ig .DeepCopy ())
355357
356358 ig .Spec .Rules [0 ].Host = ts .Spec .Ingress .Host
@@ -366,10 +368,13 @@ func (r *TypesenseClusterReconciler) updateIngress(ctx context.Context, ig netwo
366368 tlsSecretName = fmt .Sprintf ("%s-reverse-proxy-%s-certificate-tls" , ts .Name , * ts .Spec .Ingress .ClusterIssuer )
367369 }
368370
371+ if ts .Spec .Ingress .Labels != nil {
372+ maps .Copy (ig .Labels , ts .Spec .Ingress .Labels )
373+ }
374+
369375 if ts .Spec .Ingress .Annotations != nil {
370- maps .Copy (annotations , ts .Spec .Ingress .Annotations )
376+ maps .Copy (ig . Annotations , ts .Spec .Ingress .Annotations )
371377 }
372- ig .Annotations = annotations
373378
374379 if ts .Spec .Ingress .TLSSecretName != nil {
375380 tlsSecretName = * ts .Spec .Ingress .TLSSecretName
@@ -392,6 +397,17 @@ func (r *TypesenseClusterReconciler) deleteIngress(ctx context.Context, ig *netw
392397 return nil
393398}
394399
400+ func (r * TypesenseClusterReconciler ) getIngressLabels (ig * networkingv1.Ingress , ts * tsv1alpha1.TypesenseCluster , key client.ObjectKey ) map [string ]string {
401+ var filters []string
402+ defaultLabels := getIngressObjectMeta (ts , & key .Name , nil , nil ).Labels
403+ for k := range defaultLabels {
404+ filters = append (filters , k )
405+ }
406+
407+ filtered := filterMap (ig .Labels , filters ... )
408+ return filtered
409+ }
410+
395411func (r * TypesenseClusterReconciler ) getIngressAnnotations (ig * networkingv1.Ingress , ts * tsv1alpha1.TypesenseCluster ) map [string ]string {
396412 filters := append ([]string {clusterIssuerAnnotationKey , rancherDomainAnnotationKey }, ts .Spec .IgnoreAnnotationsFromExternalMutations ... )
397413 filtered := filterMap (ig .Annotations , filters ... )
0 commit comments