/
seaweed_maintenance.go
37 lines (27 loc) · 1.06 KB
/
seaweed_maintenance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package controllers
import (
"io/ioutil"
"os"
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
"github.com/seaweedfs/seaweedfs-operator/controllers/swadmin"
ctrl "sigs.k8s.io/controller-runtime"
)
func (r *SeaweedReconciler) maintenance(m *seaweedv1.Seaweed) (done bool, result ctrl.Result, err error) {
masters := getMasterPeersString(m)
r.Log.V(0).Info("wait to connect to masters", "masters", masters)
// this step blocks since the operator can not access the masters when running from outside of the k8s cluster
sa := swadmin.NewSeaweedAdmin(masters, ioutil.Discard)
// For now this is an example of the admin commands
// master by default has some maintenance commands already.
r.Log.V(0).Info("volume.list")
sa.Output = os.Stdout
if err := sa.ProcessCommand("volume.list"); err != nil {
r.Log.V(0).Info("volume.list", "error", err)
}
sa.ProcessCommand("lock")
if err := sa.ProcessCommand("volume.balance -force"); err != nil {
r.Log.V(0).Info("volume.balance", "error", err)
}
sa.ProcessCommand("unlock")
return ReconcileResult(nil)
}