Error on HTTP resources are not nescessarly protocol related

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
This commit is contained in:
Sylvain Rabot
2021-12-10 09:27:37 +01:00
parent e65e571ed1
commit 738573b079
3 changed files with 9 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ import (
"sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/konfig"
load "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
@@ -366,7 +367,8 @@ func (kt *KustTarget) accumulateResources(
for _, path := range paths {
// try loading resource as file then as base (directory or git repository)
if errF := kt.accumulateFile(ra, path, origin); errF != nil {
if strings.HasPrefix(path, "https://") || strings.HasPrefix(path, "http://") {
// not much we can do if the error is an HTTP error so we bail out
if errors.Is(errF, load.ErrorHTTP) {
return nil, errF
}
ldr, err := kt.ldr.New(path)

5
api/loader/errors.go Normal file
View File

@@ -0,0 +1,5 @@
package loader
import "fmt"
var ErrorHTTP = fmt.Errorf("HTTP Error")

View File

@@ -314,7 +314,7 @@ func (fl *fileLoader) Load(path string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return nil, fmt.Errorf("URL returned error %d (%s)", resp.StatusCode, http.StatusText(resp.StatusCode))
return nil, fmt.Errorf("%w: status code %d (%s)", ErrorHTTP, resp.StatusCode, http.StatusText(resp.StatusCode))
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {