Skip to content

Commit ea0a4c4

Browse files
committed
chore: review
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent ee521fa commit ea0a4c4

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

dagger/maintenance/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import (
1515

1616
type Maintenance struct{}
1717

18-
// Updates the OS dependencies in the system-libs directory for the specified extension(s)
18+
// UpdateOSLibs updates the OS dependencies in the system-libs directory for the specified extension(s)
1919
func (m *Maintenance) UpdateOSLibs(
2020
ctx context.Context,
21-
// The source directory containing the extension folders. Defaults to the current directory
22-
// +ignore=["dagger", ".github"]
23-
// +defaultPath="/"
21+
// The source directory containing the extension folders. Defaults to the current directory
22+
// +ignore=["dagger", ".github"]
23+
// +defaultPath="/"
2424
source *dagger.Directory,
25-
// The target extension to update OS libs for. Defaults to "all".
26-
// +default="all"
25+
// The target extension to update OS libs for. Defaults to "all".
26+
// +default="all"
2727
target string,
2828
) (*dagger.Directory, error) {
2929
extDir := source
@@ -50,7 +50,7 @@ func (m *Maintenance) UpdateOSLibs(
5050
return nil, err
5151
}
5252

53-
files := make([]*dagger.File, 0, len(matrix.Distributions)+len(matrix.MajorVersions))
53+
files := make([]*dagger.File, 0, len(matrix.Distributions)*len(matrix.MajorVersions))
5454
for _, distribution := range matrix.Distributions {
5555
for _, majorVersion := range matrix.MajorVersions {
5656
file, err := updateOSLibsOnTarget(
@@ -73,12 +73,12 @@ func (m *Maintenance) UpdateOSLibs(
7373
}), nil
7474
}
7575

76-
// Return a list in JSON format of the extensions requiring OS libs updates
76+
// UpdateOSLibsTargets return a list in JSON format of the extensions requiring OS libs updates
7777
func (m *Maintenance) UpdateOSLibsTargets(
7878
ctx context.Context,
79-
// The source directory containing the extension folders. Defaults to the current directory
80-
// +ignore=["dagger", ".github"]
81-
// +defaultPath="/"
79+
// The source directory containing the extension folders. Defaults to the current directory
80+
// +ignore=["dagger", ".github"]
81+
// +defaultPath="/"
8282
source *dagger.Directory,
8383
) (string, error) {
8484
targetExtensions, err := extensionsWithOSLibs(ctx, source)

dagger/maintenance/parse.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ const (
2929
)
3030

3131
func parseBuildMatrix(ctx context.Context, source *dagger.Directory, target string) (*buildMatrix, error) {
32-
bakeData, err := source.File(
33-
bakeFileName).Contents(ctx)
32+
bakeData, err := source.File(bakeFileName).Contents(ctx)
3433
if err != nil {
3534
return nil, err
3635
}
37-
metadata, err := source.File(
38-
path.Join(target, metadataFile)).Contents(ctx)
36+
metadata, err := source.File(path.Join(target, metadataFile)).Contents(ctx)
3937
if err != nil {
4038
return nil, err
4139
}
@@ -54,7 +52,6 @@ func parseBuildMatrix(ctx context.Context, source *dagger.Directory, target stri
5452
}
5553

5654
var matrix buildMatrix
57-
5855
for _, variable := range p.AllVariables {
5956
switch variable.Name {
6057
case "distributions":
@@ -79,27 +76,22 @@ func parseBuildMatrix(ctx context.Context, source *dagger.Directory, target stri
7976
return &matrix, nil
8077
}
8178

82-
func parseExtensionMetadata(ctx context.Context, source *dagger.Directory) (*extensionMetadata, error) {
79+
func parseExtensionMetadata(ctx context.Context, extensionDirectory *dagger.Directory) (*extensionMetadata, error) {
8380
type Config struct {
8481
Metadata extensionMetadata `hcl:"metadata"`
8582
Remain hcl.Body `hcl:",remain"`
8683
}
8784

88-
data, err := source.File(
89-
metadataFile).Contents(ctx)
85+
data, err := extensionDirectory.File(metadataFile).Contents(ctx)
9086
if err != nil {
9187
return nil, err
9288
}
9389

9490
var rootMeta Config
95-
err = hclsimple.Decode(
96-
metadataFile,
97-
[]byte(data),
98-
nil,
99-
&rootMeta,
100-
)
91+
err = hclsimple.Decode(metadataFile, []byte(data), nil, &rootMeta)
10192
if err != nil {
10293
return nil, err
10394
}
95+
10496
return &rootMeta.Metadata, nil
10597
}

dagger/maintenance/updatelibs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ func updateOSLibsOnTarget(
1515
distribution string,
1616
majorVersion string,
1717
) (*dagger.File, error) {
18-
postgresBaseImage := fmt.Sprintf("ghcr.io/cloudnative-pg/postgresql:%s-minimal-%s",
19-
majorVersion,
20-
distribution)
18+
postgresBaseImage := fmt.Sprintf("ghcr.io/cloudnative-pg/postgresql:%s-minimal-%s", majorVersion, distribution)
2119
packageName := fmt.Sprintf("postgresql-%s-%s", majorVersion, target)
2220
out, err := dag.Container().
2321
From(postgresBaseImage).
@@ -39,6 +37,7 @@ func updateOSLibsOnTarget(
3937
}
4038
}
4139
file := dag.File(fmt.Sprintf("%s-%s-os-libs.txt", majorVersion, distribution), result)
40+
4241
return file, nil
4342
}
4443

@@ -51,7 +50,7 @@ func extensionsWithOSLibs(
5150
return nil, err
5251
}
5352

54-
extensions := make(map[string]string, 0)
53+
extensions := make(map[string]string)
5554
for _, dir := range dirs {
5655
metadata, err := parseExtensionMetadata(ctx, dir)
5756
if err != nil {

0 commit comments

Comments
 (0)