GitLabgitlab-org

cli

main
ply9 git calls200 ms99 KiB7 cachedprotocol v2
184 lines5.4 KiBRaw
1package bootstrap
3import (
4 "bytes"
5 "errors"
6 "fmt"
7 "os"
8 "path"
9 "time"
11 "github.com/avast/retry-go/v5"
12 "go.yaml.in/yaml/v3"
15var _ FluxWrapper = (*localFluxWrapper)(nil)
17func NewLocalFluxWrapper(
18 cmd Cmd,
19 binary string,
20 manifestPath string,
21 helmRepositoryAddress string,
22 helmRepositoryName string,
23 helmRepositoryNamespace string,
24 helmRepositoryFilepath string,
25 helmReleaseName string,
26 helmReleaseNamespace string,
27 helmReleaseFilepath string,
28 helmReleaseTargetNamespace string,
29 helmReleaseValues []string,
30 helmReleaseValuesFrom []string,
31 fluxSourceType string,
32 fluxSourceNamespace string,
33 fluxSourceName string,
34) FluxWrapper {
35 return &localFluxWrapper{
36 cmd: cmd,
37 binary: binary,
38 manifestPath: manifestPath,
39 helmRepositoryAddress: helmRepositoryAddress,
40 helmRepositoryName: helmRepositoryName,
41 helmRepositoryNamespace: helmRepositoryNamespace,
42 helmRepositoryFilepath: helmRepositoryFilepath,
43 helmReleaseName: helmReleaseName,
44 helmReleaseNamespace: helmReleaseNamespace,
45 helmReleaseFilepath: helmReleaseFilepath,
46 helmReleaseTargetNamespace: helmReleaseTargetNamespace,
47 helmReleaseValues: helmReleaseValues,
48 helmReleaseValuesFrom: helmReleaseValuesFrom,
49 fluxSourceType: fluxSourceType,
50 fluxSourceNamespace: fluxSourceNamespace,
51 fluxSourceName: fluxSourceName,
53 reconcileRetryDelay: 10 * time.Second,
54 }
57type localFluxWrapper struct {
58 cmd Cmd
59 binary string
60 manifestPath string
61 helmRepositoryAddress string
62 helmRepositoryName string
63 helmRepositoryNamespace string
64 helmRepositoryFilepath string
65 helmReleaseName string
66 helmReleaseNamespace string
67 helmReleaseFilepath string
68 helmReleaseTargetNamespace string
69 helmReleaseValues []string
70 helmReleaseValuesFrom []string
71 fluxSourceType string
72 fluxSourceNamespace string
73 fluxSourceName string
74 reconcileRetryDelay time.Duration
77func (f *localFluxWrapper) createHelmRepositoryManifest() (file, error) {
78 helmRepositoryYAML, err := f.cmd.RunWithOutput(
79 f.binary,
80 "create",
81 "source",
82 "helm",
83 f.helmRepositoryName,
84 "--export",
85 fmt.Sprintf("-n=%s", f.helmRepositoryNamespace),
86 fmt.Sprintf("--url=%s", f.helmRepositoryAddress),
87 )
88 if err != nil {
89 return file{}, err
90 }
92 return file{path: path.Join(f.manifestPath, f.helmRepositoryFilepath), content: helmRepositoryYAML}, nil
95type agentHelmChartValues struct {
96 Config *agentHelmChartValuesConfig `yaml:"config"`
99type agentHelmChartValuesConfig struct {
100 KASAddress string `yaml:"kasAddress"`
101 SecretName string `yaml:"secretName"`
104func (f *localFluxWrapper) createHelmReleaseManifest(kasAddress string) (file, error) {
105 // create temporary file for Flux CLI to read values from.
106 // The Flux CLI does not yet support reading values from literal flags.
107 valuesFile, err := os.CreateTemp("", "glab-bootstrap-helmrelease-values")
108 if err != nil {
109 return file{}, err
110 }
111 defer os.Remove(valuesFile.Name())
112 defer valuesFile.Close()
114 cfg := &agentHelmChartValues{
115 Config: &agentHelmChartValuesConfig{
116 KASAddress: kasAddress,
117 SecretName: "gitlab-agent-token",
118 },
119 }
121 enc := yaml.NewEncoder(valuesFile)
122 if err := enc.Encode(cfg); err != nil {
123 return file{}, err
124 }
126 args := []string{
127 "create",
128 "helmrelease",
129 f.helmReleaseName,
130 "--export",
131 fmt.Sprintf("-n=%s", f.helmReleaseNamespace),
132 fmt.Sprintf("--target-namespace=%s", f.helmReleaseTargetNamespace),
133 "--create-target-namespace=true",
134 fmt.Sprintf("--source=HelmRepository/%s.%s", f.helmRepositoryName, f.helmRepositoryNamespace),
135 "--chart=gitlab-agent",
136 fmt.Sprintf("--release-name=%s", f.helmReleaseName),
137 fmt.Sprintf("--values=%s", valuesFile.Name()),
138 }
140 for _, v := range f.helmReleaseValues {
141 args = append(args, fmt.Sprintf("--values=%s", v))
142 }
143 for _, v := range f.helmReleaseValuesFrom {
144 args = append(args, fmt.Sprintf("--values-from=%s", v))
145 }
147 helmReleaseYAML, err := f.cmd.RunWithOutput(
148 f.binary,
149 args...,
150 )
151 if err != nil {
152 return file{}, err
153 }
155 return file{path: path.Join(f.manifestPath, f.helmReleaseFilepath), content: helmReleaseYAML}, nil
158func (f *localFluxWrapper) reconcile() error {
159 // reconcile flux source to pull new HelmRepository source
160 err := f.cmd.Run(f.binary, "reconcile", "source", f.fluxSourceType, f.fluxSourceName, fmt.Sprintf("-n=%s", f.fluxSourceNamespace))
161 if err != nil {
162 return err
163 }
165 // just reconciling doesn't mean that the HelmRelease now exists ... (bug in flux? At least very unfortunate behavior)
166 err = retry.New(retry.Attempts(6), retry.Delay(f.reconcileRetryDelay)).Do(func() error {
167 output, err := f.cmd.RunWithOutput(f.binary, "get", "helmreleases", f.helmReleaseName, fmt.Sprintf("-n=%s", f.helmReleaseNamespace))
168 if err != nil {
169 // flux always returns with exit code 0, even when the helmrelease does not exist (yet)
170 return retry.Unrecoverable(err)
171 }
173 if bytes.Contains(output, fmt.Appendf(nil, `HelmRelease object '%s' not found in "%s" namespace`, f.helmReleaseName, f.helmReleaseNamespace)) {
174 return errors.New(string(output))
175 }
177 return nil
178 })
179 if err != nil {
180 return err
181 }
183 return f.cmd.Run(f.binary, "reconcile", "helmrelease", f.helmReleaseName, fmt.Sprintf("-n=%s", f.helmReleaseNamespace), "--with-source")
Diagnostics9 git calls · 200 ms
CallStatusSizeTime0200 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 · 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=32926
git.response.cache=HIT
git.response.duration_ms=3
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=44
Open pack map
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=3
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:02001.8 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=1857
git.response.cache=HIT
git.response.duration_ms=2
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=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200200 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=200
git.response.cache=HIT
git.response.duration_ms=2
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=948ee807a1ee817af67f2df94421a202e82325f9
Open 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=adfacba5ff1f4fcf28dcaac12e2874f6d48a7934
Open 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=a621ec095c3ac7a33563831f77c04827c9c343d3
Open pack map
fetch2001.6 KiB187 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=186
git.response.bytes=1623
git.response.cache=MISS
git.response.duration_ms=187
git.fetch.wants=bf0b3d7ebc3f75427b64c77bf7bf49437369c42e
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=1623
git.pkt.payload.max=1596
git.sideband.band1.bytes=1596
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
a5eb08c4bdba21ca
Request
440e30ea…
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