2018-05-11 15:34:36 +00:00
|
|
|
//
|
|
|
|
// DISCLAIMER
|
|
|
|
//
|
2020-03-04 10:25:14 +00:00
|
|
|
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
|
2018-05-11 15:34:36 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
|
|
|
//
|
|
|
|
// Author Ewout Prangsma
|
|
|
|
//
|
|
|
|
|
|
|
|
package deployment
|
|
|
|
|
|
|
|
import (
|
2021-03-23 15:47:28 +00:00
|
|
|
"context"
|
|
|
|
|
2020-06-08 11:30:32 +00:00
|
|
|
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
|
|
|
|
"github.com/arangodb/kube-arangodb/pkg/util"
|
2018-05-11 15:34:36 +00:00
|
|
|
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
|
2021-03-10 13:30:47 +00:00
|
|
|
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
|
2020-06-08 11:30:32 +00:00
|
|
|
core "k8s.io/api/core/v1"
|
|
|
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2018-05-11 15:34:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// removePodFinalizers removes all finalizers from all pods owned by us.
|
2021-03-10 13:30:47 +00:00
|
|
|
func (d *Deployment) removePodFinalizers(cachedStatus inspectorInterface.Inspector) error {
|
2018-05-11 15:34:36 +00:00
|
|
|
log := d.deps.Log
|
|
|
|
kubecli := d.GetKubeCli()
|
2020-06-08 11:30:32 +00:00
|
|
|
|
|
|
|
if err := cachedStatus.IteratePods(func(pod *core.Pod) error {
|
|
|
|
if err := k8sutil.RemovePodFinalizers(log, kubecli, pod, pod.GetFinalizers(), true); err != nil {
|
2018-05-11 15:34:36 +00:00
|
|
|
log.Warn().Err(err).Msg("Failed to remove pod finalizers")
|
2020-06-08 11:30:32 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-23 15:47:28 +00:00
|
|
|
if err := kubecli.CoreV1().Pods(pod.GetNamespace()).Delete(context.Background(), pod.GetName(), meta.DeleteOptions{
|
2020-06-08 11:30:32 +00:00
|
|
|
GracePeriodSeconds: util.NewInt64(1),
|
|
|
|
}); err != nil {
|
|
|
|
if !k8sutil.IsNotFound(err) {
|
|
|
|
log.Warn().Err(err).Msg("Failed to remove pod")
|
|
|
|
return err
|
|
|
|
}
|
2018-05-11 15:34:36 +00:00
|
|
|
}
|
2020-06-08 11:30:32 +00:00
|
|
|
return nil
|
|
|
|
}, inspector.FilterPodsByLabels(k8sutil.LabelsForDeployment(d.GetName(), ""))); err != nil {
|
|
|
|
return err
|
2018-05-11 15:34:36 +00:00
|
|
|
}
|
2020-06-08 11:30:32 +00:00
|
|
|
|
2018-05-11 15:34:36 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// removePVCFinalizers removes all finalizers from all PVCs owned by us.
|
2021-03-10 13:30:47 +00:00
|
|
|
func (d *Deployment) removePVCFinalizers(cachedStatus inspectorInterface.Inspector) error {
|
2018-05-11 15:34:36 +00:00
|
|
|
log := d.deps.Log
|
|
|
|
kubecli := d.GetKubeCli()
|
2020-06-08 11:30:32 +00:00
|
|
|
|
|
|
|
if err := cachedStatus.IteratePersistentVolumeClaims(func(pvc *core.PersistentVolumeClaim) error {
|
|
|
|
if err := k8sutil.RemovePVCFinalizers(log, kubecli, pvc, pvc.GetFinalizers(), true); err != nil {
|
2018-05-11 15:34:36 +00:00
|
|
|
log.Warn().Err(err).Msg("Failed to remove PVC finalizers")
|
2020-06-08 11:30:32 +00:00
|
|
|
return err
|
2018-05-11 15:34:36 +00:00
|
|
|
}
|
2020-06-08 11:30:32 +00:00
|
|
|
return nil
|
|
|
|
}, inspector.FilterPersistentVolumeClaimsByLabels(k8sutil.LabelsForDeployment(d.GetName(), ""))); err != nil {
|
|
|
|
return err
|
2018-05-11 15:34:36 +00:00
|
|
|
}
|
2020-06-08 11:30:32 +00:00
|
|
|
|
2018-05-11 15:34:36 +00:00
|
|
|
return nil
|
|
|
|
}
|