Skip to content

Commit

Permalink
Unify process of drop cert-manager annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Oct 14, 2024
1 parent 8a3cd1f commit b2ce755
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ var (
certManagerIssuerKindKey = "cert-manager.io/issuer-kind"
certManagerIssuerGroupKey = "cert-manager.io/issuer-group"

unwantedAnnotationsForCNames = []string{
certManagerAnnotations = []string{
certManagerIssuerKey,
certManagerClusterIssuerKey,
certManagerIssuerKindKey,
certManagerIssuerGroupKey,
}
)

Expand Down Expand Up @@ -193,7 +195,7 @@ func (k *IngressService) Ensure(ctx context.Context, id router.InstanceID, o rou
k.fillIngressTLS(ingress, id)
ingress.ObjectMeta.Annotations[AnnotationsACMEKey] = "true"
} else {
k.cleanupACMEAnnotations(ingress)
k.cleanupCertManagerAnnotations(ingress)
}
if len(o.CNames) > 0 {
ingress.Annotations[AnnotationsCNames] = strings.Join(o.CNames, ",")
Expand Down Expand Up @@ -259,7 +261,6 @@ func (k *IngressService) mergeIngresses(ctx context.Context, ingress *networking
ingress.Spec.DefaultBackend = existingIngress.Spec.DefaultBackend
}
if existingIngress.Spec.TLS != nil && len(existingIngress.Spec.TLS) > 0 {
fmt.Println("from merge -> existingIngress.Spec.TLS", existingIngress.Spec.TLS)
k.fillIngressTLS(ingress, id)
}
_, err := ingressClient.Update(ctx, ingress, metav1.UpdateOptions{})
Expand Down Expand Up @@ -371,7 +372,7 @@ func (k *IngressService) ensureCNameBackend(ctx context.Context, opts ensureCNam
k.fillIngressTLS(ingress, opts.id)
ingress.ObjectMeta.Annotations[AnnotationsACMEKey] = "true"
} else {
k.cleanupACMEAnnotations(ingress)
k.cleanupCertManagerAnnotations(ingress)
}

err = k.ensureCertManagerIssuer(ctx, opts, ingress, existingIngress)
Expand Down Expand Up @@ -429,14 +430,7 @@ func (k *IngressService) ensureCertManagerIssuer(ctx context.Context, opts ensur
}

func (k *IngressService) cleanupCertManagerAnnotations(ingress *networkingV1.Ingress) {
delete(ingress.Annotations, certManagerIssuerKey)
delete(ingress.Annotations, certManagerClusterIssuerKey)
delete(ingress.Annotations, certManagerIssuerKindKey)
delete(ingress.Annotations, certManagerIssuerGroupKey)
}

func (k *IngressService) cleanupACMEAnnotations(ingress *networkingV1.Ingress) {
for _, annotation := range unwantedAnnotationsForCNames {
for _, annotation := range certManagerAnnotations {
delete(ingress.Annotations, annotation)
}
}
Expand Down

0 comments on commit b2ce755

Please sign in to comment.