Skip to content

Commit e2e8a95

Browse files
committed
In clusterctl, adds ability to automatically select local
filesystem backend when URL of the repo begins with "file://"
1 parent f208101 commit e2e8a95

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

cmd/clusterctl/pkg/client/repository/client.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ func repositoryFactory(providerConfig config.Provider, configVariablesClient con
164164
return repo, err
165165
}
166166

167-
// if the url is a local repository
168-
//TODO: implement in a follow up PR
167+
// if the url is a local filesystem repository
168+
if rURL.Scheme == "file" || rURL.Scheme == "" {
169+
repo, err := newLocalRepository(providerConfig, configVariablesClient)
170+
if err != nil {
171+
return nil, errors.Wrap(err, "error creating the local filesystem repository client")
172+
}
173+
return repo, err
174+
}
169175

170176
return nil, errors.Errorf("invalid provider url. there are no provider implementation for %q schema", rURL.Scheme)
171177
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package repository
18+
19+
import (
20+
"os"
21+
"reflect"
22+
"testing"
23+
24+
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
25+
"sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/client/config"
26+
"sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/internal/test"
27+
)
28+
29+
func Test_newRepositoryClient_LocalFileSystemRepository(t *testing.T) {
30+
tmpDir := createTempDir(t)
31+
defer os.RemoveAll(tmpDir)
32+
33+
dst1 := createLocalTestProviderFile(t, tmpDir, "provider-1/v1.0.0/bootstrap-components.yaml", "")
34+
dst2 := createLocalTestProviderFile(t, tmpDir, "provider-2/v2.0.0/bootstrap-components.yaml", "")
35+
36+
type fields struct {
37+
provider config.Provider
38+
}
39+
tests := []struct {
40+
name string
41+
fields fields
42+
}{
43+
{
44+
name: "successfully creates repository client with local filesystem backend and scheme == \"\"",
45+
fields: fields{
46+
provider: config.NewProvider("provider-1", dst1, clusterctlv1.BootstrapProviderType),
47+
},
48+
},
49+
{
50+
name: "successfully creates repository client with local filesystem backend and scheme == \"file\"",
51+
fields: fields{
52+
provider: config.NewProvider("provider-2", "file://"+dst2, clusterctlv1.BootstrapProviderType),
53+
},
54+
},
55+
}
56+
for _, tt := range tests {
57+
t.Run(tt.name, func(t *testing.T) {
58+
repoClient, err := newRepositoryClient(tt.fields.provider, test.NewFakeVariableClient())
59+
if err != nil {
60+
t.Fatalf("got error %v when none was expected", err)
61+
}
62+
if _, ok := repoClient.repository.(*localRepository); !ok {
63+
t.Fatalf("got repository of type %v when *repository.localRepository was expected", reflect.TypeOf(repoClient.repository))
64+
}
65+
})
66+
}
67+
}

0 commit comments

Comments
 (0)