@@ -17,9 +17,13 @@ limitations under the License.
17
17
package repository
18
18
19
19
import (
20
+ "io/ioutil"
20
21
"net/url"
22
+ "os"
23
+ "path/filepath"
21
24
22
25
"github.com/pkg/errors"
26
+ "k8s.io/client-go/util/homedir"
23
27
"sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/client/config"
24
28
"sigs.k8s.io/cluster-api/cmd/clusterctl/pkg/internal/test"
25
29
)
@@ -151,3 +155,32 @@ func repositoryFactory(providerConfig config.Provider, configVariablesClient con
151
155
152
156
return nil , errors .Errorf ("invalid provider url. there are no provider implementation for %q schema" , rURL .Scheme )
153
157
}
158
+
159
+ const overrideFolder = "overrides"
160
+
161
+ // getLocalOverride return local override file from the config folder, if it exists.
162
+ // This is required for development purposes, but it can be used also in production as a workaround for problems on the official repositories
163
+ func getLocalOverride (provider config.Provider , version , path string ) ([]byte , error ) {
164
+
165
+ // local override files are searched at $home/cluster-api/overrides/<provider-name>/<version>/<path>
166
+ homeFolder := filepath .Join (homedir .HomeDir (), config .ConfigFolder )
167
+ overridePath := filepath .Join (homeFolder , overrideFolder , provider .Name (), version , path )
168
+
169
+ // it the local override exists, use it
170
+ _ , err := os .Stat (overridePath )
171
+ if err == nil {
172
+ content , err := ioutil .ReadFile (overridePath )
173
+ if err != nil {
174
+ return nil , errors .Wrapf (err , "failed to read local override for %s/%s/%s" , provider .Name (), version , path )
175
+ }
176
+ return content , nil
177
+ }
178
+
179
+ // it the local override does not exists, return (so files from the provider's repository could be used)
180
+ if os .IsNotExist (err ) {
181
+ return nil , nil
182
+ }
183
+
184
+ // blocks for any other error
185
+ return nil , err
186
+ }
0 commit comments