Skip to content

Commit f7105ea

Browse files
bigkevmcdhiddeco
authored andcommitted
Implement Size field on archived artifacts
This adds a Size field to Artifacts, which reflects the number of bytes written to the artifact when it's being archived. Signed-off-by: Kevin McDermott <[email protected]>
1 parent 25e6e16 commit f7105ea

14 files changed

+95
-5
lines changed

api/v1beta2/artifact_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ type Artifact struct {
5151
// artifact.
5252
// +required
5353
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
54+
55+
// Size is the number of bytes in the file.
56+
// +optional
57+
Size *int64 `json:"size,omitempty"`
5458
}
5559

5660
// HasRevision returns true if the given revision matches the current Revision

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ spec:
391391
in the origin source system. It can be a Git commit SHA, Git
392392
tag, a Helm index timestamp, a Helm chart version, etc.
393393
type: string
394+
size:
395+
description: Size is the number of bytes in the file.
396+
format: int64
397+
type: integer
394398
url:
395399
description: URL is the HTTP address of this artifact. It is used
396400
by the consumers of the artifacts to fetch and use the artifacts.

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ spec:
559559
in the origin source system. It can be a Git commit SHA, Git
560560
tag, a Helm index timestamp, a Helm chart version, etc.
561561
type: string
562+
size:
563+
description: Size is the number of bytes in the file.
564+
format: int64
565+
type: integer
562566
url:
563567
description: URL is the HTTP address of this artifact. It is used
564568
by the consumers of the artifacts to fetch and use the artifacts.
@@ -663,6 +667,10 @@ spec:
663667
in the origin source system. It can be a Git commit SHA, Git
664668
tag, a Helm index timestamp, a Helm chart version, etc.
665669
type: string
670+
size:
671+
description: Size is the number of bytes in the file.
672+
format: int64
673+
type: integer
666674
url:
667675
description: URL is the HTTP address of this artifact. It is
668676
used by the consumers of the artifacts to fetch and use the

config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ spec:
438438
in the origin source system. It can be a Git commit SHA, Git
439439
tag, a Helm index timestamp, a Helm chart version, etc.
440440
type: string
441+
size:
442+
description: Size is the number of bytes in the file.
443+
format: int64
444+
type: integer
441445
url:
442446
description: URL is the HTTP address of this artifact. It is used
443447
by the consumers of the artifacts to fetch and use the artifacts.

config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ spec:
364364
in the origin source system. It can be a Git commit SHA, Git
365365
tag, a Helm index timestamp, a Helm chart version, etc.
366366
type: string
367+
size:
368+
description: Size is the number of bytes in the file.
369+
format: int64
370+
type: integer
367371
url:
368372
description: URL is the HTTP address of this artifact. It is used
369373
by the consumers of the artifacts to fetch and use the artifacts.

controllers/artifact_matchers_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func (m matchArtifact) Match(actual interface{}) (success bool, err error) {
5454
if ok, err = Equal(m.expected.Checksum).Match(actualArtifact.Checksum); !ok {
5555
return ok, err
5656
}
57+
if ok, err = Equal(m.expected.Size).Match(actualArtifact.Size); !ok {
58+
return ok, err
59+
}
5760

5861
return ok, err
5962
}

controllers/bucket_controller_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func TestBucketReconciler_reconcileStorage(t *testing.T) {
200200
Revision: "c",
201201
Checksum: "2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6",
202202
URL: testStorage.Hostname + "/reconcile-storage/c.txt",
203+
Size: int64p(int64(len("c"))),
203204
},
204205
assertPaths: []string{
205206
"/reconcile-storage/c.txt",
@@ -251,6 +252,7 @@ func TestBucketReconciler_reconcileStorage(t *testing.T) {
251252
Revision: "f",
252253
Checksum: "3b9c358f36f0a31b6ad3e14f309c7cf198ac9246e8316f9ce543d5b19ac02b80",
253254
URL: testStorage.Hostname + "/reconcile-storage/hostname.txt",
255+
Size: int64p(int64(len("file"))),
254256
},
255257
},
256258
}

controllers/gitrepository_controller_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"net/http"
2223
"net/url"
2324
"os"
2425
"path/filepath"
@@ -818,6 +819,16 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
818819
wantErr: true,
819820
},
820821
}
822+
artifactSize := func(g *WithT, artifactURL string) *int64 {
823+
if artifactURL == "" {
824+
return nil
825+
}
826+
res, err := http.Get(artifactURL)
827+
g.Expect(err).NotTo(HaveOccurred())
828+
g.Expect(res.StatusCode).To(Equal(http.StatusOK))
829+
defer res.Body.Close()
830+
return &res.ContentLength
831+
}
821832

822833
for _, tt := range tests {
823834
t.Run(tt.name, func(t *testing.T) {
@@ -850,6 +861,10 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
850861
g.Expect(err != nil).To(Equal(tt.wantErr))
851862
g.Expect(got).To(Equal(tt.want))
852863

864+
if obj.Status.Artifact != nil {
865+
g.Expect(obj.Status.Artifact.Size).To(Equal(artifactSize(g, obj.Status.Artifact.URL)))
866+
}
867+
853868
if tt.afterFunc != nil {
854869
tt.afterFunc(g, obj)
855870
}

controllers/helmchart_controller_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ func TestHelmChartReconciler_reconcileStorage(t *testing.T) {
198198
Revision: "c",
199199
Checksum: "2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6",
200200
URL: testStorage.Hostname + "/reconcile-storage/c.txt",
201+
Size: int64p(int64(len("c"))),
201202
},
202203
assertPaths: []string{
203204
"/reconcile-storage/c.txt",
@@ -250,6 +251,7 @@ func TestHelmChartReconciler_reconcileStorage(t *testing.T) {
250251
Revision: "f",
251252
Checksum: "3b9c358f36f0a31b6ad3e14f309c7cf198ac9246e8316f9ce543d5b19ac02b80",
252253
URL: testStorage.Hostname + "/reconcile-storage/hostname.txt",
254+
Size: int64p(int64(len("file"))),
253255
},
254256
},
255257
}

0 commit comments

Comments
 (0)