Skip to content

Commit 53baad2

Browse files
committed
dev? rework context acncellation - stage 1
1 parent b7f36f0 commit 53baad2

34 files changed

+61
-381
lines changed

pkg/controller/chi/controller-config-map.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ import (
2323
apiErrors "k8s.io/apimachinery/pkg/api/errors"
2424
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2525

26-
log "github.com/altinity/clickhouse-operator/pkg/announcer"
2726
"github.com/altinity/clickhouse-operator/pkg/controller"
2827
chiLabeler "github.com/altinity/clickhouse-operator/pkg/model/chi/tags/labeler"
29-
"github.com/altinity/clickhouse-operator/pkg/util"
3028
)
3129

3230
// getConfigMap gets ConfigMap either by namespaced name or by labels
@@ -78,20 +76,10 @@ func (c *Controller) getConfigMap(ctx context.Context, meta meta.Object, byNameO
7876
}
7977

8078
func (c *Controller) createConfigMap(ctx context.Context, cm *core.ConfigMap) error {
81-
if util.IsContextDone(ctx) {
82-
log.V(2).Info("task is done")
83-
return nil
84-
}
85-
8679
_, err := c.kube.ConfigMap().Create(ctx, cm)
8780
return err
8881
}
8982

9083
func (c *Controller) updateConfigMap(ctx context.Context, cm *core.ConfigMap) (*core.ConfigMap, error) {
91-
if util.IsContextDone(ctx) {
92-
log.V(2).Info("task is done")
93-
return nil, nil
94-
}
95-
9684
return c.kube.ConfigMap().Update(ctx, cm)
9785
}

pkg/controller/chi/controller-deleter.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
2626
"github.com/altinity/clickhouse-operator/pkg/controller/common/storage"
2727
"github.com/altinity/clickhouse-operator/pkg/interfaces"
28-
"github.com/altinity/clickhouse-operator/pkg/util"
2928
)
3029

3130
// deleteHost deletes all kubernetes resources related to replica *chop.Host
@@ -45,11 +44,6 @@ func (c *Controller) deleteHost(ctx context.Context, host *api.Host) error {
4544

4645
// deleteConfigMapsCHI
4746
func (c *Controller) deleteConfigMapsCHI(ctx context.Context, chi *api.ClickHouseInstallation) error {
48-
if util.IsContextDone(ctx) {
49-
log.V(2).Info("task is done")
50-
return nil
51-
}
52-
5347
// Delete common ConfigMap's
5448
//
5549
// chi-b3d29f-common-configd 2 61s
@@ -88,11 +82,6 @@ func (c *Controller) deleteConfigMapsCHI(ctx context.Context, chi *api.ClickHous
8882

8983
// statefulSetDeletePod delete a pod of a StatefulSet. This requests StatefulSet to relaunch deleted pod
9084
func (c *Controller) statefulSetDeletePod(ctx context.Context, statefulSet *apps.StatefulSet, host *api.Host) error {
91-
if util.IsContextDone(ctx) {
92-
log.V(2).Info("task is done")
93-
return nil
94-
}
95-
9685
name := c.namer.Name(interfaces.NamePod, statefulSet)
9786
log.V(1).M(host).Info("Delete Pod %s/%s", statefulSet.Namespace, name)
9887
err := c.kube.Pod().Delete(ctx, statefulSet.Namespace, name)
@@ -109,11 +98,6 @@ func (c *Controller) statefulSetDeletePod(ctx context.Context, statefulSet *apps
10998
}
11099

111100
func (c *Controller) deleteStatefulSet(ctx context.Context, host *api.Host) error {
112-
if util.IsContextDone(ctx) {
113-
log.V(2).Info("task is done")
114-
return nil
115-
}
116-
117101
name := c.namer.Name(interfaces.NameStatefulSet, host)
118102
namespace := host.Runtime.Address.Namespace
119103
log.V(1).M(host).F().Info("%s/%s", namespace, name)
@@ -122,11 +106,6 @@ func (c *Controller) deleteStatefulSet(ctx context.Context, host *api.Host) erro
122106

123107
// deleteConfigMap deletes ConfigMap
124108
func (c *Controller) deleteConfigMap(ctx context.Context, host *api.Host) error {
125-
if util.IsContextDone(ctx) {
126-
log.V(2).Info("task is done")
127-
return nil
128-
}
129-
130109
name := c.namer.Name(interfaces.NameConfigMapHost, host)
131110
namespace := host.Runtime.Address.Namespace
132111
log.V(1).M(host).F().Info("%s/%s", namespace, name)
@@ -143,11 +122,6 @@ func (c *Controller) deleteConfigMap(ctx context.Context, host *api.Host) error
143122

144123
// deleteServiceHost deletes Service
145124
func (c *Controller) deleteServiceHost(ctx context.Context, host *api.Host) error {
146-
if util.IsContextDone(ctx) {
147-
log.V(2).Info("task is done")
148-
return nil
149-
}
150-
151125
serviceName := c.namer.Name(interfaces.NameStatefulSetService, host)
152126
namespace := host.Runtime.Address.Namespace
153127
log.V(1).M(host).F().Info("%s/%s", namespace, serviceName)
@@ -156,11 +130,6 @@ func (c *Controller) deleteServiceHost(ctx context.Context, host *api.Host) erro
156130

157131
// deleteServiceShard
158132
func (c *Controller) deleteServiceShard(ctx context.Context, shard *api.ChiShard) error {
159-
if util.IsContextDone(ctx) {
160-
log.V(2).Info("task is done")
161-
return nil
162-
}
163-
164133
serviceName := c.namer.Name(interfaces.NameShardService, shard)
165134
namespace := shard.Runtime.Address.Namespace
166135
log.V(1).M(shard).F().Info("%s/%s", namespace, serviceName)
@@ -169,11 +138,6 @@ func (c *Controller) deleteServiceShard(ctx context.Context, shard *api.ChiShard
169138

170139
// deleteServiceCluster
171140
func (c *Controller) deleteServiceCluster(ctx context.Context, cluster *api.Cluster) error {
172-
if util.IsContextDone(ctx) {
173-
log.V(2).Info("task is done")
174-
return nil
175-
}
176-
177141
serviceName := c.namer.Name(interfaces.NameClusterService, cluster)
178142
namespace := cluster.Runtime.Address.Namespace
179143
log.V(1).M(cluster).F().Info("%s/%s", namespace, serviceName)
@@ -182,11 +146,6 @@ func (c *Controller) deleteServiceCluster(ctx context.Context, cluster *api.Clus
182146

183147
// deleteServiceCR
184148
func (c *Controller) deleteServiceCR(ctx context.Context, cr api.ICustomResource) error {
185-
if util.IsContextDone(ctx) {
186-
log.V(2).Info("task is done")
187-
return nil
188-
}
189-
190149
if templates, ok := cr.GetRootServiceTemplates(); ok {
191150
for _, template := range templates {
192151
serviceName := c.namer.Name(interfaces.NameCRService, cr, template)
@@ -206,11 +165,6 @@ func (c *Controller) deleteServiceCR(ctx context.Context, cr api.ICustomResource
206165

207166
// deleteSecretCluster
208167
func (c *Controller) deleteSecretCluster(ctx context.Context, cluster *api.Cluster) error {
209-
if util.IsContextDone(ctx) {
210-
log.V(2).Info("task is done")
211-
return nil
212-
}
213-
214168
secretName := c.namer.Name(interfaces.NameClusterAutoSecret, cluster)
215169
namespace := cluster.Runtime.Address.Namespace
216170
log.V(1).M(cluster).F().Info("%s/%s", namespace, secretName)
@@ -219,11 +173,6 @@ func (c *Controller) deleteSecretCluster(ctx context.Context, cluster *api.Clust
219173

220174
// deleteSecretIfExists deletes Secret in case it does not exist
221175
func (c *Controller) deleteSecretIfExists(ctx context.Context, namespace, name string) error {
222-
if util.IsContextDone(ctx) {
223-
log.V(2).Info("task is done")
224-
return nil
225-
}
226-
227176
// Check specified service exists
228177
_, err := c.kube.Secret().Get(ctx, &core.Secret{
229178
ObjectMeta: meta.ObjectMeta{

pkg/controller/chi/controller-discoverer.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,13 @@ import (
2525
"github.com/altinity/clickhouse-operator/pkg/interfaces"
2626
"github.com/altinity/clickhouse-operator/pkg/model"
2727
chiLabeler "github.com/altinity/clickhouse-operator/pkg/model/chi/tags/labeler"
28-
"github.com/altinity/clickhouse-operator/pkg/util"
2928
)
3029

3130
func getLabeler(cr api.ICustomResource) interfaces.ILabeler {
3231
return chiLabeler.New(cr)
3332
}
3433

3534
func (c *Controller) discovery(ctx context.Context, cr api.ICustomResource) *model.Registry {
36-
if util.IsContextDone(ctx) {
37-
log.V(2).Info("task is done")
38-
return nil
39-
}
40-
4135
opts := controller.NewListOptions(getLabeler(cr).Selector(interfaces.SelectorCRScope))
4236
r := model.NewRegistry()
4337
c.discoveryStatefulSets(ctx, r, cr, opts)

pkg/controller/chi/controller-pdb.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,19 @@ import (
1818
"context"
1919

2020
policy "k8s.io/api/policy/v1"
21-
22-
log "github.com/altinity/clickhouse-operator/pkg/announcer"
23-
"github.com/altinity/clickhouse-operator/pkg/util"
2421
)
2522

2623
func (c *Controller) getPDB(ctx context.Context, pdb *policy.PodDisruptionBudget) (*policy.PodDisruptionBudget, error) {
2724
return c.kube.PDB().Get(ctx, pdb.GetNamespace(), pdb.GetName())
2825
}
2926

3027
func (c *Controller) createPDB(ctx context.Context, pdb *policy.PodDisruptionBudget) error {
31-
if util.IsContextDone(ctx) {
32-
log.V(2).Info("task is done")
33-
return nil
34-
}
35-
3628
_, err := c.kube.PDB().Create(ctx, pdb)
3729

3830
return err
3931
}
4032

4133
func (c *Controller) updatePDB(ctx context.Context, pdb *policy.PodDisruptionBudget) error {
42-
if util.IsContextDone(ctx) {
43-
log.V(2).Info("task is done")
44-
return nil
45-
}
46-
4734
_, err := c.kube.PDB().Update(ctx, pdb)
4835

4936
return err

pkg/controller/chi/controller-secret.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ func (c *Controller) getSecret(ctx context.Context, secret *core.Secret) (*core.
2929
}
3030

3131
func (c *Controller) createSecret(ctx context.Context, secret *core.Secret) error {
32-
log.V(1).M(secret).F().P()
33-
34-
if util.IsContextDone(ctx) {
35-
log.V(2).Info("task is done")
36-
return nil
37-
}
38-
3932
log.V(1).Info("Create Secret %s", util.NamespacedName(secret))
4033
if _, err := c.kube.Secret().Create(ctx, secret); err != nil {
4134
// Unable to create StatefulSet at all

pkg/controller/chi/controller-service.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

2222
log "github.com/altinity/clickhouse-operator/pkg/announcer"
23-
"github.com/altinity/clickhouse-operator/pkg/util"
2423
)
2524

2625
func (c *Controller) getService(ctx context.Context, service *core.Service) (*core.Service, error) {
@@ -39,11 +38,6 @@ func (c *Controller) updateService(ctx context.Context, service *core.Service) e
3938

4039
// deleteServiceIfExists deletes Service in case it does not exist
4140
func (c *Controller) deleteServiceIfExists(ctx context.Context, namespace, name string) error {
42-
if util.IsContextDone(ctx) {
43-
log.V(2).Info("task is done")
44-
return nil
45-
}
46-
4741
// Check specified service exists
4842
_, err := c.kube.Service().Get(ctx, &core.Service{
4943
ObjectMeta: meta.ObjectMeta{

pkg/controller/chi/controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ type patchFinalizers struct {
696696
// patchCHIFinalizers patch ClickHouseInstallation finalizers
697697
func (c *Controller) patchCHIFinalizers(ctx context.Context, chi *api.ClickHouseInstallation) error {
698698
if util.IsContextDone(ctx) {
699-
log.V(2).Info("task is done")
699+
log.V(1).Info("Reconcile is aborted. CR patch fin: %s ", chi.GetName())
700700
return nil
701701
}
702702

@@ -736,7 +736,7 @@ func (c *Controller) patchCHIFinalizers(ctx context.Context, chi *api.ClickHouse
736736

737737
func (c *Controller) poll(ctx context.Context, chi *api.ClickHouseInstallation, f func(c *api.ClickHouseInstallation, e error) bool) {
738738
if util.IsContextDone(ctx) {
739-
log.V(2).Info("task is done")
739+
log.V(1).Info("Reconcile is aborted. Polling CR: %s ", chi.GetName())
740740
return
741741
}
742742

@@ -747,7 +747,7 @@ func (c *Controller) poll(ctx context.Context, chi *api.ClickHouseInstallation,
747747
if f(cur.(*api.ClickHouseInstallation), err) {
748748
// Continue polling
749749
if util.IsContextDone(ctx) {
750-
log.V(2).Info("task is done")
750+
log.V(1).Info("Reconcile is aborted. Polling CR: %s ", chi.GetName())
751751
return
752752
}
753753
time.Sleep(15 * time.Second)
@@ -761,7 +761,7 @@ func (c *Controller) poll(ctx context.Context, chi *api.ClickHouseInstallation,
761761
// installFinalizer
762762
func (c *Controller) installFinalizer(ctx context.Context, chi *api.ClickHouseInstallation) error {
763763
if util.IsContextDone(ctx) {
764-
log.V(2).Info("task is done")
764+
log.V(1).Info("Reconcile is aborted. CR install fn: %s ", chi.GetName())
765765
return nil
766766
}
767767

@@ -789,7 +789,7 @@ func (c *Controller) installFinalizer(ctx context.Context, chi *api.ClickHouseIn
789789
// uninstallFinalizer
790790
func (c *Controller) uninstallFinalizer(ctx context.Context, chi *api.ClickHouseInstallation) error {
791791
if util.IsContextDone(ctx) {
792-
log.V(2).Info("task is done")
792+
log.V(1).Info("Reconcile is aborted. CR uninstall fin: %s ", chi.GetName())
793793
return nil
794794
}
795795

pkg/controller/chi/labeler/labeler.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ func (l *Labeler) LabelMyObjectsTree(ctx context.Context) error {
7575
// name: clickhouse-operator
7676
// uid: a275a8a0-83ae-11e9-b92d-0208b778ea1a
7777

78-
if util.IsContextDone(ctx) {
79-
log.V(2).Info("task is done")
80-
return nil
81-
}
82-
8378
// What pod does operator run in?
8479
name, ok1 := chop.GetRuntimeParam(deployment.OPERATOR_POD_NAME)
8580
namespace, ok2 := chop.GetRuntimeParam(deployment.OPERATOR_POD_NAMESPACE)
@@ -255,11 +250,6 @@ func (l *Labeler) addLabels(labels map[string]string) map[string]string {
255250

256251
// appendLabelReadyOnPod appends Label "Ready" to the pod of the specified host
257252
func (l *Labeler) appendLabelReadyOnPod(ctx context.Context, host *api.Host) error {
258-
if util.IsContextDone(ctx) {
259-
log.V(2).Info("task is done")
260-
return nil
261-
}
262-
263253
pod, err := l.pod.Get(host)
264254
if err != nil {
265255
log.M(host).F().Error("FAIL get pod for host %s err:%v", host.Runtime.Address.NamespaceNameString(), err)
@@ -280,11 +270,6 @@ func (l *Labeler) appendLabelReadyOnPod(ctx context.Context, host *api.Host) err
280270

281271
// deleteLabelReadyOnPod deletes Label "Ready" from the pod of the specified host
282272
func (l *Labeler) deleteLabelReadyOnPod(ctx context.Context, host *api.Host) error {
283-
if util.IsContextDone(ctx) {
284-
log.V(2).Info("task is done")
285-
return nil
286-
}
287-
288273
if host == nil {
289274
return nil
290275
}
@@ -311,11 +296,6 @@ func (l *Labeler) deleteLabelReadyOnPod(ctx context.Context, host *api.Host) err
311296

312297
// appendAnnotationReadyOnService appends Annotation "Ready" to the service of the specified host
313298
func (l *Labeler) appendAnnotationReadyOnService(ctx context.Context, host *api.Host) error {
314-
if util.IsContextDone(ctx) {
315-
log.V(2).Info("task is done")
316-
return nil
317-
}
318-
319299
svc, err := l.service.Get(ctx, host)
320300
if err != nil {
321301
log.M(host).F().Error("FAIL get service for host %s err:%v", host.Runtime.Address.NamespaceNameString(), err)
@@ -336,11 +316,6 @@ func (l *Labeler) appendAnnotationReadyOnService(ctx context.Context, host *api.
336316

337317
// deleteAnnotationReadyOnService deletes Annotation "Ready" from the service of the specified host
338318
func (l *Labeler) deleteAnnotationReadyOnService(ctx context.Context, host *api.Host) error {
339-
if util.IsContextDone(ctx) {
340-
log.V(2).Info("task is done")
341-
return nil
342-
}
343-
344319
if host == nil {
345320
return nil
346321
}

pkg/controller/chi/worker-boilerplate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (w *worker) processReconcilePod(ctx context.Context, cmd *cmd_queue.Reconci
152152
// processItem processes one work item according to its type
153153
func (w *worker) processItem(ctx context.Context, item interface{}) error {
154154
if util.IsContextDone(ctx) {
155-
log.V(2).Info("task is done")
155+
log.V(1).Info("Reconcile is aborted")
156156
return nil
157157
}
158158

0 commit comments

Comments
 (0)