GitLabgitlab-org
cli
main
1package delete
3import (
4 "context"
5 "errors"
6 "fmt"
7 "strconv"
8 "strings"
10 "github.com/MakeNowJust/heredoc/v2"
11 "github.com/spf13/cobra"
13 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
15 "gitlab.com/gitlab-org/cli/internal/api"
16 "gitlab.com/gitlab-org/cli/internal/cmdutils"
17 "gitlab.com/gitlab-org/cli/internal/iostreams"
18 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
19 "gitlab.com/gitlab-org/cli/internal/text"
20)
22type options struct {
23 io *iostreams.IOStreams
24 apiClient func(repoHost string) (*api.Client, error)
26 controllerID int64
27 runnerIDs []int64
28 instance bool
29 force bool
30}
32func NewCmd(f cmdutils.Factory) *cobra.Command {
33 opts := &options{
34 io: f.IO(),
35 apiClient: f.ApiClient,
36 }
38 cmd := &cobra.Command{
39 Use: "delete <controller-id> [flags]",
40 Short: `Delete a scope from a runner controller. (EXPERIMENTAL)`,
41 Long: heredoc.Docf(`
42 Deletes a scope from a runner controller. This is an administrator-only feature.
44 Use one of the following flags to specify the scope type:
46 - --instance: Remove an instance-level scope from the runner controller.
47 - --runner <id>: Remove a runner-level scope for a specific runner. Multiple IDs
48 can be comma-separated or specified by repeating the flag.
49 %s`, text.ExperimentalString),
50 Args: cobra.ExactArgs(1),
51 Example: heredoc.Doc(`
52 # Remove an instance-level scope from runner controller 42 (with confirmation)
53 glab runner-controller scope delete 42 --instance
55 # Remove an instance-level scope without confirmation
56 glab runner-controller scope delete 42 --instance --force
58 # Remove a runner-level scope for runner 5 from runner controller 42
59 glab runner-controller scope delete 42 --runner 5 --force
61 # Remove runner-level scopes for multiple runners
62 glab runner-controller scope delete 42 --runner 5 --runner 10 --force
63 glab runner-controller scope delete 42 --runner 5,10 --force`),
64 Annotations: map[string]string{
65 mcpannotations.Destructive: "true",
66 },
67 RunE: func(cmd *cobra.Command, args []string) error {
68 if err := opts.complete(args); err != nil {
69 return err
70 }
71 if err := opts.validate(cmd.Context()); err != nil {
72 return err
73 }
74 return opts.run(cmd.Context())
75 },
76 }
78 fl := cmd.Flags()
79 fl.BoolVar(&opts.instance, "instance", false, "Remove an instance-level scope.")
80 fl.Int64SliceVar(&opts.runnerIDs, "runner", nil, "Remove a runner-level scope for the specified runner ID. Multiple IDs can be comma-separated or specified by repeating the flag.")
81 fl.BoolVarP(&opts.force, "force", "f", false, "Skip confirmation prompt.")
83 cmd.MarkFlagsMutuallyExclusive("instance", "runner")
84 cmd.MarkFlagsOneRequired("instance", "runner")
86 return cmd
87}
89func (o *options) complete(args []string) error {
90 id, err := cmdutils.ParseID(args[0], "runner controller ID")
91 if err != nil {
92 return err
93 }
94 o.controllerID = id
95 return nil
96}
98func (o *options) validate(ctx context.Context) error {
99 if !o.force {
100 if !o.io.PromptEnabled() {
101 return cmdutils.FlagError{Err: errors.New("--force required when not running interactively")}
102 }
104 var confirmMsg string
105 switch {
106 case o.instance:
107 confirmMsg = fmt.Sprintf("Remove instance-level scope from runner controller %d?", o.controllerID)
108 default:
109 ids := make([]string, 0, len(o.runnerIDs))
110 for _, id := range o.runnerIDs {
111 ids = append(ids, strconv.FormatInt(id, 10))
112 }
113 confirmMsg = fmt.Sprintf("Remove runner-level scope for runner(s) %s from runner controller %d?", strings.Join(ids, ", "), o.controllerID)
114 }
116 var confirmed bool
117 err := o.io.Confirm(ctx, &confirmed, confirmMsg)
118 if err != nil {
119 return err
120 }
122 if !confirmed {
123 return cmdutils.CancelError()
124 }
125 }
126 return nil
127}
129func (o *options) run(ctx context.Context) error {
130 apiClient, err := o.apiClient("")
131 if err != nil {
132 return err
133 }
134 client := apiClient.Lab()
136 switch {
137 case o.instance:
138 _, err = client.RunnerControllerScopes.RemoveRunnerControllerInstanceScope(o.controllerID, gitlab.WithContext(ctx))
139 if err != nil {
140 return cmdutils.WrapError(err, "failed to remove instance-level scope")
141 }
142 o.io.LogInfof("Removed instance-level scope from runner controller %d\n", o.controllerID)
143 default:
144 for _, runnerID := range o.runnerIDs {
145 _, err = client.RunnerControllerScopes.RemoveRunnerControllerRunnerScope(o.controllerID, runnerID, gitlab.WithContext(ctx))
146 if err != nil {
147 return cmdutils.WrapError(err, fmt.Sprintf("failed to remove runner-level scope for runner %d", runnerID))
148 }
149 o.io.LogInfof("Removed runner-level scope for runner %d from runner controller %d\n", runnerID, o.controllerID)
150 }
151 }
153 return nil
154}
Diagnostics9 git calls · 348 ms
CallStatusSizeTime0348 ms
discover200185 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=185 git.server.agent=git/2.56.g1891de4-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=185 git.pkt.payload.max=35
ls-refs20058 KiB3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=59849 git.response.cache=UPDATING git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=731 git.pkt.data=730 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=59849 git.pkt.payload.max=143 git.ls_refs.count=730 git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=combine:blob:none+tree:2 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=1 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4273 git.pkt.payload.max=4173 git.sideband.band1.bytes=4173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=11 git.pack.bytes=4173 git.fetch.wide.objects=11 git.fetch.wide.extra_bytes=3930 git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=5 git.fetch.filter=tree:0 git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=22 git.pkt.data=20 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=32926 git.pkt.payload.max=32046 git.sideband.band1.bytes=32046 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=80 git.pack.bytes=32046 git.pack.ofs_delta=36 git.pack.ref_delta=0 git.pack.chain.max=2 git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91 git.pack.full=44Open pack map
fetchtree:02001.8 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=1857 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1857 git.pkt.payload.max=1830 git.sideband.band1.bytes=1830 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=1830 git.pack.trailer=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200323 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=323 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=8185a1b139a07a59fba10180a7318233adb22fc3 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=323 git.pkt.payload.max=296 git.sideband.band1.bytes=296 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=296 git.pack.trailer=ac106711ec2e15414437a5964de4b85c86703290Open pack map
fetchtree:0200196 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=196 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=2457618d95f2bcb98ae5f01c872bb42789a59b56 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=196 git.pkt.payload.max=169 git.sideband.band1.bytes=169 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=169 git.pack.trailer=02c3a461145a7ea4fb72afbfd8909e6ed3eedc5aOpen pack map
fetchtree:0200138 B · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=138 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=tree:0 git.fetch.wants=d0364dda4a4029e1452610cf9430977bfa67ac26 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=138 git.pkt.payload.max=111 git.sideband.band1.bytes=111 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=111 git.pack.trailer=b923cb56c89a2b5ff082f6143c46f5e5370e6777Open pack map
fetch2001.6 KiB329 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=329 git.response.bytes=1644 git.response.cache=MISS git.response.duration_ms=329 git.fetch.wants=d07c5e77fe025fc659ed9aafd061257f0e711df9 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1644 git.pkt.payload.max=1617 git.sideband.band1.bytes=1617 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://gitlab.com/gitlab-org/cli
- Ref
- refs/heads/main
- Commit
- 0dd7574dce9e385c5c30540e6c15657adc6bdce9
- cf-ray
- a5e1d8f26f99a151
- Request
- cc1c8656…
- Protocol
- v2 · sha1
- Agent
- git/2.56.g1891de4-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format