mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
01163ea57b
This PR provides two commands: * `coder prebuilds pause` * `coder prebuilds resume` These allow the suspension of all prebuilds activity, intended for use if prebuilds are misbehaving.
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/serpent"
|
|
|
|
"github.com/coder/coder/v2/cli"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
func (r *RootCmd) prebuilds() *serpent.Command {
|
|
cmd := &serpent.Command{
|
|
Use: "prebuilds",
|
|
Short: "Manage Coder prebuilds",
|
|
Long: "Administrators can use these commands to manage prebuilt workspace settings.\n" + cli.FormatExamples(
|
|
cli.Example{
|
|
Description: "Pause Coder prebuilt workspace reconciliation.",
|
|
Command: "coder prebuilds pause",
|
|
},
|
|
cli.Example{
|
|
Description: "Resume Coder prebuilt workspace reconciliation if it has been paused.",
|
|
Command: "coder prebuilds resume",
|
|
},
|
|
),
|
|
Aliases: []string{"prebuild"},
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
return inv.Command.HelpHandler(inv)
|
|
},
|
|
Children: []*serpent.Command{
|
|
r.pausePrebuilds(),
|
|
r.resumePrebuilds(),
|
|
},
|
|
}
|
|
return cmd
|
|
}
|
|
|
|
func (r *RootCmd) pausePrebuilds() *serpent.Command {
|
|
client := new(codersdk.Client)
|
|
cmd := &serpent.Command{
|
|
Use: "pause",
|
|
Short: "Pause prebuilds",
|
|
Middleware: serpent.Chain(
|
|
serpent.RequireNArgs(0),
|
|
r.InitClient(client),
|
|
),
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
err := client.PutPrebuildsSettings(inv.Context(), codersdk.PrebuildsSettings{
|
|
ReconciliationPaused: true,
|
|
})
|
|
if err != nil {
|
|
return xerrors.Errorf("unable to pause prebuilds: %w", err)
|
|
}
|
|
|
|
_, _ = fmt.Fprintln(inv.Stderr, "Prebuilds are now paused.")
|
|
return nil
|
|
},
|
|
}
|
|
return cmd
|
|
}
|
|
|
|
func (r *RootCmd) resumePrebuilds() *serpent.Command {
|
|
client := new(codersdk.Client)
|
|
cmd := &serpent.Command{
|
|
Use: "resume",
|
|
Short: "Resume prebuilds",
|
|
Middleware: serpent.Chain(
|
|
serpent.RequireNArgs(0),
|
|
r.InitClient(client),
|
|
),
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
err := client.PutPrebuildsSettings(inv.Context(), codersdk.PrebuildsSettings{
|
|
ReconciliationPaused: false,
|
|
})
|
|
if err != nil {
|
|
return xerrors.Errorf("unable to resume prebuilds: %w", err)
|
|
}
|
|
|
|
_, _ = fmt.Fprintln(inv.Stderr, "Prebuilds are now resumed.")
|
|
return nil
|
|
},
|
|
}
|
|
return cmd
|
|
}
|