Skip to content

Commit f8c4bd3

Browse files
committed
api/artifact: add ArtifactDir helper func
To make it easier to construct just the directory path for the artifact (relative to the storage base path).
1 parent ecaa980 commit f8c4bd3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

api/v1alpha1/artifact.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
"fmt"
20+
"path"
21+
"strings"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
@@ -44,8 +45,15 @@ type Artifact struct {
4445
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
4546
}
4647

48+
// ArtifactDir returns the artifact dir path in the form of
49+
// <source-kind>/<source-namespace>/<source-name>
50+
func ArtifactDir(kind, namespace, name string) string {
51+
kind = strings.ToLower(kind)
52+
return path.Join(kind, namespace, name)
53+
}
54+
4755
// ArtifactPath returns the artifact path in the form of
4856
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>
4957
func ArtifactPath(kind, namespace, name, filename string) string {
50-
return fmt.Sprintf("%s/%s/%s/%s", kind, namespace, name, filename)
58+
return path.Join(ArtifactDir(kind, namespace, name), filename)
5159
}

controllers/storage.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
7171

7272
// ArtifactFor returns an artifact for the given Kubernetes object
7373
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
74-
kind = strings.ToLower(kind)
7574
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
7675
localPath := filepath.Join(s.BasePath, path)
7776
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)

0 commit comments

Comments
 (0)