Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin): Fix ability to have custom value for openebs.io/nodeid #451

Merged
merged 7 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Configure the custom topology keys (if needed). This can be used for many purpos
https://github.com/openebs/zfs-localpv/blob/HEAD/docs/faq.md#6-how-to-add-custom-topology-key

### Installation
In order to support moving data to a new node later on, you must label each node with a unique value for `openebs.io/nodeid`.
For more information on migrating data, please [see here](docs/faq.md#8-how-to-migrate-pvs-to-the-new-node-in-case-old-node-is-not-accessible)

We can install the latest release of OpenEBS ZFS driver by running the following command:
```bash
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/450-nodeid-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix regression introduced with v2.0.0 that caused the plugin code to not be able to start when a user sets openebs.io/nodeid
7 changes: 6 additions & 1 deletion pkg/driver/controller.go

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have some tests for the changes to both go classes

Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,12 @@ func (cs *controller) GetCapacity(

var availableCapacity int64
for _, nodeName := range nodeNames {
v, exists, err := zfsNodesCache.GetByKey(zfs.OpenEBSNamespace + "/" + nodeName)
mappedNodeId, mapErr := zfs.GetNodeID(nodeName)
if mapErr != nil {
klog.Warningf("Unable to find mapped node id for %s", nodeName)
mappedNodeId = nodeName
}
v, exists, err := zfsNodesCache.GetByKey(zfs.OpenEBSNamespace + "/" + mappedNodeId)
if err != nil {
klog.Warning("unexpected error after querying the zfsNode informer cache")
continue
Expand Down
43 changes: 39 additions & 4 deletions pkg/mgmt/zfsnode/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ package zfsnode

import (
"context"
"fmt"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/klog/v2"
"os"
"strings"
"sync"
"time"

Expand All @@ -27,7 +35,6 @@ import (
"github.com/openebs/zfs-localpv/pkg/zfs"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -60,10 +67,38 @@ func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}) error {
options.FieldSelector = fields.OneTermEqualSelector("metadata.name", zfs.NodeID).String()
}))

k8sNode, err := kubeClient.CoreV1().Nodes().Get(context.TODO(), zfs.NodeID, metav1.GetOptions{})
if err != nil {
return errors.Wrapf(err, "fetch k8s node %s", zfs.NodeID)
nodeName := os.Getenv("OPENEBS_NODE_NAME")
var k8sNode v1.Node

if len(strings.TrimSpace(zfs.NodeID)) == 0 || nodeName == zfs.NodeID {
k8sNodeCandidate, err := kubeClient.CoreV1().Nodes().Get(context.TODO(), zfs.NodeID, metav1.GetOptions{})

if err != nil {
return errors.Wrapf(err, "fetch k8s node %s", zfs.NodeID)
}

k8sNode = *k8sNodeCandidate

} else {
topologyRequirement, requirementError := labels.NewRequirement(zfs.ZFSTopologyKey, selection.Equals, []string{zfs.NodeID})
if requirementError != nil {
return errors.Wrapf(requirementError, "Unable to generate topology requirement by %s for node id %s", zfs.ZFSTopologyKey, zfs.NodeID)
}
topologySelector := labels.NewSelector().Add(*topologyRequirement).String()
klog.Infof("The topology selector is %s", topologySelector)

k8sNodeCandidate, err := kubeClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
LabelSelector: topologySelector,
})
if err != nil {
return errors.Wrapf(err, "error trying to find node with label %s having value %s", zfs.ZFSTopologyKey, zfs.NodeID)
}
if k8sNodeCandidate == nil || len(k8sNodeCandidate.Items) != 1 {
return fmt.Errorf("unable to retrieve a single node by %s for %s", zfs.ZFSTopologyKey, zfs.NodeID)
}
k8sNode = k8sNodeCandidate.Items[0]
}

isTrue := true
// as object returned by client go clears all TypeMeta from it.
nodeGVK := &schema.GroupVersionKind{
Expand Down
Loading