Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/opensvc/om3
Browse files Browse the repository at this point in the history
  • Loading branch information
remimendes committed Sep 1, 2023
2 parents 4acfccb + 97f2eb7 commit 1fb1f3e
Show file tree
Hide file tree
Showing 204 changed files with 6,652 additions and 2,982 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* New placement policy `last start`. Use the mtime of `<objvar>/last_start` as the candidate sort key. More recent has higher priority.

* **breaking change:** Drop the --dry-run flag.

* **breaking change:** Drop the `default_mon_format` node keyword. It should be a user-level setting, not a node-level config.

* **breaking change:** Drop the `reboot` node command and associated keywords: `reboot.schedule`, `reboot.pre`, `reboot.once`, `reboot.blocking_pre`
Expand Down
19 changes: 2 additions & 17 deletions cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ func newCmdNodeGet() *cobra.Command {
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagEval(flags, &options.Eval)
addFlagKeyword(flags, &options.Keyword)
return cmd
}
Expand Down Expand Up @@ -1954,7 +1955,6 @@ func newCmdObjectDelete(kind string) *cobra.Command {
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagDryRun(flags, &options.DryRun)
addFlagRID(flags, &options.RID)
return cmd
}
Expand Down Expand Up @@ -2034,6 +2034,7 @@ func newCmdObjectGet(kind string) *cobra.Command {
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagEval(flags, &options.Eval)
addFlagKeyword(flags, &options.Keyword)
return cmd
}
Expand Down Expand Up @@ -2217,7 +2218,6 @@ func newCmdObjectProvision(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagLeader(flags, &options.Leader)
addFlagDisableRollback(flags, &options.DisableRollback)
Expand All @@ -2238,7 +2238,6 @@ func newCmdObjectPRStart(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
return cmd
}
Expand All @@ -2257,7 +2256,6 @@ func newCmdObjectPRStop(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
return cmd
}
Expand All @@ -2277,7 +2275,6 @@ func newCmdObjectPurge(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagLeader(flags, &options.Leader)
return cmd
Expand Down Expand Up @@ -2316,7 +2313,6 @@ func newCmdObjectRestart(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagDisableRollback(flags, &options.DisableRollback)
return cmd
Expand All @@ -2336,7 +2332,6 @@ func newCmdObjectSyncFull(kind string) *cobra.Command {
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagTarget(flags, &options.Target)
return cmd
Expand All @@ -2356,7 +2351,6 @@ func newCmdObjectSyncResync(kind string) *cobra.Command {
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
return cmd
}
Expand All @@ -2375,7 +2369,6 @@ func newCmdObjectSyncUpdate(kind string) *cobra.Command {
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagTarget(flags, &options.Target)
return cmd
Expand All @@ -2395,7 +2388,6 @@ func newCmdObjectRun(kind string) *cobra.Command {
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagDryRun(flags, &options.DryRun)
addFlagConfirm(flags, &options.Confirm)
addFlagCron(flags, &options.Cron)
return cmd
Expand Down Expand Up @@ -2432,7 +2424,6 @@ func newCmdObjectSetProvisioned(kind string) *cobra.Command {
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagDryRun(flags, &options.DryRun)
return cmd
}

Expand All @@ -2451,7 +2442,6 @@ func newCmdObjectSetUnprovisioned(kind string) *cobra.Command {
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagDryRun(flags, &options.DryRun)
return cmd
}

Expand All @@ -2469,7 +2459,6 @@ func newCmdObjectShutdown(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
return cmd
}
Expand All @@ -2489,7 +2478,6 @@ func newCmdObjectStart(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagDisableRollback(flags, &options.DisableRollback)
return cmd
Expand All @@ -2509,7 +2497,6 @@ func newCmdObjectStartStandby(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagDisableRollback(flags, &options.DisableRollback)
return cmd
Expand Down Expand Up @@ -2548,7 +2535,6 @@ func newCmdObjectStop(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
return cmd
}
Expand Down Expand Up @@ -2635,7 +2621,6 @@ func newCmdObjectUnprovision(kind string) *cobra.Command {
addFlagsLock(flags, &options.OptsLock)
addFlagsResourceSelector(flags, &options.OptsResourceSelector)
addFlagsTo(flags, &options.OptTo)
addFlagDryRun(flags, &options.DryRun)
addFlagForce(flags, &options.Force)
addFlagLeader(flags, &options.Leader)
return cmd
Expand Down
5 changes: 4 additions & 1 deletion cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ func addFlagsGlobal(flagSet *pflag.FlagSet, p *commands.OptsGlobal) {
flagSet.BoolVar(&p.Local, "local", false, "Inline action on local instance.")
flagSet.BoolVarP(&p.Quiet, "quiet", "q", false, "Display no logs and no progress.")
flagSet.StringVar(&p.Color, "color", "auto", "Output colorization yes|no|auto.")
flagSet.StringVar(&p.Format, "format", "auto", "Output format json|flat|auto.")
flagSet.StringVar(&p.Output, "format", "auto", "Output format json|flat|auto|tab=<header>:<jsonpath>,...")
flagSet.StringVarP(&p.Output, "output", "o", "auto", "Output format json|flat|auto|tab=<header>:<jsonpath>,...")
flagSet.StringVar(&p.Log, "log", "", "Display the logs on the console at the specified level.")
flagSet.StringVar(&p.Server, "server", "", "URI of the opensvc api server. scheme raw|https.")
flagSet.StringVar(&p.NodeSelector, "node", "", "Execute on a list of nodes.")
flagSet.StringVarP(&p.ObjectSelector, "service", "s", "", "Execute on a list of objects.")
flagSet.MarkHidden("format")

}

func addFlagsLock(flagSet *pflag.FlagSet, p *commands.OptsLock) {
Expand Down
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var (
configFlag string
colorFlag string
logFlag string
formatFlag string
selectorFlag string
serverFlag string
nodeFlag string
Expand Down Expand Up @@ -202,7 +201,6 @@ func init() {
cobra.OnInitialize(initConfig)
root.PersistentFlags().StringVar(&configFlag, "config", "", "Config file (default \"$HOME/.opensvc.yaml\").")
root.PersistentFlags().StringVar(&colorFlag, "color", "auto", "Output colorization yes|no|auto.")
root.PersistentFlags().StringVar(&formatFlag, "format", "auto", "Output format json|flat|auto.")
root.PersistentFlags().StringVar(&serverFlag, "server", "", "URI of the opensvc api server. scheme raw|https.")
root.PersistentFlags().StringVar(&logFlag, "log", "", "Display logs on the console at the specified level.")
root.PersistentFlags().BoolVar(&callerFlag, "caller", false, "Show caller <file>:<line> in logs.")
Expand Down
4 changes: 2 additions & 2 deletions cmd/svcapp_print_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func TestAppPrintStatusFlatJson(t *testing.T) {
for rid, c := range cases {
t.Logf("check rid %d, expected %v", rid, c)
for i, log := range c {
prefix := fmt.Sprintf("instances.node1.status.resources[%d].log[%d]", rid, i)
prefix := fmt.Sprintf("instances[0].status.resources[%d].log[%d]", rid, i)
searched := fmt.Sprintf("%s.message = %s%s%s", prefix, string('"'), log.Message, string('"'))
assert.Containsf(t, outS, searched, "%s not found in \n%s", searched, string(outS))

searched = fmt.Sprintf("%s.level = %s%s%s", prefix, string('"'), log.Level, string('"'))
assert.Containsf(t, outS, searched, "%s not found in \n%s", searched, string(outS))
}
mustNotExist := fmt.Sprintf("instances.node1.status.resources[%d].log[%d]", rid, len(c)+1)
mustNotExist := fmt.Sprintf("instances[0].status.resources[%d].log[%d]", rid, len(c)+1)
assert.NotContainsf(t, outS, mustNotExist, "extra log has been found: '%s' in \n'%s'", mustNotExist, outS)
}
}
11 changes: 0 additions & 11 deletions core/actioncontext/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
lockDisabledKey
propsKey
quietKey
dryRunKey
ridKey
rollbackDisabledKey
subsetKey
Expand Down Expand Up @@ -71,16 +70,6 @@ func Verbose(ctx context.Context) int {
return 0
}

func WithDryRun(ctx context.Context, v bool) context.Context {
return context.WithValue(ctx, dryRunKey, v)
}
func IsDryRun(ctx context.Context) bool {
if i := ctx.Value(dryRunKey); i != nil {
return i.(bool)
}
return false
}

func WithLeader(ctx context.Context, v bool) context.Context {
return context.WithValue(ctx, leaderKey, v)
}
Expand Down
6 changes: 0 additions & 6 deletions core/client/api/get_daemon_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ func (t *GetDaemonStatus) SetSelector(s string) *GetDaemonStatus {
return t
}

func (t *GetDaemonStatus) SetRelatives(s bool) *GetDaemonStatus {
t.relatives = &s
return t
}

func NewGetDaemonStatus(t api.ClientInterface) *GetDaemonStatus {
options := &GetDaemonStatus{
client: t,
Expand All @@ -43,7 +38,6 @@ func (t GetDaemonStatus) Get() ([]byte, error) {
params := api.GetDaemonStatusParams{
Namespace: t.namespace,
Selector: t.selector,
Relatives: t.relatives,
}
resp, err := t.client.GetDaemonStatus(context.Background(), &params)
if err != nil {
Expand Down
15 changes: 2 additions & 13 deletions core/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (s *Data) GetObjectStatus(p path.T) object.Digest {
data.Object, _ = s.Cluster.Object[ps]
for nodename, ndata := range s.Cluster.Node {
instanceStates := instance.States{}
instanceStates.Path = p
instanceStates.Node.FrozenAt = ndata.Status.FrozenAt
instanceStates.Node.Name = nodename
inst, ok := ndata.Instance[ps]
Expand All @@ -162,19 +163,7 @@ func (s *Data) GetObjectStatus(p path.T) object.Digest {
if inst.Monitor != nil {
instanceStates.Monitor = *inst.Monitor
}
data.Instances[nodename] = instanceStates
for _, relative := range instanceStates.Status.Parents {
ps := relative.String()
data.Parents[ps] = s.Cluster.Object[ps]
}
for _, relative := range instanceStates.Status.Children {
ps := relative.String()
data.Children[ps] = s.Cluster.Object[ps]
}
for _, relative := range instanceStates.Status.Slaves {
ps := relative.String()
data.Slaves[ps] = s.Cluster.Object[ps]
}
data.Instances = append(data.Instances, instanceStates)
}
return *data
}
16 changes: 11 additions & 5 deletions core/cluster/frame_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ func (f Frame) sObjectInstance(path string, node string, scope []string) string
} else {
instanceMonitor = instance.Monitor{}
}
var instanceConfig instance.Config
if inst.Config != nil {
instanceConfig = *inst.Config
} else {
instanceConfig = instance.Config{}
}
instanceStatus := *inst.Status
s += sObjectInstanceAvail(avail, instanceStatus)
s += sObjectInstanceAvail(avail, instanceStatus, instanceMonitor)
s += sObjectInstanceOverall(instanceStatus)
s += sObjectInstanceDRP(instanceStatus)
s += sObjectInstanceDRP(instanceConfig)
s += sObjectInstanceHALeader(instanceMonitor)
s += sObjectInstanceFrozen(instanceStatus)
s += sObjectInstanceUnprovisioned(instanceStatus)
Expand All @@ -33,8 +39,8 @@ func (f Frame) sObjectInstance(path string, node string, scope []string) string
return s + "\t"
}

func sObjectInstanceAvail(objectAvail status.T, instance instance.Status) string {
if instance.Preserved {
func sObjectInstanceAvail(objectAvail status.T, instance instance.Status, mon instance.Monitor) string {
if mon.Preserved {
return iconPreserved
}
switch instance.Avail {
Expand Down Expand Up @@ -69,7 +75,7 @@ func sObjectInstanceOverall(instance instance.Status) string {
return ""
}

func sObjectInstanceDRP(instance instance.Status) string {
func sObjectInstanceDRP(instance instance.Config) string {
if instance.DRP {
return iconDRP
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/array_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (t *CmdArrayLs) Run() error {
data, err = t.extractDaemon()
}
output.Renderer{
Format: t.Format,
Format: t.Output,
Color: t.Color,
Data: data,
HumanRenderer: func() string {
Expand Down
2 changes: 1 addition & 1 deletion core/commands/cluster_freeze.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (t *CmdClusterFreeze) Run() error {
nodeaction.WithAsyncTime(t.Time),
nodeaction.WithAsyncWait(t.Wait),
nodeaction.WithAsyncWatch(t.Watch),
nodeaction.WithFormat(t.Format),
nodeaction.WithFormat(t.Output),
nodeaction.WithColor(t.Color),
nodeaction.WithLocal(false),
).Do()
Expand Down
2 changes: 1 addition & 1 deletion core/commands/cluster_unfreeze.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (t *CmdClusterUnfreeze) Run() error {
nodeaction.WithAsyncTime(t.Time),
nodeaction.WithAsyncWait(t.Wait),
nodeaction.WithAsyncWatch(t.Watch),
nodeaction.WithFormat(t.Format),
nodeaction.WithFormat(t.Output),
nodeaction.WithColor(t.Color),
nodeaction.WithLocal(false),
).Do()
Expand Down
24 changes: 0 additions & 24 deletions core/commands/daemon_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,6 @@ type (
CmdDaemonCommon struct{}
)

func (t *CmdDaemonCommon) startDaemon() (err error) {
cmd := command.New(
command.WithName(os.Args[0]),
command.WithArgs([]string{"daemon", "start"}),
)
_, _ = fmt.Fprintf(os.Stdout, "Start daemon\n")
if err := cmd.Run(); err != nil {
return fmt.Errorf("%s: %w", cmd, err)
}
return nil
}

func (t *CmdDaemonCommon) stopDaemon() (err error) {
cmd := command.New(
command.WithName(os.Args[0]),
command.WithArgs([]string{"daemon", "stop"}),
)
_, _ = fmt.Fprintf(os.Stdout, "Stop daemon\n")
if err := cmd.Run(); err != nil {
return fmt.Errorf("%s: %w", cmd, err)
}
return nil
}

// isRunning returns true if daemon is running
func (t *CmdDaemonCommon) isRunning() bool {
cli, err := client.New()
Expand Down
2 changes: 1 addition & 1 deletion core/commands/daemon_dns_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (t *CmdDaemonDNSDump) Run() error {
return err
}
renderer := output.Renderer{
Format: t.Format,
Format: t.Output,
Color: t.Color,
Data: parsed,
Colorize: rawconfig.Colorize,
Expand Down
Loading

0 comments on commit 1fb1f3e

Please sign in to comment.