Skip to content

Commit 1023315

Browse files
committed
misc: various nits in doc blocks
Signed-off-by: Hidde Beydals <[email protected]>
1 parent f65e261 commit 1023315

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

controllers/gitrepository_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
rreconcile "github.com/fluxcd/pkg/runtime/reconcile"
5454

5555
"github.com/fluxcd/pkg/sourceignore"
56+
5657
sourcev1 "github.com/fluxcd/source-controller/api/v1"
5758
serror "github.com/fluxcd/source-controller/internal/error"
5859
"github.com/fluxcd/source-controller/internal/features"
@@ -381,8 +382,8 @@ func (r *GitRepositoryReconciler) shouldNotify(oldObj, newObj *sourcev1.GitRepos
381382
// it is removed from the object.
382383
// If the object does not have an Artifact in its Status, a Reconciling
383384
// condition is added.
384-
// The hostname of any URL in the Status of the object are updated, to ensure
385-
// they match the Storage server hostname of current runtime.
385+
// The hostname of the Artifact in the Status of the object is updated, to
386+
// ensure it matches the Storage server hostname of current runtime.
386387
func (r *GitRepositoryReconciler) reconcileStorage(ctx context.Context, sp *patch.SerialPatcher,
387388
obj *sourcev1.GitRepository, _ *git.Commit, _ *artifactSet, _ string) (sreconcile.Result, error) {
388389
// Garbage collect previous advertised artifact(s) from storage
@@ -606,8 +607,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
606607
// Source ignore patterns are loaded, and the given directory is archived while
607608
// taking these patterns into account.
608609
// On a successful archive, the Artifact, Includes, observed ignore, recurse
609-
// submodules and observed include in the Status of the object are set, and the
610-
// symlink in the Storage is updated to its path.
610+
// submodules and observed include in the Status of the object are set.
611611
func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, sp *patch.SerialPatcher,
612612
obj *sourcev1.GitRepository, commit *git.Commit, includes *artifactSet, dir string) (sreconcile.Result, error) {
613613

controllers/storage.go

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ import (
3939
"github.com/fluxcd/pkg/sourceignore"
4040
"github.com/fluxcd/pkg/untar"
4141

42-
sourcev1 "github.com/fluxcd/source-controller/api/v1"
42+
"github.com/fluxcd/source-controller/api/v1"
4343
intdigest "github.com/fluxcd/source-controller/internal/digest"
4444
sourcefs "github.com/fluxcd/source-controller/internal/fs"
4545
)
4646

4747
const GarbageCountLimit = 1000
4848

4949
const (
50-
// defaultFileMode is the permission mode applied to all files inside of an artifact archive.
50+
// defaultFileMode is the permission mode applied to all files inside an artifact archive.
5151
defaultFileMode int64 = 0o644
52-
// defaultDirMode is the permission mode applied to all directories inside of an artifact archive.
52+
// defaultDirMode is the permission mode applied to all directories inside an artifact archive.
5353
defaultDirMode int64 = 0o755
5454
)
5555

@@ -83,19 +83,19 @@ func NewStorage(basePath string, hostname string, artifactRetentionTTL time.Dura
8383
}, nil
8484
}
8585

86-
// NewArtifactFor returns a new v1beta1.Artifact.
87-
func (s *Storage) NewArtifactFor(kind string, metadata metav1.Object, revision, fileName string) sourcev1.Artifact {
88-
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
89-
artifact := sourcev1.Artifact{
86+
// NewArtifactFor returns a new v1.Artifact.
87+
func (s *Storage) NewArtifactFor(kind string, metadata metav1.Object, revision, fileName string) v1.Artifact {
88+
path := v1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
89+
artifact := v1.Artifact{
9090
Path: path,
9191
Revision: revision,
9292
}
9393
s.SetArtifactURL(&artifact)
9494
return artifact
9595
}
9696

97-
// SetArtifactURL sets the URL on the given v1beta1.Artifact.
98-
func (s Storage) SetArtifactURL(artifact *sourcev1.Artifact) {
97+
// SetArtifactURL sets the URL on the given v1.Artifact.
98+
func (s Storage) SetArtifactURL(artifact *v1.Artifact) {
9999
if artifact.Path == "" {
100100
return
101101
}
@@ -116,14 +116,14 @@ func (s Storage) SetHostname(URL string) string {
116116
return u.String()
117117
}
118118

119-
// MkdirAll calls os.MkdirAll for the given v1beta1.Artifact base dir.
120-
func (s *Storage) MkdirAll(artifact sourcev1.Artifact) error {
119+
// MkdirAll calls os.MkdirAll for the given v1.Artifact base dir.
120+
func (s *Storage) MkdirAll(artifact v1.Artifact) error {
121121
dir := filepath.Dir(s.LocalPath(artifact))
122122
return os.MkdirAll(dir, 0o700)
123123
}
124124

125-
// RemoveAll calls os.RemoveAll for the given v1beta1.Artifact base dir.
126-
func (s *Storage) RemoveAll(artifact sourcev1.Artifact) (string, error) {
125+
// RemoveAll calls os.RemoveAll for the given v1.Artifact base dir.
126+
func (s *Storage) RemoveAll(artifact v1.Artifact) (string, error) {
127127
var deletedDir string
128128
dir := filepath.Dir(s.LocalPath(artifact))
129129
// Check if the dir exists.
@@ -134,8 +134,8 @@ func (s *Storage) RemoveAll(artifact sourcev1.Artifact) (string, error) {
134134
return deletedDir, os.RemoveAll(dir)
135135
}
136136

137-
// RemoveAllButCurrent removes all files for the given v1beta1.Artifact base dir, excluding the current one.
138-
func (s *Storage) RemoveAllButCurrent(artifact sourcev1.Artifact) ([]string, error) {
137+
// RemoveAllButCurrent removes all files for the given v1.Artifact base dir, excluding the current one.
138+
func (s *Storage) RemoveAllButCurrent(artifact v1.Artifact) ([]string, error) {
139139
deletedFiles := []string{}
140140
localPath := s.LocalPath(artifact)
141141
dir := filepath.Dir(localPath)
@@ -168,7 +168,7 @@ func (s *Storage) RemoveAllButCurrent(artifact sourcev1.Artifact) ([]string, err
168168
// 1. collect all artifact files with an expired ttl
169169
// 2. if we satisfy maxItemsToBeRetained, then return
170170
// 3. else, collect all artifact files till the latest n files remain, where n=maxItemsToBeRetained
171-
func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, maxItemsToBeRetained int, ttl time.Duration) (garbageFiles []string, _ error) {
171+
func (s *Storage) getGarbageFiles(artifact v1.Artifact, totalCountLimit, maxItemsToBeRetained int, ttl time.Duration) (garbageFiles []string, _ error) {
172172
localPath := s.LocalPath(artifact)
173173
dir := filepath.Dir(localPath)
174174
artifactFilesWithCreatedTs := make(map[time.Time]string)
@@ -219,7 +219,7 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
219219
return garbageFiles, nil
220220
}
221221

222-
// sort all timestamps in an ascending order.
222+
// sort all timestamps in ascending order.
223223
sort.Slice(creationTimestamps, func(i, j int) bool { return creationTimestamps[i].Before(creationTimestamps[j]) })
224224
for _, ts := range creationTimestamps {
225225
path, ok := artifactFilesWithCreatedTs[ts]
@@ -233,7 +233,7 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
233233
noOfGarbageFiles := len(garbageFiles)
234234
for _, path := range sortedPaths {
235235
if path != localPath && filepath.Ext(path) != ".lock" && !stringInSlice(path, garbageFiles) {
236-
// If we previously collected a few garbage files with an expired ttl, then take that into account
236+
// If we previously collected some garbage files with an expired ttl, then take that into account
237237
// when checking whether we need to remove more files to satisfy the max no. of items allowed
238238
// in the filesystem, along with the no. of files already removed in this loop.
239239
if noOfGarbageFiles > 0 {
@@ -253,9 +253,9 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
253253
return garbageFiles, nil
254254
}
255255

256-
// GarbageCollect removes all garabge files in the artifact dir according to the provided
256+
// GarbageCollect removes all garbage files in the artifact dir according to the provided
257257
// retention options.
258-
func (s *Storage) GarbageCollect(ctx context.Context, artifact sourcev1.Artifact, timeout time.Duration) ([]string, error) {
258+
func (s *Storage) GarbageCollect(ctx context.Context, artifact v1.Artifact, timeout time.Duration) ([]string, error) {
259259
delFilesChan := make(chan []string)
260260
errChan := make(chan error)
261261
// Abort if it takes more than the provided timeout duration.
@@ -316,8 +316,8 @@ func stringInSlice(a string, list []string) bool {
316316
return false
317317
}
318318

319-
// ArtifactExist returns a boolean indicating whether the v1beta1.Artifact exists in storage and is a regular file.
320-
func (s *Storage) ArtifactExist(artifact sourcev1.Artifact) bool {
319+
// ArtifactExist returns a boolean indicating whether the v1.Artifact exists in storage and is a regular file.
320+
func (s *Storage) ArtifactExist(artifact v1.Artifact) bool {
321321
fi, err := os.Lstat(s.LocalPath(artifact))
322322
if err != nil {
323323
return false
@@ -343,11 +343,11 @@ func SourceIgnoreFilter(ps []gitignore.Pattern, domain []string) ArchiveFileFilt
343343
}
344344
}
345345

346-
// Archive atomically archives the given directory as a tarball to the given v1beta1.Artifact path, excluding
346+
// Archive atomically archives the given directory as a tarball to the given v1.Artifact path, excluding
347347
// directories and any ArchiveFileFilter matches. While archiving, any environment specific data (for example,
348348
// the user and group name) is stripped from file headers.
349349
// If successful, it sets the digest and last update time on the artifact.
350-
func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter ArchiveFileFilter) (err error) {
350+
func (s *Storage) Archive(artifact *v1.Artifact, dir string, filter ArchiveFileFilter) (err error) {
351351
if f, err := os.Stat(dir); os.IsNotExist(err) || !f.IsDir() {
352352
return fmt.Errorf("invalid dir path: %s", dir)
353353
}
@@ -467,9 +467,9 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
467467
return nil
468468
}
469469

470-
// AtomicWriteFile atomically writes the io.Reader contents to the v1beta1.Artifact path.
470+
// AtomicWriteFile atomically writes the io.Reader contents to the v1.Artifact path.
471471
// If successful, it sets the digest and last update time on the artifact.
472-
func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader, mode os.FileMode) (err error) {
472+
func (s *Storage) AtomicWriteFile(artifact *v1.Artifact, reader io.Reader, mode os.FileMode) (err error) {
473473
localPath := s.LocalPath(*artifact)
474474
tf, err := os.CreateTemp(filepath.Split(localPath))
475475
if err != nil {
@@ -509,9 +509,9 @@ func (s *Storage) AtomicWriteFile(artifact *sourcev1.Artifact, reader io.Reader,
509509
return nil
510510
}
511511

512-
// Copy atomically copies the io.Reader contents to the v1beta1.Artifact path.
512+
// Copy atomically copies the io.Reader contents to the v1.Artifact path.
513513
// If successful, it sets the digest and last update time on the artifact.
514-
func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error) {
514+
func (s *Storage) Copy(artifact *v1.Artifact, reader io.Reader) (err error) {
515515
localPath := s.LocalPath(*artifact)
516516
tf, err := os.CreateTemp(filepath.Split(localPath))
517517
if err != nil {
@@ -547,9 +547,9 @@ func (s *Storage) Copy(artifact *sourcev1.Artifact, reader io.Reader) (err error
547547
return nil
548548
}
549549

550-
// CopyFromPath atomically copies the contents of the given path to the path of the v1beta1.Artifact.
550+
// CopyFromPath atomically copies the contents of the given path to the path of the v1.Artifact.
551551
// If successful, the digest and last update time on the artifact is set.
552-
func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err error) {
552+
func (s *Storage) CopyFromPath(artifact *v1.Artifact, path string) (err error) {
553553
f, err := os.Open(path)
554554
if err != nil {
555555
return err
@@ -564,7 +564,7 @@ func (s *Storage) CopyFromPath(artifact *sourcev1.Artifact, path string) (err er
564564
}
565565

566566
// CopyToPath copies the contents in the (sub)path of the given artifact to the given path.
567-
func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string) error {
567+
func (s *Storage) CopyToPath(artifact *v1.Artifact, subPath, toPath string) error {
568568
// create a tmp directory to store artifact
569569
tmp, err := os.MkdirTemp("", "flux-include-")
570570
if err != nil {
@@ -602,8 +602,8 @@ func (s *Storage) CopyToPath(artifact *sourcev1.Artifact, subPath, toPath string
602602
return nil
603603
}
604604

605-
// Symlink creates or updates a symbolic link for the given v1beta1.Artifact and returns the URL for the symlink.
606-
func (s *Storage) Symlink(artifact sourcev1.Artifact, linkName string) (string, error) {
605+
// Symlink creates or updates a symbolic link for the given v1.Artifact and returns the URL for the symlink.
606+
func (s *Storage) Symlink(artifact v1.Artifact, linkName string) (string, error) {
607607
localPath := s.LocalPath(artifact)
608608
dir := filepath.Dir(localPath)
609609
link := filepath.Join(dir, linkName)
@@ -621,19 +621,18 @@ func (s *Storage) Symlink(artifact sourcev1.Artifact, linkName string) (string,
621621
return "", err
622622
}
623623

624-
url := fmt.Sprintf("http://%s/%s", s.Hostname, filepath.Join(filepath.Dir(artifact.Path), linkName))
625-
return url, nil
624+
return fmt.Sprintf("http://%s/%s", s.Hostname, filepath.Join(filepath.Dir(artifact.Path), linkName)), nil
626625
}
627626

628-
// Lock creates a file lock for the given v1beta1.Artifact.
629-
func (s *Storage) Lock(artifact sourcev1.Artifact) (unlock func(), err error) {
627+
// Lock creates a file lock for the given v1.Artifact.
628+
func (s *Storage) Lock(artifact v1.Artifact) (unlock func(), err error) {
630629
lockFile := s.LocalPath(artifact) + ".lock"
631630
mutex := lockedfile.MutexAt(lockFile)
632631
return mutex.Lock()
633632
}
634633

635634
// LocalPath returns the secure local path of the given artifact (that is: relative to the Storage.BasePath).
636-
func (s *Storage) LocalPath(artifact sourcev1.Artifact) string {
635+
func (s *Storage) LocalPath(artifact v1.Artifact) string {
637636
if artifact.Path == "" {
638637
return ""
639638
}
@@ -644,7 +643,7 @@ func (s *Storage) LocalPath(artifact sourcev1.Artifact) string {
644643
return path
645644
}
646645

647-
// writecounter is an implementation of io.Writer that only records the number
646+
// writeCounter is an implementation of io.Writer that only records the number
648647
// of bytes written.
649648
type writeCounter struct {
650649
written int64

0 commit comments

Comments
 (0)