Merge pull request #18 from fluxcd/artifact-path
Change artifact path format
This commit is contained in:
commit
0e4e3cd660
|
@ -16,7 +16,11 @@ limitations under the License.
|
||||||
|
|
||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
)
|
||||||
|
|
||||||
// Artifact represents the output of a source synchronisation
|
// Artifact represents the output of a source synchronisation
|
||||||
type Artifact struct {
|
type Artifact struct {
|
||||||
|
@ -39,3 +43,9 @@ type Artifact struct {
|
||||||
// +required
|
// +required
|
||||||
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
|
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArtifactPath returns the artifact path in the form of
|
||||||
|
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>
|
||||||
|
func ArtifactPath(kind, namespace, name, filename string) string {
|
||||||
|
return fmt.Sprintf("%s/%s/%s/%s", kind, namespace, name, filename)
|
||||||
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"helm.sh/helm/v3/pkg/getter"
|
"helm.sh/helm/v3/pkg/getter"
|
||||||
"helm.sh/helm/v3/pkg/repo"
|
"helm.sh/helm/v3/pkg/repo"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
@ -149,7 +148,7 @@ func (r *HelmChartReconciler) sync(repository sourcev1.HelmRepository, chart sou
|
||||||
ref := cv.URLs[0]
|
ref := cv.URLs[0]
|
||||||
u, err := url.Parse(ref)
|
u, err := url.Parse(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Errorf("invalid chart URL format '%s': %w", ref, err)
|
err = fmt.Errorf("invalid chart URL format '%s': %w", ref, err)
|
||||||
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
|
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPullFailedReason, err.Error()), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
|
||||||
// ArtifactFor returns an artifact for the given Kubernetes object
|
// ArtifactFor returns an artifact for the given Kubernetes object
|
||||||
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
|
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
|
||||||
kind = strings.ToLower(kind)
|
kind = strings.ToLower(kind)
|
||||||
path := fmt.Sprintf("%s/%s-%s/%s", kind, metadata.GetNamespace(), metadata.GetName(), fileName)
|
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
|
||||||
localPath := filepath.Join(s.BasePath, path)
|
localPath := filepath.Join(s.BasePath, path)
|
||||||
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)
|
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ func TestAuthMethodFromSecret(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{"HTTP", "http://git.example.com/org/repo.git", basicAuthSecretFixture, &http.BasicAuth{}, false},
|
{"HTTP", "http://git.example.com/org/repo.git", basicAuthSecretFixture, &http.BasicAuth{}, false},
|
||||||
{"HTTPS", "https://git.example.com/org/repo.git", basicAuthSecretFixture, &http.BasicAuth{}, false},
|
{"HTTPS", "https://git.example.com/org/repo.git", basicAuthSecretFixture, &http.BasicAuth{}, false},
|
||||||
{"SSH", "ssh://git.example.com:2222/org/repo.git", privateKeySecretFixture, &ssh.PublicKeys{}, false},
|
{"SSH", "ssh://git.example.com:2222/org/repo.git", privateKeySecretFixture, &ssh.PublicKeys{}, false},
|
||||||
{"unsupported", "protocol://git.example.com/org/repo.git", corev1.Secret{}, nil, false},
|
{"unsupported", "protocol://git.example.com/org/repo.git", corev1.Secret{}, nil, false},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -83,13 +83,13 @@ func TestBasicAuthFromSecret(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
secret corev1.Secret
|
secret corev1.Secret
|
||||||
modify func(secret *corev1.Secret)
|
modify func(secret *corev1.Secret)
|
||||||
want *http.BasicAuth
|
want *http.BasicAuth
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{"username and password", basicAuthSecretFixture, nil, &http.BasicAuth{Username: "git", Password: "password"}, false},
|
{"username and password", basicAuthSecretFixture, nil, &http.BasicAuth{Username: "git", Password: "password"}, false},
|
||||||
{"without username", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "username")}, nil, true},
|
{"without username", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "username") }, nil, true},
|
||||||
{"without password", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "password")}, nil, true},
|
{"without password", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "password") }, nil, true},
|
||||||
{"empty", corev1.Secret{}, nil, nil, true},
|
{"empty", corev1.Secret{}, nil, nil, true},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -114,7 +114,7 @@ func TestPublicKeysFromSecret(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
secret corev1.Secret
|
secret corev1.Secret
|
||||||
modify func(secret *corev1.Secret)
|
modify func(secret *corev1.Secret)
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{"private key and known_hosts", privateKeySecretFixture, nil, false},
|
{"private key and known_hosts", privateKeySecretFixture, nil, false},
|
||||||
|
|
|
@ -16,8 +16,8 @@ var (
|
||||||
tlsSecretFixture = corev1.Secret{
|
tlsSecretFixture = corev1.Secret{
|
||||||
Data: map[string][]byte{
|
Data: map[string][]byte{
|
||||||
"certFile": []byte(`fixture`),
|
"certFile": []byte(`fixture`),
|
||||||
"keyFile": []byte(`fixture`),
|
"keyFile": []byte(`fixture`),
|
||||||
"caFile": []byte(`fixture`),
|
"caFile": []byte(`fixture`),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,7 @@ func TestBasicAuthFromSecret(t *testing.T) {
|
||||||
wantErr bool
|
wantErr bool
|
||||||
wantNil bool
|
wantNil bool
|
||||||
}{
|
}{
|
||||||
{"username and password", basicAuthSecretFixture, nil,false, false},
|
{"username and password", basicAuthSecretFixture, nil, false, false},
|
||||||
{"without username", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "username") }, true, true},
|
{"without username", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "username") }, true, true},
|
||||||
{"without password", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "password") }, true, true},
|
{"without password", basicAuthSecretFixture, func(s *corev1.Secret) { delete(s.Data, "password") }, true, true},
|
||||||
{"empty", corev1.Secret{}, nil, false, true},
|
{"empty", corev1.Secret{}, nil, false, true},
|
||||||
|
@ -95,7 +95,7 @@ func TestTLSClientConfigFromSecret(t *testing.T) {
|
||||||
wantErr bool
|
wantErr bool
|
||||||
wantNil bool
|
wantNil bool
|
||||||
}{
|
}{
|
||||||
{"certFile, keyFile and caFile", tlsSecretFixture, nil,false, false},
|
{"certFile, keyFile and caFile", tlsSecretFixture, nil, false, false},
|
||||||
{"without certFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "certFile") }, true, true},
|
{"without certFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "certFile") }, true, true},
|
||||||
{"without keyFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "keyFile") }, true, true},
|
{"without keyFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "keyFile") }, true, true},
|
||||||
{"without caFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "caFile") }, true, true},
|
{"without caFile", tlsSecretFixture, func(s *corev1.Secret) { delete(s.Data, "caFile") }, true, true},
|
||||||
|
|
Loading…
Reference in New Issue