Skip to content

Commit bbe403d

Browse files
authored
Merge pull request #2192 from Nordix/clusterctlv2-select-repo-local
✨ clusterctl: Add automatic selection of repository backend based on URL
2 parents f208101 + 98d51d3 commit bbe403d

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-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,66 @@
1+
/*
2+
Copyright 2020 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+
"testing"
22+
23+
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
24+
"sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/client/config"
25+
"sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/internal/test"
26+
)
27+
28+
func Test_newRepositoryClient_LocalFileSystemRepository(t *testing.T) {
29+
tmpDir := createTempDir(t)
30+
defer os.RemoveAll(tmpDir)
31+
32+
dst1 := createLocalTestProviderFile(t, tmpDir, "provider-1/v1.0.0/bootstrap-components.yaml", "")
33+
dst2 := createLocalTestProviderFile(t, tmpDir, "provider-2/v2.0.0/bootstrap-components.yaml", "")
34+
35+
type fields struct {
36+
provider config.Provider
37+
}
38+
tests := []struct {
39+
name string
40+
fields fields
41+
}{
42+
{
43+
name: "successfully creates repository client with local filesystem backend and scheme == \"\"",
44+
fields: fields{
45+
provider: config.NewProvider("provider-1", dst1, clusterctlv1.BootstrapProviderType),
46+
},
47+
},
48+
{
49+
name: "successfully creates repository client with local filesystem backend and scheme == \"file\"",
50+
fields: fields{
51+
provider: config.NewProvider("provider-2", "file://"+dst2, clusterctlv1.BootstrapProviderType),
52+
},
53+
},
54+
}
55+
for _, tt := range tests {
56+
t.Run(tt.name, func(t *testing.T) {
57+
repoClient, err := newRepositoryClient(tt.fields.provider, test.NewFakeVariableClient())
58+
if err != nil {
59+
t.Fatalf("got error %v when none was expected", err)
60+
}
61+
if _, ok := repoClient.repository.(*localRepository); !ok {
62+
t.Fatalf("got repository of type %T when *repository.localRepository was expected", repoClient.repository)
63+
}
64+
})
65+
}
66+
}

0 commit comments

Comments
 (0)