Skip to content

Commit c8a0920

Browse files
authored
[Feature] [TG-165] Kill pod forcefully (#896)
1 parent b296b83 commit c8a0920

22 files changed

+226
-157
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Do not check License V2 on Community images
55
- Add status.members.<group>.
66
- Define MemberReplacementRequired condition
7+
- Remove pod immediately when annotation is turned on
78

89
## [1.2.7](https://github.com/arangodb/kube-arangodb/tree/1.2.7) (2022-01-17)
910
- Add Plan BackOff functionality

pkg/apis/deployment/annotations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ const (
2525
ArangoDeploymentPodMaintenanceAnnotation = ArangoDeploymentAnnotationPrefix + "/maintenance"
2626
ArangoDeploymentPodRotateAnnotation = ArangoDeploymentAnnotationPrefix + "/rotate"
2727
ArangoDeploymentPodReplaceAnnotation = ArangoDeploymentAnnotationPrefix + "/replace"
28+
ArangoDeploymentPodDeleteNow = ArangoDeploymentAnnotationPrefix + "/delete_now"
2829
ArangoDeploymentPlanCleanAnnotation = "plan." + ArangoDeploymentAnnotationPrefix + "/clean"
2930
)

pkg/apis/deployment/v1/conditions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const (
5959

6060
// ConditionTypeTerminating indicates that the member is terminating but not yet terminated.
6161
ConditionTypeTerminating ConditionType = "Terminating"
62-
// ConditionTypeTerminating indicates that the deployment is up to date.
62+
// ConditionTypeUpToDate indicates that the deployment is up to date.
6363
ConditionTypeUpToDate ConditionType = "UpToDate"
6464
// ConditionTypeMarkedToRemove indicates that the member is marked to be removed.
6565
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"

pkg/apis/deployment/v1/plan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const (
7777
ActionTypeRotateMember ActionType = "RotateMember"
7878
// ActionTypeRotateStartMember causes a member to be shutdown and have it's pod removed. Do not wait to pod recover.
7979
ActionTypeRotateStartMember ActionType = "RotateStartMember"
80-
// ActionTypeRotateMember causes a member to be restored.
80+
// ActionTypeRotateStopMember causes a member to be restored.
8181
ActionTypeRotateStopMember ActionType = "RotateStopMember"
8282
// ActionTypeUpgradeMember causes a member to be shutdown and have it's pod removed, restarted with AutoUpgrade option, waited until termination and the restarted again.
8383
ActionTypeUpgradeMember ActionType = "UpgradeMember"
@@ -105,7 +105,7 @@ const (
105105
ActionTypeUpdateTLSSNI ActionType = "UpdateTLSSNI"
106106
// ActionTypeSetCurrentImage causes status.CurrentImage to be updated to the image given in the action.
107107
ActionTypeSetCurrentImage ActionType = "SetCurrentImage"
108-
// ActionTypeSetCurrentImage replace image of member to current one.
108+
// ActionTypeSetMemberCurrentImage replace image of member to current one.
109109
ActionTypeSetMemberCurrentImage ActionType = "SetMemberCurrentImage"
110110
// ActionTypeDisableClusterScaling turns off scaling DBservers and coordinators
111111
ActionTypeDisableClusterScaling ActionType = "ScalingDisabled"
@@ -115,7 +115,7 @@ const (
115115
ActionTypePVCResize ActionType = "PVCResize"
116116
// ActionTypePVCResized waits for PVC to resize for defined time
117117
ActionTypePVCResized ActionType = "PVCResized"
118-
// UpToDateUpdateResized define up to date annotation in spec
118+
// UpToDateUpdate define up to date annotation in spec
119119
UpToDateUpdate ActionType = "UpToDateUpdate"
120120
// ActionTypeBackupRestore restore plan
121121
ActionTypeBackupRestore ActionType = "BackupRestore"

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const (
5959

6060
// ConditionTypeTerminating indicates that the member is terminating but not yet terminated.
6161
ConditionTypeTerminating ConditionType = "Terminating"
62-
// ConditionTypeTerminating indicates that the deployment is up to date.
62+
// ConditionTypeUpToDate indicates that the deployment is up to date.
6363
ConditionTypeUpToDate ConditionType = "UpToDate"
6464
// ConditionTypeMarkedToRemove indicates that the member is marked to be removed.
6565
ConditionTypeMarkedToRemove ConditionType = "MarkedToRemove"

pkg/apis/deployment/v2alpha1/plan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const (
7777
ActionTypeRotateMember ActionType = "RotateMember"
7878
// ActionTypeRotateStartMember causes a member to be shutdown and have it's pod removed. Do not wait to pod recover.
7979
ActionTypeRotateStartMember ActionType = "RotateStartMember"
80-
// ActionTypeRotateMember causes a member to be restored.
80+
// ActionTypeRotateStopMember causes a member to be restored.
8181
ActionTypeRotateStopMember ActionType = "RotateStopMember"
8282
// ActionTypeUpgradeMember causes a member to be shutdown and have it's pod removed, restarted with AutoUpgrade option, waited until termination and the restarted again.
8383
ActionTypeUpgradeMember ActionType = "UpgradeMember"
@@ -105,7 +105,7 @@ const (
105105
ActionTypeUpdateTLSSNI ActionType = "UpdateTLSSNI"
106106
// ActionTypeSetCurrentImage causes status.CurrentImage to be updated to the image given in the action.
107107
ActionTypeSetCurrentImage ActionType = "SetCurrentImage"
108-
// ActionTypeSetCurrentImage replace image of member to current one.
108+
// ActionTypeSetMemberCurrentImage replace image of member to current one.
109109
ActionTypeSetMemberCurrentImage ActionType = "SetMemberCurrentImage"
110110
// ActionTypeDisableClusterScaling turns off scaling DBservers and coordinators
111111
ActionTypeDisableClusterScaling ActionType = "ScalingDisabled"
@@ -115,7 +115,7 @@ const (
115115
ActionTypePVCResize ActionType = "PVCResize"
116116
// ActionTypePVCResized waits for PVC to resize for defined time
117117
ActionTypePVCResized ActionType = "PVCResized"
118-
// UpToDateUpdateResized define up to date annotation in spec
118+
// UpToDateUpdate define up to date annotation in spec
119119
UpToDateUpdate ActionType = "UpToDateUpdate"
120120
// ActionTypeBackupRestore restore plan
121121
ActionTypeBackupRestore ActionType = "BackupRestore"

pkg/deployment/chaos/context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ package chaos
2323
import (
2424
"context"
2525

26-
v1 "k8s.io/api/core/v1"
27-
2826
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+
v1 "k8s.io/api/core/v1"
28+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
)
3030

3131
// Context provides methods to the chaos package.
@@ -34,7 +34,7 @@ type Context interface {
3434
GetSpec() api.DeploymentSpec
3535
// DeletePod deletes a pod with given name in the namespace
3636
// of the deployment. If the pod does not exist, the error is ignored.
37-
DeletePod(ctx context.Context, podName string) error
37+
DeletePod(ctx context.Context, podName string, options meta.DeleteOptions) error
3838
// GetOwnedPods returns a list of all pods owned by the deployment.
3939
GetOwnedPods(ctx context.Context) ([]v1.Pod, error)
4040
}

pkg/deployment/chaos/monkey.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ import (
2525
"math/rand"
2626
"time"
2727

28-
"github.com/arangodb/kube-arangodb/pkg/util/errors"
29-
3028
"github.com/rs/zerolog"
3129
"github.com/rs/zerolog/log"
30+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
31+
32+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3233
)
3334

3435
// Monkey is the service that introduces chaos in the deployment
@@ -87,7 +88,7 @@ func (m Monkey) killRandomPod(ctx context.Context) error {
8788
}
8889
p := pods[rand.Intn(len(pods))]
8990
m.log.Info().Str("pod-name", p.GetName()).Msg("Killing pod")
90-
if err := m.context.DeletePod(ctx, p.GetName()); err != nil {
91+
if err := m.context.DeletePod(ctx, p.GetName(), meta.DeleteOptions{}); err != nil {
9192
return errors.WithStack(err)
9293
}
9394
return nil

pkg/deployment/context_impl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,10 @@ func (d *Deployment) GetPod(ctx context.Context, podName string) (*core.Pod, err
389389

390390
// DeletePod deletes a pod with given name in the namespace
391391
// of the deployment. If the pod does not exist, the error is ignored.
392-
func (d *Deployment) DeletePod(ctx context.Context, podName string) error {
392+
func (d *Deployment) DeletePod(ctx context.Context, podName string, options meta.DeleteOptions) error {
393393
log := d.deps.Log
394394
err := globals.GetGlobalTimeouts().Kubernetes().RunWithTimeout(ctx, func(ctxChild context.Context) error {
395-
return d.PodsModInterface().Delete(ctxChild, podName, meta.DeleteOptions{})
395+
return d.PodsModInterface().Delete(ctxChild, podName, options)
396396
})
397397
if err != nil && !k8sutil.IsNotFound(err) {
398398
log.Debug().Err(err).Str("pod", podName).Msg("Failed to remove pod")

pkg/deployment/reconcile/action.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,20 @@ func getActionFactory(t api.ActionType) (actionFactory, bool) {
125125
f, ok := actions[t]
126126
return f, ok
127127
}
128+
129+
type actionSuccess struct{}
130+
131+
// NewActionSuccess returns action which always returns success.
132+
func NewActionSuccess() ActionCore {
133+
return actionSuccess{}
134+
}
135+
136+
// Start always returns true.
137+
func (actionSuccess) Start(_ context.Context) (bool, error) {
138+
return true, nil
139+
}
140+
141+
// CheckProgress always returns true.
142+
func (actionSuccess) CheckProgress(_ context.Context) (bool, bool, error) {
143+
return true, false, nil
144+
}

0 commit comments

Comments
 (0)