Skip to content

Commit

Permalink
Remove headless services for instance manager pods
Browse files Browse the repository at this point in the history
longhorn-8844

Signed-off-by: Phan Le <phan.le@suse.com>
(cherry picked from commit 8ee07d1)
  • Loading branch information
PhanLe1010 committed Jul 2, 2024
1 parent fca1d4d commit d67e7b1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/longhorn/longhorn-manager/upgrade/v151to152"
"github.com/longhorn/longhorn-manager/upgrade/v15xto160"
"github.com/longhorn/longhorn-manager/upgrade/v160to161"
"github.com/longhorn/longhorn-manager/upgrade/v162to163"
"github.com/longhorn/longhorn-manager/upgrade/v1beta1"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
Expand Down Expand Up @@ -267,6 +268,12 @@ func doResourceUpgrade(namespace string, lhClient *lhclientset.Clientset, kubeCl
return err
}
}
if semver.Compare(lhVersionBeforeUpgrade, "v1.6.3") < 0 {
logrus.Info("Walking through the resource upgrade path v1.6.2 to v1.6.3")
if err := v162to163.UpgradeResources(namespace, lhClient, kubeClient, resourceMaps); err != nil {
return err
}
}
if err := upgradeutil.UpdateResources(namespace, lhClient, resourceMaps); err != nil {
return err
}
Expand Down
45 changes: 45 additions & 0 deletions upgrade/v162to163/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package v162to163

import (
"context"

"github.com/pkg/errors"

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

lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
)

const (
upgradeLogPrefix = "upgrade from v1.6.2 to v1.6.3: "
)

func UpgradeResources(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
if err := deleteInstanceManagerServices(namespace, kubeClient); err != nil {
return err
}
return nil
}

func UpgradeResourcesStatus(namespace string, lhClient *lhclientset.Clientset, kubeClient *clientset.Clientset, resourceMaps map[string]interface{}) error {
// Currently there are no resources status to upgrade. See previous Longhorn
// versions for examples.
return nil
}

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

instanceManagerServiceNames := []string{"longhorn-engine-manager", "longhorn-replica-manager"}

for _, serviceName := range instanceManagerServiceNames {
if err := kubeClient.CoreV1().Services(namespace).Delete(context.TODO(), serviceName, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
return err
}
}
return nil
}

0 comments on commit d67e7b1

Please sign in to comment.