func()

in pkg/controller/sync/sync.go [201:250]


func (s impl) Ingress(ctx context.Context, id types.Id) error {
	originalIngress, err := s.ingress.Get(id)
	if errors.IsNotFound(err) {
		return nil
	} else if err != nil {
		return err
	}

	klog.Infof("Syncing Ingress %s", id.String())

	sslCertificates, managedCertificates, err := s.getCertificatesToAttach(originalIngress)
	if err != nil {
		return fmt.Errorf("getCertificatesToAttach(): %w", err)
	}

	preSharedCertValue := buildPreSharedCertAnnotation(sslCertificates)

	if preSharedCertValue == originalIngress.Annotations[config.AnnotationPreSharedCertKey] {
		return nil
	}

	klog.Infof("Annotation %s on Ingress %s was %s, set to %s",
		config.AnnotationPreSharedCertKey, id.String(),
		originalIngress.Annotations[config.AnnotationPreSharedCertKey], preSharedCertValue)

	modifiedIngress := originalIngress.DeepCopy()

	if modifiedIngress.Annotations == nil {
		modifiedIngress.Annotations = make(map[string]string, 0)
	}
	modifiedIngress.Annotations[config.AnnotationPreSharedCertKey] = preSharedCertValue

	patchBytes, modified, err := patch.CreateMergePatch(originalIngress, modifiedIngress)
	if err != nil {
		return fmt.Errorf("patch.CreateMergePatch(): %w", err)
	}

	if modified {
		err = s.ingress.Patch(ctx, id, patchBytes)
		if err != nil {
			return fmt.Errorf("s.ingress.Patch(): %w", err)
		}
	}

	if err := s.reportManagedCertificatesAttached(ctx, managedCertificates); err != nil {
		return fmt.Errorf("reportManagedCertificatesAttached(): %w", err)
	}

	return nil
}