Skip to content

Commit

Permalink
fix deletions for secrets (#611)
Browse files Browse the repository at this point in the history
Fixes: #588

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg authored Oct 19, 2022
1 parent 30cf06e commit 195e5b2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/provider/kubernetes/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func (r *gatewayReconciler) Reconcile(ctx context.Context, request reconcile.Req
}

found := false
var secrets []corev1.Secret
// Set status conditions for all accepted gateways.
for i := range acceptedGateways {
gw := acceptedGateways[i]
Expand Down Expand Up @@ -376,9 +375,19 @@ func (r *gatewayReconciler) Reconcile(ctx context.Context, request reconcile.Req
}

if !found {
gw, ok := r.resources.Gateways.Load(request.NamespacedName)
if !ok {
r.log.Info("failed to find gateway in the watchable map", "namespace", gw.Namespace, "name", gw.Name)
}

r.resources.Gateways.Delete(request.NamespacedName)
// Delete the TLS secrets from the resource map if no other managed
// Gateways reference them.
secrets, _, err := r.secretsAndRefGrantsForGateway(ctx, gw)
if err != nil {
r.log.Info("failed to get secrets and referencegrants for gateway",
"namespace", gw.Namespace, "name", gw.Name)
}
for i := range secrets {
secret := secrets[i]
referenced, err := r.gatewaysRefSecret(ctx, &secret)
Expand Down Expand Up @@ -535,6 +544,7 @@ func (r *gatewayReconciler) secretsAndRefGrantsForGateway(ctx context.Context, g
}
secret := new(corev1.Secret)
if err := r.client.Get(ctx, key, secret); err != nil {
r.resources.Secrets.Delete(key)
return nil, nil, fmt.Errorf("failed to get secret: %v", err)
}
secrets = append(secrets, *secret)
Expand All @@ -548,6 +558,7 @@ func (r *gatewayReconciler) secretsAndRefGrantsForGateway(ctx context.Context, g
}
secret := new(corev1.Secret)
if err := r.client.Get(ctx, key, secret); err != nil {
r.resources.Secrets.Delete(key)
return nil, nil, fmt.Errorf("failed to get secret: %v", err)
}
secrets = append(secrets, *secret)
Expand Down

0 comments on commit 195e5b2

Please sign in to comment.