@@ -17,13 +17,15 @@ limitations under the License.
1717package cstor
1818
1919import (
20+ "context"
2021 "encoding/json"
2122 "fmt"
2223
2324 cstorv1 "github.com/openebs/api/v2/pkg/apis/cstor/v1"
2425 maya "github.com/openebs/cstor-csi/pkg/utils"
2526 "github.com/pkg/errors"
2627 k8serrors "k8s.io/apimachinery/pkg/api/errors"
28+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2729)
2830
2931// (Kasakaze)todo: Determine whether it is csiVolume, if so, cvc must be backed up
@@ -83,10 +85,13 @@ func (p *Plugin) restoreCVC(volumeID, pvcName, pvcNamespace, snapName string) er
8385 rCount = fmt .Sprint (rcvc .Spec .Provision .ReplicaCount )
8486 cspcName = rcvc .ObjectMeta .Labels ["openebs.io/cstor-pool-cluster" ]
8587 snapshotID = ""
86- // (Kasakaze)todo: If the data is migrated to another cluster, the nodeID may not be the same
8788 nodeID = rcvc .Publish .NodeID
8889 policyName = rcvc .ObjectMeta .Labels ["openebs.io/volume-policy" ]
8990 )
91+ nodeID , err = p .getValidNodeID (nodeID )
92+ if err != nil {
93+ return errors .Cause (err )
94+ }
9095
9196 err = maya .ProvisionVolume (size , volumeID , rCount ,
9297 cspcName , snapshotID ,
@@ -114,3 +119,22 @@ func (p *Plugin) downloadCVC(volumeID, snapName string) (*cstorv1.CStorVolumeCon
114119
115120 return cvc , nil
116121}
122+
123+ // If the backup cvc nodeID does not belong to the current cluster, use the environment variable OPENEBS_NODE_ID
124+ func (p * Plugin ) getValidNodeID (nodeID string ) (string , error ) {
125+ if nodeID == "" {
126+ return p .nodeID , nil
127+ }
128+
129+ _ , err := p .K8sClient .CoreV1 ().Nodes ().Get (context .TODO (), nodeID , metav1.GetOptions {})
130+ if err != nil {
131+ if ! k8serrors .IsNotFound (err ) {
132+ return "" , errors .Cause (err )
133+ }
134+
135+ p .Log .Warnf ("invalid nodeID(%s), use env VELERO_NODE_ID(%s)" , nodeID , p .nodeID )
136+ nodeID = p .nodeID
137+ }
138+
139+ return nodeID , nil
140+ }
0 commit comments