Skip to content

Commit 0e4e3cd

Browse files
authored
Merge pull request #18 from fluxcd/artifact-path
Change artifact path format
2 parents 041bb23 + e88d721 commit 0e4e3cd

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

api/v1alpha1/artifact.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ limitations under the License.
1616

1717
package v1alpha1
1818

19-
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
import (
20+
"fmt"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
)
2024

2125
// Artifact represents the output of a source synchronisation
2226
type Artifact struct {
@@ -39,3 +43,9 @@ type Artifact struct {
3943
// +required
4044
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
4145
}
46+
47+
// ArtifactPath returns the artifact path in the form of
48+
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>
49+
func ArtifactPath(kind, namespace, name, filename string) string {
50+
return fmt.Sprintf("%s/%s/%s/%s", kind, namespace, name, filename)
51+
}

controllers/helmchart_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"time"
2525

2626
"github.com/go-logr/logr"
27-
"github.com/pkg/errors"
2827
"helm.sh/helm/v3/pkg/getter"
2928
"helm.sh/helm/v3/pkg/repo"
3029
corev1 "k8s.io/api/core/v1"
@@ -149,7 +148,7 @@ func (r *HelmChartReconciler) sync(repository sourcev1.HelmRepository, chart sou
149148
ref := cv.URLs[0]
150149
u, err := url.Parse(ref)
151150
if err != nil {
152-
err = errors.Errorf("invalid chart URL format '%s': %w", ref, err)
151+
err = fmt.Errorf("invalid chart URL format '%s': %w", ref, err)
153152
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
154153
}
155154

controllers/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
6161
// ArtifactFor returns an artifact for the given Kubernetes object
6262
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
6363
kind = strings.ToLower(kind)
64-
path := fmt.Sprintf("%s/%s-%s/%s", kind, metadata.GetNamespace(), metadata.GetName(), fileName)
64+
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
6565
localPath := filepath.Join(s.BasePath, path)
6666
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)
6767

internal/git/transport_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestAuthMethodFromSecret(t *testing.T) {
5959
}{
6060
{"HTTP", "http://git.example.com/org/repo.git", basicAuthSecretFixture, &http.BasicAuth{}, false},
6161
{"HTTPS", "https://git.example.com/org/repo.git", basicAuthSecretFixture, &http.BasicAuth{}, false},
62-
{"SSH", "ssh://git.example.com:2222/org/repo.git", privateKeySecretFixture, &ssh.PublicKeys{}, false},
62+
{"SSH", "ssh://git.example.com:2222/org/repo.git", privateKeySecretFixture, &ssh.PublicKeys{}, false},
6363
{"unsupported", "protocol://git.example.com/org/repo.git", corev1.Secret{}, nil, false},
6464
}
6565
for _, tt := range tests {
@@ -83,13 +83,13 @@ func TestBasicAuthFromSecret(t *testing.T) {
8383
tests := []struct {
8484
name string
8585
secret corev1.Secret
86-
modify func(secret *corev1.Secret)
86+
modify func(secret *corev1.Secret)
8787
want *http.BasicAuth
8888
wantErr bool
8989
}{
9090
{"username and password", basicAuthSecretFixture, nil, &http.BasicAuth{Username: "git", Password: "password"}, false},
91-
{"without username", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "username")}, nil, true},
92-
{"without password", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "password")}, nil, true},
91+
{"without username", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "username") }, nil, true},
92+
{"without password", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "password") }, nil, true},
9393
{"empty", corev1.Secret{}, nil, nil, true},
9494
}
9595
for _, tt := range tests {
@@ -114,7 +114,7 @@ func TestPublicKeysFromSecret(t *testing.T) {
114114
tests := []struct {
115115
name string
116116
secret corev1.Secret
117-
modify func(secret *corev1.Secret)
117+
modify func(secret *corev1.Secret)
118118
wantErr bool
119119
}{
120120
{"private key and known_hosts", privateKeySecretFixture, nil, false},

internal/helm/getter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ var (
1616
tlsSecretFixture = corev1.Secret{
1717
Data: map[string][]byte{
1818
"certFile": []byte(`fixture`),
19-
"keyFile": []byte(`fixture`),
20-
"caFile": []byte(`fixture`),
19+
"keyFile": []byte(`fixture`),
20+
"caFile": []byte(`fixture`),
2121
},
2222
}
2323
)
@@ -63,7 +63,7 @@ func TestBasicAuthFromSecret(t *testing.T) {
6363
wantErr bool
6464
wantNil bool
6565
}{
66-
{"username and password", basicAuthSecretFixture, nil,false, false},
66+
{"username and password", basicAuthSecretFixture, nil, false, false},
6767
{"without username", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "username") }, true, true},
6868
{"without password", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "password") }, true, true},
6969
{"empty", corev1.Secret{}, nil, false, true},
@@ -95,7 +95,7 @@ func TestTLSClientConfigFromSecret(t *testing.T) {
9595
wantErr bool
9696
wantNil bool
9797
}{
98-
{"certFile, keyFile and caFile", tlsSecretFixture, nil,false, false},
98+
{"certFile, keyFile and caFile", tlsSecretFixture, nil, false, false},
9999
{"without certFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "certFile") }, true, true},
100100
{"without keyFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "keyFile") }, true, true},
101101
{"without caFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "caFile") }, true, true},

0 commit comments

Comments
 (0)