Skip to content

Commit e87f0b1

Browse files
committed
Prevent blocking namespace deletion by ignoring chart removals in terminating namespaces
1 parent ca228d3 commit e87f0b1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/controllers/chart/chart.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type Controller struct {
9090
jobs batchcontroller.JobController
9191
jobCache batchcontroller.JobCache
9292
secretCache corecontroller.SecretCache
93+
namespaceCache corecontroller.NamespaceCache
9394
apply apply.Apply
9495
recorder record.EventRecorder
9596
apiServerPort string
@@ -114,7 +115,8 @@ func Register(
114115
sas corecontroller.ServiceAccountController,
115116
cm corecontroller.ConfigMapController,
116117
s corecontroller.SecretController,
117-
sCache corecontroller.SecretCache) {
118+
sCache corecontroller.SecretCache,
119+
nsCache corecontroller.NamespaceCache) {
118120

119121
c := &Controller{
120122
systemNamespace: systemNamespace,
@@ -127,6 +129,7 @@ func Register(
127129
jobs: jobs,
128130
jobCache: jobCache,
129131
secretCache: sCache,
132+
namespaceCache: nsCache,
130133
recorder: recorder,
131134
apiServerPort: apiServerPort,
132135
}
@@ -335,6 +338,14 @@ func (c *Controller) OnRemove(key string, chart *v1.HelmChart) (*v1.HelmChart, e
335338
return nil, nil
336339
}
337340

341+
// if the target namespace is terminating, we are not allowed to spawn jobs
342+
// skip to not block indefinitely. namespace deletion will remove the chart
343+
if ns, err := c.namespaceCache.Get(chart.Namespace); err != nil {
344+
return nil, fmt.Errorf("could not perform uninstall: namespace %s not found", chart.Namespace)
345+
} else if ns.Status.Phase == corev1.NamespaceTerminating {
346+
return nil, nil
347+
}
348+
338349
expectedJob, objs, err := c.getJobAndRelatedResources(chart)
339350
if err != nil {
340351
return nil, err

pkg/controllers/controllers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func Register(ctx context.Context, systemNamespace, controllerName string, cfg c
9797
appCtx.Core.ConfigMap(),
9898
appCtx.Core.Secret(),
9999
appCtx.Core.Secret().Cache(),
100+
appCtx.Core.Namespace().Cache(),
100101
)
101102

102103
klog.Infof("Starting helm controller with %d threads", opts.Threadiness)

0 commit comments

Comments
 (0)