diff --git a/apis/apps/v1alpha1/nebulacluster_types.go b/apis/apps/v1alpha1/nebulacluster_types.go index 22a420a5..00ecefa8 100644 --- a/apis/apps/v1alpha1/nebulacluster_types.go +++ b/apis/apps/v1alpha1/nebulacluster_types.go @@ -185,7 +185,6 @@ type EmptyStruct struct{} type FailureHost struct { Host string `json:"host,omitempty"` PVCSet map[types.UID]EmptyStruct `json:"pvcSet,omitempty"` - DataBalanced *bool `json:"dataBalanced,omitempty"` PodRestarted bool `json:"podRestarted,omitempty"` PodRebuilt bool `json:"podRebuilt,omitempty"` NodeDown bool `json:"nodeDown,omitempty"` diff --git a/apis/apps/v1alpha1/zz_generated.deepcopy.go b/apis/apps/v1alpha1/zz_generated.deepcopy.go index 7096e456..92db0ce7 100644 --- a/apis/apps/v1alpha1/zz_generated.deepcopy.go +++ b/apis/apps/v1alpha1/zz_generated.deepcopy.go @@ -498,11 +498,6 @@ func (in *FailureHost) DeepCopyInto(out *FailureHost) { (*out)[key] = val } } - if in.DataBalanced != nil { - in, out := &in.DataBalanced, &out.DataBalanced - *out = new(bool) - **out = **in - } in.CreationTime.DeepCopyInto(&out.CreationTime) in.ConfirmationTime.DeepCopyInto(&out.ConfirmationTime) in.DeletionTime.DeepCopyInto(&out.DeletionTime) diff --git a/apis/go.mod b/apis/go.mod index 6607456f..feffe714 100644 --- a/apis/go.mod +++ b/apis/go.mod @@ -7,6 +7,7 @@ require ( github.com/vesoft-inc/nebula-go/v3 v3.6.0 k8s.io/api v0.27.10 k8s.io/apimachinery v0.27.10 + k8s.io/client-go v0.27.10 k8s.io/utils v0.0.0-20230209194617-a36077c30491 sigs.k8s.io/controller-runtime v0.15.2 ) @@ -26,4 +27,5 @@ require ( k8s.io/klog/v2 v2.90.1 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/apis/go.sum b/apis/go.sum index 06030139..2600365e 100644 --- a/apis/go.sum +++ b/apis/go.sum @@ -103,6 +103,8 @@ k8s.io/api v0.27.10 h1:VFvsFZxiG3qeKyMvSOlO6hzrB7CGk6CC0XI1hniBI28= k8s.io/api v0.27.10/go.mod h1:cDmAF4GtSVRO0+5hOY/Vo3lLCQMOp6FfrXZ94/gQwC0= k8s.io/apimachinery v0.27.10 h1:AlOhsgdtNPMYDMJyUDsj2HZDLKOf1qPfvbbo5O9m4jg= k8s.io/apimachinery v0.27.10/go.mod h1:IHu2ovJ60RqxyPSLmTel7KDLdOCRbpOxwtUBmwBnT/E= +k8s.io/client-go v0.27.10 h1:ZOrDrfTSsw+66NIkFMmnamKZ9TTs8WUaV8WRc9NhtJA= +k8s.io/client-go v0.27.10/go.mod h1:PhrjLdIJNy7L8liOPEzm6wNlMjhIRJeVbfvksTxKNqI= k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw= k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY= @@ -114,3 +116,4 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h6 sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/charts/nebula-operator/crds/nebulaclusters.yaml b/charts/nebula-operator/crds/nebulaclusters.yaml index 703f3cf1..259adbff 100644 --- a/charts/nebula-operator/crds/nebulaclusters.yaml +++ b/charts/nebula-operator/crds/nebulaclusters.yaml @@ -11792,8 +11792,6 @@ spec: creationTime: format: date-time type: string - dataBalanced: - type: boolean deletionTime: format: date-time type: string @@ -11881,8 +11879,6 @@ spec: creationTime: format: date-time type: string - dataBalanced: - type: boolean deletionTime: format: date-time type: string @@ -11978,8 +11974,6 @@ spec: creationTime: format: date-time type: string - dataBalanced: - type: boolean deletionTime: format: date-time type: string diff --git a/config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml b/config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml index 703f3cf1..259adbff 100644 --- a/config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml +++ b/config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml @@ -11792,8 +11792,6 @@ spec: creationTime: format: date-time type: string - dataBalanced: - type: boolean deletionTime: format: date-time type: string @@ -11881,8 +11879,6 @@ spec: creationTime: format: date-time type: string - dataBalanced: - type: boolean deletionTime: format: date-time type: string @@ -11978,8 +11974,6 @@ spec: creationTime: format: date-time type: string - dataBalanced: - type: boolean deletionTime: format: date-time type: string diff --git a/pkg/controller/component/storaged_cluster.go b/pkg/controller/component/storaged_cluster.go index e79e0f67..177d636e 100644 --- a/pkg/controller/component/storaged_cluster.go +++ b/pkg/controller/component/storaged_cluster.go @@ -575,10 +575,6 @@ func (c *storagedCluster) shouldRecover(nc *v1alpha1.NebulaCluster) (bool, []str defer func() { _ = metaClient.Disconnect() }() - spaces, err := metaClient.ListSpaces() - if err != nil { - return false, nil, err - } onlineHosts := make([]string, 0) hostItems, err := metaClient.ListHosts(meta.ListHostType_STORAGE) @@ -588,12 +584,7 @@ func (c *storagedCluster) shouldRecover(nc *v1alpha1.NebulaCluster) (bool, []str thriftPort := nc.StoragedComponent().GetPort(v1alpha1.StoragedPortNameThrift) for _, host := range hostItems { podName, ok := m[host.HostAddr.Host] - fh, exists := nc.Status.Storaged.FailureHosts[podName] - balanced := pointer.BoolDeref(fh.DataBalanced, false) if ok && host.Status == meta.HostStatus_ONLINE && host.HostAddr.Port == thriftPort { - if exists && len(spaces) > 0 && !balanced { - continue - } onlineHosts = append(onlineHosts, podName) } } diff --git a/pkg/controller/component/storaged_failover.go b/pkg/controller/component/storaged_failover.go index 4fbec4ca..0e179e91 100644 --- a/pkg/controller/component/storaged_failover.go +++ b/pkg/controller/component/storaged_failover.go @@ -24,13 +24,11 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" - "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/vesoft-inc/nebula-operator/apis/apps/v1alpha1" "github.com/vesoft-inc/nebula-operator/apis/pkg/label" "github.com/vesoft-inc/nebula-operator/pkg/kube" - "github.com/vesoft-inc/nebula-operator/pkg/nebula" utilerrors "github.com/vesoft-inc/nebula-operator/pkg/util/errors" ) @@ -51,37 +49,7 @@ func (s *storagedFailover) Failover(nc *v1alpha1.NebulaCluster) error { if err != nil { return err } - if len(readyPods) > 0 { - options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true)) - if err != nil { - return err - } - endpoints := []string{nc.GetMetadThriftConnAddress()} - metaClient, err := nebula.NewMetaClient(endpoints, options...) - if err != nil { - return err - } - defer func() { - err := metaClient.Disconnect() - if err != nil { - klog.Errorf("meta client disconnect failed: %v", err) - } - }() - - spaces, err := metaClient.ListSpaces() - if err != nil { - return err - } - if len(spaces) > 0 { - for _, podName := range readyPods { - fh, ok := nc.Status.Storaged.FailureHosts[podName] - if ok { - fh.DataBalanced = pointer.Bool(true) - nc.Status.Storaged.FailureHosts[podName] = fh - } - } - } return utilerrors.ReconcileErrorf("storaged pods [%v] are ready after restarted", readyPods) } if err := s.deleteFailurePodAndPVC(nc); err != nil { @@ -90,9 +58,6 @@ func (s *storagedFailover) Failover(nc *v1alpha1.NebulaCluster) error { if err := s.checkPendingPod(nc); err != nil { return err } - if err := s.balanceData(nc); err != nil { - return err - } return nil } @@ -235,69 +200,3 @@ func (s *storagedFailover) checkPendingPod(nc *v1alpha1.NebulaCluster) error { } return nil } - -func (s *storagedFailover) balanceData(nc *v1alpha1.NebulaCluster) error { - podNames := make([]string, 0) - for podName, fh := range nc.Status.Storaged.FailureHosts { - if pointer.BoolDeref(fh.DataBalanced, false) { - continue - } - pod, err := s.clientSet.Pod().GetPod(nc.Namespace, podName) - if err != nil { - return err - } - if !isPodHealthy(pod) { - return utilerrors.ReconcileErrorf("rebuilt storaged pod [%s/%s] is not healthy", nc.Namespace, podName) - } - podNames = append(podNames, podName) - } - if len(podNames) == 0 { - return nil - } - - options, err := nebula.ClientOptions(nc, nebula.SetIsMeta(true)) - if err != nil { - return err - } - endpoints := []string{nc.GetMetadThriftConnAddress()} - metaClient, err := nebula.NewMetaClient(endpoints, options...) - if err != nil { - klog.Errorf("create meta client failed: %v", err) - return err - } - defer func() { - err := metaClient.Disconnect() - if err != nil { - klog.Errorf("disconnect meta client failed: %v", err) - } - }() - - spaces, err := metaClient.ListSpaces() - if err != nil { - return err - } - if len(spaces) == 0 { - return utilerrors.ReconcileErrorf("storaged cluster [%s/%s] data balanced for recovery", nc.Namespace, nc.Name) - } - - if nc.Status.Storaged.BalancedSpaces == nil { - nc.Status.Storaged.BalancedSpaces = make([]int32, 0, len(spaces)) - } - for _, space := range spaces { - if contains(nc.Status.Storaged.BalancedSpaces, *space.Id.SpaceID) { - continue - } - if err := balanceSpace(s.clientSet, metaClient, nc, *space.Id.SpaceID); err != nil { - return err - } - } - - for podName, fh := range nc.Status.Storaged.FailureHosts { - fh.DataBalanced = pointer.Bool(true) - nc.Status.Storaged.FailureHosts[podName] = fh - } - - nc.Status.Storaged.BalancedSpaces = nil - nc.Status.Storaged.LastBalanceJob = nil - return utilerrors.ReconcileErrorf("storaged cluster [%s/%s] data balanced for recovery", nc.Namespace, nc.Name) -} diff --git a/pkg/nebula/meta_client.go b/pkg/nebula/meta_client.go index da961bac..e1bf9c36 100644 --- a/pkg/nebula/meta_client.go +++ b/pkg/nebula/meta_client.go @@ -74,7 +74,15 @@ func NewMetaClient(hosts []string, options ...Option) (MetaInterface, error) { if len(hosts) == 0 { return nil, ErrNoAvailableMetadEndpoints } - mc, err := newMetaConnection(hosts[0], options...) + var err error + var mc MetaInterface + for i := 0; i < len(hosts); i++ { + mc, err = newMetaConnection(hosts[i], options...) + if err != nil { + klog.Error(err) + continue + } + } if err != nil { return nil, err }