@@ -29,6 +29,7 @@ import (
2929 "github.com/vesoft-inc/nebula-operator/apis/apps/v1alpha1"
3030 "github.com/vesoft-inc/nebula-operator/apis/pkg/label"
3131 "github.com/vesoft-inc/nebula-operator/pkg/kube"
32+ "github.com/vesoft-inc/nebula-operator/pkg/nebula"
3233 utilerrors "github.com/vesoft-inc/nebula-operator/pkg/util/errors"
3334)
3435
@@ -58,6 +59,49 @@ func (s *storagedFailover) Failover(nc *v1alpha1.NebulaCluster) error {
5859 if err := s .checkPendingPod (nc ); err != nil {
5960 return err
6061 }
62+
63+ options , err := nebula .ClientOptions (nc , nebula .SetIsMeta (true ))
64+ if err != nil {
65+ return err
66+ }
67+ endpoints := []string {nc .GetMetadThriftConnAddress ()}
68+ metaClient , err := nebula .NewMetaClient (endpoints , options ... )
69+ if err != nil {
70+ klog .Errorf ("create meta client failed: %v" , err )
71+ return err
72+ }
73+ defer func () {
74+ err := metaClient .Disconnect ()
75+ if err != nil {
76+ klog .Errorf ("disconnect meta client failed: %v" , err )
77+ }
78+ }()
79+
80+ spaces , err := metaClient .ListSpaces ()
81+ if err != nil {
82+ return err
83+ }
84+
85+ if len (spaces ) > 0 && nc .Status .Storaged .BalancedSpaces == nil {
86+ nc .Status .Storaged .BalancedSpaces = make ([]int32 , 0 , len (spaces ))
87+ }
88+
89+ for _ , space := range spaces {
90+ if contains (nc .Status .Storaged .BalancedSpaces , * space .Id .SpaceID ) {
91+ continue
92+ }
93+ if err := balanceSpace (s .clientSet , metaClient , nc , * space .Id .SpaceID ); err != nil {
94+ return err
95+ }
96+ if err := metaClient .BalanceLeader (* space .Id .SpaceID ); err != nil {
97+ return err
98+ }
99+ nc .Status .Storaged .BalancedSpaces = append (nc .Status .Storaged .BalancedSpaces , * space .Id .SpaceID )
100+ }
101+
102+ nc .Status .Storaged .BalancedSpaces = nil
103+ nc .Status .Storaged .LastBalanceJob = nil
104+
61105 return nil
62106}
63107
0 commit comments