1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Bugfix] Adjust pod finalizers (#749)

This commit is contained in:
Adam Janikowski 2021-07-04 18:16:22 +02:00 committed by GitHub
parent 51299ac3a5
commit b068b884c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 1 deletions

View file

@ -4,6 +4,7 @@
- Switch K8S CRD API to V1 - Switch K8S CRD API to V1
- Deprecate Alpine image usage - Deprecate Alpine image usage
- Use persistent name and namespace in ArangoDeployment reconcilation loop - Use persistent name and namespace in ArangoDeployment reconcilation loop
- Remove finalizers when Server container is already terminated and reduce initial reconciliation delay
## [1.1.9](https://github.com/arangodb/kube-arangodb/tree/1.1.9) (2021-05-28) ## [1.1.9](https://github.com/arangodb/kube-arangodb/tree/1.1.9) (2021-05-28)
- Add IP, DNS, ShortDNS, HeadlessService (Default) communication methods - Add IP, DNS, ShortDNS, HeadlessService (Default) communication methods

View file

@ -253,7 +253,11 @@ func (d *Deployment) run() {
d.lookForServiceMonitorCRD() d.lookForServiceMonitorCRD()
inspectionInterval := maxInspectionInterval // Execute inspection for first time without delay of 10s
log.Debug().Msg("Initially inspect deployment...")
inspectionInterval := d.inspectDeployment(minInspectionInterval)
log.Debug().Str("interval", inspectionInterval.String()).Msg("...deployment inspect started")
for { for {
select { select {
case <-d.stopCh: case <-d.stopCh:

View file

@ -49,10 +49,18 @@ const (
func (r *Resources) runPodFinalizers(ctx context.Context, p *v1.Pod, memberStatus api.MemberStatus, updateMember func(api.MemberStatus) error) (util.Interval, error) { func (r *Resources) runPodFinalizers(ctx context.Context, p *v1.Pod, memberStatus api.MemberStatus, updateMember func(api.MemberStatus) error) (util.Interval, error) {
log := r.log.With().Str("pod-name", p.GetName()).Logger() log := r.log.With().Str("pod-name", p.GetName()).Logger()
var removalList []string var removalList []string
isServerContainerDead := !k8sutil.IsPodServerContainerRunning(p)
for _, f := range p.ObjectMeta.GetFinalizers() { for _, f := range p.ObjectMeta.GetFinalizers() {
switch f { switch f {
case constants.FinalizerPodAgencyServing: case constants.FinalizerPodAgencyServing:
log.Debug().Msg("Inspecting agency-serving finalizer") log.Debug().Msg("Inspecting agency-serving finalizer")
if isServerContainerDead {
log.Debug().Msg("Server Container is dead, removing finalizer")
removalList = append(removalList, f)
break
}
if err := r.inspectFinalizerPodAgencyServing(ctx, log, p, memberStatus, updateMember); err == nil { if err := r.inspectFinalizerPodAgencyServing(ctx, log, p, memberStatus, updateMember); err == nil {
removalList = append(removalList, f) removalList = append(removalList, f)
} else { } else {
@ -60,12 +68,23 @@ func (r *Resources) runPodFinalizers(ctx context.Context, p *v1.Pod, memberStatu
} }
case constants.FinalizerPodDrainDBServer: case constants.FinalizerPodDrainDBServer:
log.Debug().Msg("Inspecting drain dbserver finalizer") log.Debug().Msg("Inspecting drain dbserver finalizer")
if isServerContainerDead {
log.Debug().Msg("Server Container is dead, removing finalizer")
removalList = append(removalList, f)
break
}
if err := r.inspectFinalizerPodDrainDBServer(ctx, log, p, memberStatus, updateMember); err == nil { if err := r.inspectFinalizerPodDrainDBServer(ctx, log, p, memberStatus, updateMember); err == nil {
removalList = append(removalList, f) removalList = append(removalList, f)
} else { } else {
log.Debug().Err(err).Str("finalizer", f).Msg("Cannot remove Pod finalizer yet") log.Debug().Err(err).Str("finalizer", f).Msg("Cannot remove Pod finalizer yet")
} }
case constants.FinalizerDelayPodTermination: case constants.FinalizerDelayPodTermination:
if isServerContainerDead {
log.Debug().Msg("Server Container is dead, removing finalizer")
removalList = append(removalList, f)
break
}
s, _ := r.context.GetStatus() s, _ := r.context.GetStatus()
_, group, ok := s.Members.ElementByID(memberStatus.ID) _, group, ok := s.Members.ElementByID(memberStatus.ID)
if !ok { if !ok {

View file

@ -82,6 +82,22 @@ func GetPodByName(pods []core.Pod, podName string) (core.Pod, bool) {
return core.Pod{}, false return core.Pod{}, false
} }
// IsPodServerContainerRunning returns true if the arangodb container of the pod is still running
func IsPodServerContainerRunning(pod *core.Pod) bool {
for _, c := range pod.Status.ContainerStatuses {
if c.Name != ServerContainerName {
continue
}
if c.State.Terminated != nil {
return false
} else {
return true
}
}
return false
}
// IsPodSucceeded returns true if the arangodb container of the pod // IsPodSucceeded returns true if the arangodb container of the pod
// has terminated with exit code 0. // has terminated with exit code 0.
func IsPodSucceeded(pod *core.Pod) bool { func IsPodSucceeded(pod *core.Pod) bool {