diff --git a/api/v1alpha1/artifact.go b/api/v1alpha1/artifact.go index 131ea863..ff3e59ff 100644 --- a/api/v1alpha1/artifact.go +++ b/api/v1alpha1/artifact.go @@ -17,7 +17,8 @@ limitations under the License. package v1alpha1 import ( - "fmt" + "path" + "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -44,8 +45,15 @@ type Artifact struct { LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"` } +// ArtifactDir returns the artifact dir path in the form of +// // +func ArtifactDir(kind, namespace, name string) string { + kind = strings.ToLower(kind) + return path.Join(kind, namespace, name) +} + // ArtifactPath returns the artifact path in the form of // /// func ArtifactPath(kind, namespace, name, filename string) string { - return fmt.Sprintf("%s/%s/%s/%s", kind, namespace, name, filename) + return path.Join(ArtifactDir(kind, namespace, name), filename) } diff --git a/controllers/storage.go b/controllers/storage.go index 56e4ea48..293f38d4 100644 --- a/controllers/storage.go +++ b/controllers/storage.go @@ -71,7 +71,6 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora // ArtifactFor returns an artifact for the given Kubernetes object func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact { - kind = strings.ToLower(kind) path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName) localPath := filepath.Join(s.BasePath, path) url := fmt.Sprintf("http://%s/%s", s.Hostname, path)