Skip to content

Commit

Permalink
deletion logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Jan 7, 2025
1 parent 0f5f56f commit efffa6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
11 changes: 11 additions & 0 deletions internal/controller/kyma/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
if util.IsNotFound(err) {
logger.V(log.DebugLevel).Info(fmt.Sprintf("Kyma %s not found, probably already deleted",
req.NamespacedName))
if err = r.handleOrphanedResourcesDeletion(ctx, kyma); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: false}, nil
}
r.Metrics.RecordRequeueReason(metrics.KymaRetrieval, queue.UnexpectedRequeue)
Expand Down Expand Up @@ -624,6 +627,14 @@ func (r *Reconciler) UpdateModuleTemplatesIfNeeded(ctx context.Context) error {
return nil
}

func (r *Reconciler) handleOrphanedResourcesDeletion(ctx context.Context, kyma *v1beta2.Kyma) error {
if err := r.SKRWebhookManager.RemoveKCPCertificate(ctx, kyma); err != nil {
return err
}

return nil
}

func needUpdateForMandatoryModuleLabel(moduleTemplate v1beta2.ModuleTemplate) bool {
if moduleTemplate.Labels == nil {
moduleTemplate.Labels = make(map[string]string)
Expand Down
4 changes: 2 additions & 2 deletions pkg/watcher/certificate_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func (c *CertificateManager) CreateSelfSignedCert(ctx context.Context, kyma *v1b

// Remove removes the certificate including its certificate secret.
func (c *CertificateManager) Remove(ctx context.Context) error {
err := c.RemoveCertificate(ctx)
err := c.removeCertificate(ctx)
if err != nil {
return err
}

return c.removeSecret(ctx)
}

func (c *CertificateManager) RemoveCertificate(ctx context.Context) error {
func (c *CertificateManager) removeCertificate(ctx context.Context) error {
certificate := &certmanagerv1.Certificate{}
err := c.kcpClient.Get(ctx, client.ObjectKey{
Name: c.certificateName,
Expand Down
16 changes: 13 additions & 3 deletions pkg/watcher/skr_webhook_manifest_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ func (m *SKRWebhookManifestManager) Remove(ctx context.Context, kyma *v1beta2.Ky
if err != nil {
return fmt.Errorf("failed to get skrContext: %w", err)
}
certificate := NewCertificateManager(m.kcpClient, kyma.Name,
m.certificateConfig)
if err = certificate.Remove(ctx); err != nil {

if err = m.RemoveKCPCertificate(ctx, kyma); err != nil {
return err
}

skrClientObjects := m.getBaseClientObjects()
genClientObjects := getGeneratedClientObjects(&unstructuredResourcesConfig{}, []v1beta2.Watcher{},
m.config.RemoteSyncNamespace)
Expand All @@ -172,6 +172,16 @@ func (m *SKRWebhookManifestManager) Remove(ctx context.Context, kyma *v1beta2.Ky
return nil
}

func (m *SKRWebhookManifestManager) RemoveKCPCertificate(ctx context.Context, kyma *v1beta2.Kyma) error {
certificate := NewCertificateManager(m.kcpClient, kyma.Name,
m.certificateConfig)
if err := certificate.Remove(ctx); err != nil {
return err
}

return nil
}

func (m *SKRWebhookManifestManager) getSKRClientObjectsForInstall(ctx context.Context,
kymaObjKey client.ObjectKey, remoteNs string, gatewaySecret *apicorev1.Secret, logger logr.Logger,
) ([]client.Object, error) {
Expand Down

0 comments on commit efffa6d

Please sign in to comment.