Skip to content

Commit

Permalink
Delete dummy CSI services during upgrade
Browse files Browse the repository at this point in the history
Longhorn 6581

Signed-off-by: Eric Weber <[email protected]>
  • Loading branch information
ejweber committed Oct 12, 2023
1 parent 8d8abc5 commit ba45b58
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion upgrade/v15xto160/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package v15xto160

import (
"context"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"

apierrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
"github.com/longhorn/longhorn-manager/types"
upgradeutil "github.com/longhorn/longhorn-manager/upgrade/util"
)

Expand All @@ -30,7 +35,11 @@ func UpgradeResources(namespace string, lhClient *lhclientset.Clientset, kubeCli
return err
}

return upgradeVolumeAttachments(namespace, lhClient, resourceMaps)
if err := upgradeVolumeAttachments(namespace, lhClient, resourceMaps); err != nil {
return err
}

return deleteCSIServices(namespace, kubeClient)
}

func upgradeVolumes(namespace string, lhClient *lhclientset.Clientset, resourceMaps map[string]interface{}) (err error) {
Expand Down Expand Up @@ -148,6 +157,36 @@ func upgradeVolumeAttachments(namespace string, lhClient *lhclientset.Clientset,
return nil
}

func deleteCSIServices(namespace string, kubeClient *clientset.Clientset) (err error) {
defer func() {
err = errors.Wrapf(err, upgradeLogPrefix+"delete CSI service failed")
}()

servicesToDelete := map[string]struct{}{
types.CSIAttacherName: {},
types.CSIProvisionerName: {},
types.CSIResizerName: {},
types.CSISnapshotterName: {},
}

servicesInCluster, err := kubeClient.CoreV1().Services(namespace).List(context.TODO(), v1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "failed to list all existing Longhorn services during the CSI service deletion")
}

for _, serviceInCluster := range servicesInCluster.Items {
if _, ok := servicesToDelete[serviceInCluster.Name]; !ok {
continue
}
if err = kubeClient.CoreV1().Services(namespace).Delete(context.TODO(), serviceInCluster.Name, v1.DeleteOptions{}); err != nil {
// Best effort. Dummy services have no function and no finalizer, so we can proceed on failure.
logrus.Warnf("Deprecated CSI dummy service could not be deleted during upgrade: %v", err)
}
}

return nil
}

func UpgradeResourcesStatus(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
// Currently there are no statuses to upgrade. See UpgradeResources -> upgradeVolumes or previous Longhorn versions
// for examples.
Expand Down

0 comments on commit ba45b58

Please sign in to comment.