Skip to content

Commit

Permalink
add finalizers for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkrkr committed May 30, 2023
1 parent dd7638a commit e01d73a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/controller/association/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func TestReconciler_Reconcile_DeletionTimestamp(t *testing.T) {
kb := sampleKibanaWithESRef()
now := metav1.NewTime(time.Now())
kb.DeletionTimestamp = &now
kb.Finalizers = []string{"something"}
r := testReconciler(&kb)
res, err := r.Reconcile(context.Background(), reconcile.Request{NamespacedName: k8s.ExtractNamespacedName(&kb)})
// should do nothing
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/beat/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func withAnnotations(beat beatv1beta1.Beat, annotations map[string]string) *beat
func toBeDeleted(beat beatv1beta1.Beat) *beatv1beta1.Beat {
now := metav1.Now()
beat.DeletionTimestamp = &now
beat.Finalizers = []string{"something"}
return &beat
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/elasticsearch/driver/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type testPod struct {
healthy, toUpgrade, inCluster, terminating bool
uid types.UID
resourceVersion string
finalizers []string
}

func newTestPod(name string) testPod {
Expand All @@ -57,6 +58,7 @@ func (t testPod) isTerminating(v bool) testPod { t.terminating = v; ret
func (t testPod) withVersion(v string) testPod { t.version = v; return t }
func (t testPod) inStatefulset(ssetName string) testPod { t.ssetName = ssetName; return t }
func (t testPod) withResourceVersion(rv string) testPod { t.resourceVersion = rv; return t } //nolint:unparam
func (t testPod) withFinalizers(f []string) testPod { t.finalizers = f; return t }
func (t testPod) withRoles(roles ...esv1.NodeRole) testPod {
t.roles = make([]string, len(roles))
for i := range roles {
Expand Down Expand Up @@ -294,6 +296,7 @@ func (t testPod) toPod() corev1.Pod {
UID: t.uid,
DeletionTimestamp: deletionTimestamp,
ResourceVersion: t.resourceVersion,
Finalizers: t.finalizers,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ func TestUpgradePodsDeletion_Delete(t *testing.T) {
newTestPod("master-0").withRoles(esv1.MasterRole).isHealthy(true).needsUpgrade(true).isInCluster(true),
newTestPod("node-0").withRoles(esv1.DataRole).isHealthy(true).needsUpgrade(true).isInCluster(true),
newTestPod("node-1").withRoles(esv1.DataRole).isHealthy(true).needsUpgrade(true).isInCluster(true),
newTestPod("node-2").withRoles(esv1.DataRole).isHealthy(true).needsUpgrade(true).isInCluster(true).isTerminating(true),
newTestPod("node-2").withRoles(esv1.DataRole).isHealthy(true).needsUpgrade(true).isInCluster(true).
isTerminating(true).withFinalizers([]string{"something"}),
),
maxUnavailable: 2,
shardLister: migration.NewFakeShardLister(client.Shards{}),
Expand Down Expand Up @@ -1161,7 +1162,8 @@ func TestUpgradePodsDeletion_Delete(t *testing.T) {
health: tt.fields.health,
}
esClient := &fakeESClient{version: version.MustParse(tt.fields.esVersion), Shutdowns: tt.fields.shutdowns}
k8sClient := k8s.NewFakeClient(tt.fields.upgradeTestPods.toClientObjects(tt.fields.esVersion, tt.fields.maxUnavailable, tt.fields.podFilter, tt.fields.esAnnotations)...)
k8sClient := k8s.NewFakeClient(
tt.fields.upgradeTestPods.toClientObjects(tt.fields.esVersion, tt.fields.maxUnavailable, tt.fields.podFilter, tt.fields.esAnnotations)...)
nodeShutdown := shutdown.NewNodeShutdown(esClient, tt.fields.upgradeTestPods.podNamesToESNodeID(), client.Restart, "", crlog.Log)
es := tt.fields.upgradeTestPods.toES(tt.fields.esVersion, tt.fields.maxUnavailable, tt.fields.esAnnotations)
ctx := upgradeCtx{
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/elasticsearch/driver/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ func Test_healthyPods(t *testing.T) {
args: args{
pods: newUpgradeTestPods(
newTestPod("masters-2").inStatefulset("masters").withRoles(esv1.MasterRole).isHealthy(true).needsUpgrade(true).isInCluster(true).withResourceVersion("999"),
newTestPod("masters-1").inStatefulset("masters").withRoles(esv1.MasterRole).isHealthy(true).needsUpgrade(true).isInCluster(true).isTerminating(true).withResourceVersion("999"),
newTestPod("masters-1").inStatefulset("masters").withRoles(esv1.MasterRole).isHealthy(true).needsUpgrade(true).isInCluster(true).
isTerminating(true).withResourceVersion("999").withFinalizers([]string{"something"}),
newTestPod("masters-0").inStatefulset("masters").withRoles(esv1.MasterRole).isHealthy(true).needsUpgrade(true).isInCluster(true).withResourceVersion("999"),
),
statefulSets: sset.StatefulSetList{
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/maps/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ func TestReconcileMapsServer_Reconcile(t *testing.T) {
name: "Resource marked for deletion",
reconciler: ReconcileMapsServer{
Client: k8s.NewFakeClient(&v1alpha1.ElasticMapsServer{
ObjectMeta: metav1.ObjectMeta{Name: nsnFixture.Name, Namespace: nsnFixture.Namespace, DeletionTimestamp: &timeFixture, Generation: 2},
ObjectMeta: metav1.ObjectMeta{
Name: nsnFixture.Name,
Namespace: nsnFixture.Namespace,
DeletionTimestamp: &timeFixture, Generation: 2,
Finalizers: []string{"something"},
},
Status: v1alpha1.MapsStatus{
ObservedGeneration: 1,
},
Expand Down

0 comments on commit e01d73a

Please sign in to comment.