GitLabgitlab-org
cli
main
1package bootstrap
3import (
4 "errors"
5 "fmt"
6 "io"
7 "os"
8 "os/exec"
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/cmdutils"
16 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
17)
19//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -typed -destination=./mocks_for_test.go -package=bootstrap gitlab.com/gitlab-org/cli/internal/commands/cluster/agent/bootstrap API,FluxWrapper,KubectlWrapper,Cmd
20//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -typed -destination=./stdlib_mocks_for_test.go -package=bootstrap "io" "Writer"
22type API interface {
23 GetDefaultBranch() (string, error)
24 GetAgentByName(name string) (*gitlab.Agent, error)
25 RegisterAgent(name string) (*gitlab.Agent, error)
26 ConfigureAgent(agent *gitlab.Agent, branch string) error
27 ConfigureEnvironment(agentID int64, name string, kubernetesNamespace string, fluxResourcePath string) error
28 CreateAgentToken(agentID int64) (*gitlab.AgentToken, error)
29 SyncFile(f file, branch string) error
30 GetKASAddress() (string, error)
31}
33type FluxWrapper interface {
34 createHelmRepositoryManifest() (file, error)
35 createHelmReleaseManifest(kasAddress string) (file, error)
36 reconcile() error
37}
39type KubectlWrapper interface {
40 createAgentTokenSecret(tokenID int64, token string) error
41}
43type (
44 APIFactory func(*gitlab.Client, any, *commitAuthor) API
45 KubectlWrapperFactory func(Cmd, string, string, string) KubectlWrapper
46 FluxWrapperFactory func(Cmd, string, string, string, string, string, string, string, string, string, string, []string, []string, string, string, string) FluxWrapper
47 CmdFactory func(io.Writer, io.Writer, []string) Cmd
48)
50var reconcileErr = errors.New("failed to reconcile the GitLab Agent")
52const (
53 kubectlBinaryName = "kubectl"
54 fluxBinaryName = "flux"
56 defaultCommitAuthorName = "glab"
57 defaultCommitAuthorEmail = "noreply@glab.gitlab.com"
58)
60type options struct {
61 manifestPath string
62 manifestBranch string
64 noReconcile bool
66 helmRepositoryAddress string
67 helmRepositoryName string
68 helmRepositoryNamespace string
69 helmRepositoryFilepath string
71 helmReleaseName string
72 helmReleaseNamespace string
73 helmReleaseFilepath string
74 helmReleaseTargetNamespace string
75 helmReleaseValues []string
76 helmReleaseValuesFrom []string
78 gitlabAgentTokenSecretName string
80 fluxSourceType string
81 fluxSourceNamespace string
82 fluxSourceName string
84 createEnvironment bool
85 environmentName string
86 environmentNamespace string
87 environmentFluxResourcePath string
89 createFluxEnvironment bool
90 fluxEnvironmentName string
91 fluxEnvironmentNamespace string
92 fluxEnvironmentFluxResourcePath string
94 useAPICommitAuthor bool
95 commitAuthor commitAuthor
96}
98func EnsureRequirements() error {
99 if _, err := exec.LookPath(kubectlBinaryName); err != nil {
100 return fmt.Errorf("unable to find %s binary in PATH", kubectlBinaryName)
101 }
102 if _, err := exec.LookPath(fluxBinaryName); err != nil {
103 return fmt.Errorf("unable to find %s binary in PATH", fluxBinaryName)
104 }
105 return nil
106}
108func NewCmdAgentBootstrap(f cmdutils.Factory, ensureRequirements func() error, af APIFactory, kwf KubectlWrapperFactory, fwf FluxWrapperFactory, cf CmdFactory) *cobra.Command {
109 var opts options
110 agentBootstrapCmd := &cobra.Command{
111 Use: "bootstrap <agent-name> [flags]",
112 Short: `Bootstrap a GitLab Agent for Kubernetes in a project.`,
113 Long: heredoc.Docf(`Bootstrap a GitLab Agent for Kubernetes (agentk) in a project.
115The first argument must be the name of the agent.
117It requires the %[1]skubectl%[1]s and %[1]sflux%[1]s commands to be accessible via %[1]s$PATH%[1]s.
119This command consists of multiple idempotent steps:
1211. Register the agent with the project.
1222. Configure the agent.
1233. Configure an environment with dashboard for the agent.
1244. Configure an environment with dashboard for FluxCD (if %[1]s--create-flux-environment%[1]s).
1255. Create a token for the agent.
126 - If the agent has reached the maximum amount of tokens,
127 the one that has not been used the longest is revoked
128 and a new one is created.
129 - If the agent has not reached the maximum amount of tokens,
130 a new one is created.
1316. Push the Kubernetes Secret that contains the token to the cluster.
1327. Create Flux HelmRepository and HelmRelease resources.
1338. Commit and Push the created Flux Helm resources to the manifest path.
1349. Trigger Flux reconciliation of GitLab Agent HelmRelease (unless %[1]s--no-reconcile%[1]s).
135`, "`"),
136 Example: heredoc.Doc(`
137 # Bootstrap "my-agent" to the root of the Git project in CWD, and trigger reconciliation
138 glab cluster agent bootstrap my-agent
140 # Bootstrap "my-agent" to "manifests/" of the Git project in CWD, and trigger reconciliation
141 # Especially useful when "flux bootstrap gitlab --path manifests/" is used.
142 # Make sure that the "--path" from the "flux bootstrap gitlab" command matches
143 # the "--manifest-path" of the "glab cluster agent bootstrap" command.
144 glab cluster agent bootstrap my-agent --manifest-path manifests/
146 # Bootstrap "my-agent" to "manifests/" of the Git project in CWD, and do not manually trigger a reconilication
147 glab cluster agent bootstrap my-agent --manifest-path manifests/ --no-reconcile
149 # Bootstrap "my-agent" without configuring an environment
150 glab cluster agent bootstrap my-agent --create-environment=false
152 # Bootstrap "my-agent" and configure an environment with custom name and Kubernetes namespace
153 glab cluster agent bootstrap my-agent --environment-name production --environment-namespace default
155 # Bootstrap "my-agent" without configuring a FluxCD environment
156 glab cluster agent bootstrap my-agent --create-flux-environment=false
158 # Bootstrap "my-agent" and configure a FluxCD environment with custom name and Kubernetes namespace
159 glab cluster agent bootstrap my-agent --flux-environment-name production-flux --flux-environment-namespace flux-system
161 # Bootstrap "my-agent" and pass additional GitLab Helm Chart values from a local file
162 glab cluster agent bootstrap my-agent --helm-release-values values.yaml
164 # Bootstrap "my-agent" and pass additional GitLab Helm Chart values from a Kubernetes ConfigMap
165 glab cluster agent bootstrap my-agent --helm-release-values-from ConfigMap/agent-config
167 # Bootstrap "my-agent" and commit with custom user
168 glab cluster agent bootstrap my-agent --commit-author-name="Tanuki" --commit-author-email="tanuki@example.com"
170 # Bootstrap "my-agent" with authenticated API user
171 glab cluster agent bootstrap my-agent --use-api-commit-author`),
172 Aliases: []string{"bs"},
173 Args: cobra.ExactArgs(1),
174 Annotations: map[string]string{
175 mcpannotations.Destructive: "true",
176 },
177 PreRunE: func(cmd *cobra.Command, args []string) error {
178 return ensureRequirements()
179 },
180 RunE: func(cmd *cobra.Command, args []string) error {
181 stdout, stderr := f.IO().StdOut, f.IO().StdErr
183 client, err := f.GitLabClient()
184 if err != nil {
185 return err
186 }
188 repo, err := f.BaseRepo()
189 if err != nil {
190 return err
191 }
193 var commitAuthor *commitAuthor
194 if !opts.useAPICommitAuthor {
195 commitAuthor = &opts.commitAuthor
196 }
197 api := af(client, repo.FullName(), commitAuthor)
199 if opts.manifestBranch == "" {
200 opts.manifestBranch, err = api.GetDefaultBranch()
201 if err != nil {
202 return err
203 }
204 }
206 var agentEnvironmentCfg *environmentConfiguration
207 if opts.createEnvironment {
208 agentEnvironmentCfg = &environmentConfiguration{
209 name: fmt.Sprintf("%s/%s", opts.helmReleaseNamespace, opts.helmReleaseName),
210 kubernetesNamespace: opts.helmReleaseTargetNamespace,
211 fluxResourcePath: fmt.Sprintf("helm.toolkit.fluxcd.io/v2beta1/namespaces/%s/helmreleases/%s", opts.helmReleaseNamespace, opts.helmReleaseName),
212 }
214 if cmd.Flags().Changed("environment-name") {
215 agentEnvironmentCfg.name = opts.environmentName
216 }
218 if cmd.Flags().Changed("environment-namespace") {
219 agentEnvironmentCfg.kubernetesNamespace = opts.environmentNamespace
220 }
222 if cmd.Flags().Changed("environment-flux-resource-path") {
223 agentEnvironmentCfg.fluxResourcePath = opts.environmentFluxResourcePath
224 }
225 }
227 var fluxEnvironmentCfg *environmentConfiguration
228 if opts.createFluxEnvironment {
229 fluxEnvironmentCfg = &environmentConfiguration{
230 name: fmt.Sprintf("%s/%s", opts.fluxSourceNamespace, opts.fluxSourceName),
231 kubernetesNamespace: opts.fluxSourceNamespace,
232 fluxResourcePath: "kustomize.toolkit.fluxcd.io/v1/namespaces/flux-system/kustomizations/flux-system",
233 }
235 if cmd.Flags().Changed("flux-environment-name") {
236 fluxEnvironmentCfg.name = opts.fluxEnvironmentName
237 }
239 if cmd.Flags().Changed("flux-environment-namespace") {
240 fluxEnvironmentCfg.kubernetesNamespace = opts.fluxEnvironmentNamespace
241 }
243 if cmd.Flags().Changed("flux-environment-flux-resource-path") {
244 fluxEnvironmentCfg.fluxResourcePath = opts.fluxEnvironmentFluxResourcePath
245 }
246 }
248 c := cf(stdout, stderr, os.Environ())
250 fluxWrapper := fwf(
251 c, fluxBinaryName, opts.manifestPath,
252 opts.helmRepositoryAddress,
253 opts.helmRepositoryName, opts.helmRepositoryNamespace, opts.helmRepositoryFilepath,
254 opts.helmReleaseName, opts.helmReleaseNamespace, opts.helmReleaseFilepath, opts.helmReleaseTargetNamespace,
255 opts.helmReleaseValues, opts.helmReleaseValuesFrom,
256 opts.fluxSourceType, opts.fluxSourceNamespace, opts.fluxSourceName,
257 )
259 return (&bootstrapCmd{
260 api: api,
261 stdout: stdout,
262 stderr: stderr,
263 agentName: args[0],
264 manifestBranch: opts.manifestBranch,
265 kubectl: kwf(c, kubectlBinaryName, opts.helmReleaseTargetNamespace, opts.gitlabAgentTokenSecretName),
266 flux: fluxWrapper,
267 noReconcile: opts.noReconcile,
268 agentEnvironmentCfg: agentEnvironmentCfg,
269 fluxEnvironmentCfg: fluxEnvironmentCfg,
270 }).run()
271 },
272 }
273 fl := agentBootstrapCmd.Flags()
274 fl.StringVarP(&opts.manifestPath, "manifest-path", "p", "", "Location of directory in Git repository for storing the GitLab Agent for Kubernetes Helm resources.")
275 fl.StringVarP(&opts.manifestBranch, "manifest-branch", "b", "", "Branch to commit the Flux Manifests to. Defaults to the project default branch.")
277 fl.BoolVar(&opts.noReconcile, "no-reconcile", false, "Do not trigger Flux reconciliation for GitLab Agent for Kubernetes Flux resource.")
279 // https://charts.gitlab.io is the GitLab’s official Helm charts repository address
280 fl.StringVar(&opts.helmRepositoryAddress, "helm-repository-address", "https://charts.gitlab.io", "Address of the HelmRepository.")
281 fl.StringVar(&opts.helmRepositoryName, "helm-repository-name", "gitlab", "Name of the Flux HelmRepository manifest.")
282 fl.StringVar(&opts.helmRepositoryNamespace, "helm-repository-namespace", "flux-system", "Namespace of the Flux HelmRepository manifest.")
283 fl.StringVar(&opts.helmRepositoryFilepath, "helm-repository-filepath", "gitlab-helm-repository.yaml", "File path within the GitLab Agent project to commit the Flux HelmRepository to.")
285 fl.StringVar(&opts.helmReleaseName, "helm-release-name", "gitlab-agent", "Name of the Flux HelmRelease manifest.")
286 fl.StringVar(&opts.helmReleaseNamespace, "helm-release-namespace", "flux-system", "Namespace of the Flux HelmRelease manifest.")
287 fl.StringVar(&opts.helmReleaseFilepath, "helm-release-filepath", "gitlab-agent-helm-release.yaml", "File path within the GitLab Agent project to commit the Flux HelmRelease to.")
288 fl.StringVar(&opts.helmReleaseTargetNamespace, "helm-release-target-namespace", "gitlab-agent", "Namespace of the GitLab Agent deployment.")
289 fl.StringSliceVar(&opts.helmReleaseValues, "helm-release-values", nil, "Local path to values.yaml files. Multiple files can be comma-separated or specified by repeating the flag.")
290 fl.StringSliceVar(&opts.helmReleaseValuesFrom, "helm-release-values-from", nil, "Kubernetes object reference that contains the values.yaml data key in the format '<kind>/<name>', where 'kind' must be one of: (Secret, ConfigMap). Multiple references can be comma-separated or specified by repeating the flag.")
292 fl.StringVar(&opts.gitlabAgentTokenSecretName, "gitlab-agent-token-secret-name", "gitlab-agent-token", "Name of the Secret where the token for the GitLab Agent is stored. The helm-release-target-namespace is implied for the namespace of the Secret.")
294 fl.StringVar(&opts.fluxSourceType, "flux-source-type", "git", "Source type of the flux-system, like Git, OCI, or Helm.")
295 fl.StringVar(&opts.fluxSourceNamespace, "flux-source-namespace", "flux-system", "Flux source namespace.")
296 fl.StringVar(&opts.fluxSourceName, "flux-source-name", "flux-system", "Flux source name.")
298 fl.BoolVar(&opts.createEnvironment, "create-environment", true, "Create an environment for the GitLab Agent.")
299 fl.StringVar(&opts.environmentName, "environment-name", "<helm-release-namespace>/<helm-release-name>", "Name of the environment for the GitLab Agent.")
300 fl.StringVar(&opts.environmentNamespace, "environment-namespace", "<helm-release-namespace>", "Kubernetes namespace of the environment for the GitLab Agent.")
301 fl.StringVar(&opts.environmentFluxResourcePath, "environment-flux-resource-path", "helm.toolkit.fluxcd.io/v2beta1/namespaces/<helm-release-namespace>/helmreleases/<helm-release-name>", "Flux resource path of the environment for the GitLab Agent.")
303 fl.BoolVar(&opts.createFluxEnvironment, "create-flux-environment", true, "Create an environment for FluxCD. Affects only the environment creation, not the use of Flux itself. Flux is always required for the bootstrap process.")
304 fl.StringVar(&opts.fluxEnvironmentName, "flux-environment-name", "<flux-source-namespace>/<flux-source-name>", "Name of the environment for FluxCD.")
305 fl.StringVar(&opts.fluxEnvironmentNamespace, "flux-environment-namespace", "<flux-source-namespace>", "Kubernetes namespace of the environment for FluxCD.")
306 fl.StringVar(&opts.fluxEnvironmentFluxResourcePath, "flux-environment-flux-resource-path", "kustomize.toolkit.fluxcd.io/v1/namespaces/flux-system/kustomizations/flux-system", "Flux resource path of the environment for FluxCD.")
308 fl.BoolVar(&opts.useAPICommitAuthor, "use-api-commit-author", false, "When creating Git commits use the user from the authenticated API request. Conflicts with '--commit-author-name' and '--commit-author-email'.")
309 fl.StringVar(&opts.commitAuthor.name, "commit-author-name", defaultCommitAuthorName, "The Git commit author name to use. Conflicts with '--use-api-commit-author'.")
310 fl.StringVar(&opts.commitAuthor.email, "commit-author-email", defaultCommitAuthorEmail, "The Git commit author email to use. Conflicts with '--use-api-commit-author'.")
311 agentBootstrapCmd.MarkFlagsMutuallyExclusive("use-api-commit-author", "commit-author-name")
312 agentBootstrapCmd.MarkFlagsMutuallyExclusive("use-api-commit-author", "commit-author-email")
314 return agentBootstrapCmd
315}
317type bootstrapCmd struct {
318 api API
319 stdout io.Writer
320 stderr io.Writer
321 agentName string
322 manifestBranch string
323 kubectl KubectlWrapper
324 flux FluxWrapper
325 noReconcile bool
326 agentEnvironmentCfg *environmentConfiguration
327 fluxEnvironmentCfg *environmentConfiguration
328}
330type file struct {
331 path string
332 content []byte
333}
335type environmentConfiguration struct {
336 name string
337 kubernetesNamespace string
338 fluxResourcePath string
339}
341func (c *bootstrapCmd) run() error {
342 // 1. Register the agent
343 fmt.Fprintf(c.stderr, "Registering Agent ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
344 agent, err := c.registerAgent()
345 if err != nil {
346 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
347 return err
348 }
349 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
351 // 2. Configure the Agent
352 fmt.Fprintf(c.stderr, "Configuring Agent ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
353 err = c.configureAgent(agent)
354 if err != nil {
355 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
356 return err
357 }
358 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
360 // 3. Configure Environment for Agent
361 fmt.Fprintf(c.stderr, "Configuring Environment with Dashboard for Agent ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
362 if c.agentEnvironmentCfg != nil {
363 err = c.configureEnvironment(agent, c.agentEnvironmentCfg)
364 if err != nil {
365 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
366 return err
367 }
368 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
369 } else {
370 fmt.Fprintf(c.stderr, "[SKIPPED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
371 }
373 // 4. Configure Environment for FluxCD
374 fmt.Fprintf(c.stderr, "Configuring Environment with Dashboard for FluxCD ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
375 if c.fluxEnvironmentCfg != nil {
376 err = c.configureEnvironment(agent, c.fluxEnvironmentCfg)
377 if err != nil {
378 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
379 return err
380 }
381 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
382 } else {
383 fmt.Fprintf(c.stderr, "[SKIPPED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
384 }
386 // 5. Create a token for the registered agent
387 fmt.Fprintf(c.stderr, "Creating Agent Token ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
388 agentToken, err := c.createAgentToken(agent)
389 if err != nil {
390 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
391 return err
392 }
393 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
395 // 6. Push token in Kubernetes secret to cluster
396 fmt.Fprintf(c.stderr, "Creating Kubernetes Secret with Agent Token ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
397 err = c.createAgentTokenKubernetesSecret(agentToken)
398 if err != nil {
399 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
400 return err
401 }
402 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
404 // 7. Create Flux Helm Resources
405 fmt.Fprintf(c.stderr, "Creating Flux Helm Resources ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
406 helmResourceFiles, err := c.createFluxHelmResources()
407 if err != nil {
408 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
409 return err
410 }
411 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
413 // 8. Sync Flux Helm Resources
414 fmt.Fprintf(c.stderr, "Syncing Flux Helm Resources ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
415 err = c.syncFluxHelmResourceFiles(helmResourceFiles)
416 if err != nil {
417 fmt.Fprintf(c.stderr, "[FAILED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
418 return err
419 }
420 fmt.Fprintf(c.stderr, "[OK]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
422 // 9. Flux Reconcile
423 fmt.Fprintf(c.stderr, "Reconciling Flux Helm Resources ... ") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
424 if !c.noReconcile {
425 fmt.Fprintln(c.stderr, "Output from flux command:") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
426 err = c.fluxReconcile()
427 if err != nil {
428 return fmt.Errorf("%w:\n%w", reconcileErr, err)
429 }
430 } else {
431 fmt.Fprintf(c.stderr, "[SKIPPED]\n") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
432 }
434 fmt.Fprintln(c.stderr, "Successfully bootstrapped the GitLab Agent") //nolint:forbidigo // c.stderr is an io.Writer mocked directly in tests, not IOStreams
435 return nil
436}
438func (c *bootstrapCmd) registerAgent() (*gitlab.Agent, error) {
439 agent, err := c.api.GetAgentByName(c.agentName)
440 if err != nil {
441 if !errors.Is(err, agentNotFoundErr) {
442 return nil, err
443 }
445 agent, err = c.api.RegisterAgent(c.agentName)
446 if err != nil {
447 return nil, err
448 }
449 }
450 return agent, nil
451}
453func (c *bootstrapCmd) configureAgent(agent *gitlab.Agent) error {
454 return c.api.ConfigureAgent(agent, c.manifestBranch)
455}
457func (c *bootstrapCmd) configureEnvironment(agent *gitlab.Agent, cfg *environmentConfiguration) error {
458 return c.api.ConfigureEnvironment(agent.ID, cfg.name, cfg.kubernetesNamespace, cfg.fluxResourcePath)
459}
461func (c *bootstrapCmd) createAgentToken(agent *gitlab.Agent) (*gitlab.AgentToken, error) {
462 return c.api.CreateAgentToken(agent.ID)
463}
465func (c *bootstrapCmd) createAgentTokenKubernetesSecret(token *gitlab.AgentToken) error {
466 return c.kubectl.createAgentTokenSecret(token.ID, token.Token)
467}
469func (c *bootstrapCmd) createFluxHelmResources() ([]file, error) {
470 helmRepository, err := c.flux.createHelmRepositoryManifest()
471 if err != nil {
472 return nil, err
473 }
475 kasAddress, err := c.api.GetKASAddress()
476 if err != nil {
477 return nil, err
478 }
480 helmRelease, err := c.flux.createHelmReleaseManifest(kasAddress)
481 if err != nil {
482 return nil, err
483 }
485 return []file{helmRepository, helmRelease}, nil
486}
488func (c *bootstrapCmd) syncFluxHelmResourceFiles(files []file) error {
489 for _, f := range files {
490 err := c.api.SyncFile(f, c.manifestBranch)
491 if err != nil {
492 return err
493 }
494 }
495 return nil
496}
498func (c *bootstrapCmd) fluxReconcile() error {
499 return c.flux.reconcile()
500}
Diagnostics9 git calls · 346 ms
CallStatusSizeTime0346 ms
discover200185 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 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 KiB · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=2 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
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=32926 git.response.cache=HIT git.response.duration_ms=2 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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · 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=4273 git.response.cache=HIT git.response.duration_ms=4 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: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:0200200 B · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=200 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=tree:0 git.fetch.wants=9988d47506dcbe3004b8b72cbdb9d66d6d75cda4 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=200 git.pkt.payload.max=173 git.sideband.band1.bytes=173 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=173 git.pack.trailer=948ee807a1ee817af67f2df94421a202e82325f9Open pack map
fetchtree:0200405 B · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=405 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=d271680e941992259de0ff84d4a04bcbba55f531 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=405 git.pkt.payload.max=378 git.sideband.band1.bytes=378 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=378 git.pack.trailer=adfacba5ff1f4fcf28dcaac12e2874f6d48a7934Open pack map
fetchtree:0200414 B · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=414 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=3c487cc16dcfeca6d024165580948fbb3a622e23 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=414 git.pkt.payload.max=387 git.sideband.band1.bytes=387 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=387 git.pack.trailer=a621ec095c3ac7a33563831f77c04827c9c343d3Open pack map
fetch2004.8 KiB332 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=331 git.response.bytes=4866 git.response.cache=MISS git.response.duration_ms=332 git.fetch.wants=b3d2941cfea1af9ce292fdc2a4d8c80bd6433d1b 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=4866 git.pkt.payload.max=4839 git.sideband.band1.bytes=4839 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
- a5eb08ac0db421ca
- Request
- 49d9d8d6…
- 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