Merge pull request #108429 from dims/allow-env-var-to-be-remote-url

Allow KUBE_TEST_REPO_LIST to be a remote url as well
This commit is contained in:
Kubernetes Prow Robot 2022-03-02 08:07:16 -08:00 committed by GitHub
commit 4737127b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 5 deletions

View File

@ -427,9 +427,9 @@ function install-kube-manifests {
tar xzf "${KUBE_HOME}/${manifests_tar}" -C "${dst_dir}" --overwrite
local -r kube_addon_registry="${KUBE_ADDON_REGISTRY:-k8s.gcr.io}"
if [[ "${kube_addon_registry}" != "k8s.gcr.io" ]]; then
find "${dst_dir}" \(-name '*.yaml' -or -name '*.yaml.in'\) -print0 | \
find "${dst_dir}" \( -name '*.yaml' -or -name '*.yaml.in' \) -print0 | \
xargs -0 sed -ri "s@(image:\s.*)k8s.gcr.io@\1${kube_addon_registry}@"
find "${dst_dir}" \(-name '*.manifest' -or -name '*.json'\) -print0 | \
find "${dst_dir}" \( -name '*.manifest' -or -name '*.json' \) -print0 | \
xargs -0 sed -ri "s@(image\":\s+\")k8s.gcr.io@\1${kube_addon_registry}@"
fi
cp "${dst_dir}/kubernetes/gci-trusty/gci-configure-helper.sh" "${KUBE_BIN}/configure-helper.sh"

View File

@ -17,9 +17,13 @@ limitations under the License.
package image
import (
"bufio"
"bytes"
"crypto/sha256"
"encoding/base64"
"fmt"
"io"
"net/http"
"os"
"regexp"
"strings"
@ -72,9 +76,20 @@ func initReg() RegistryList {
return registry
}
fileContent, err := os.ReadFile(repoList)
if err != nil {
panic(fmt.Errorf("Error reading '%v' file contents: %v", repoList, err))
var fileContent []byte
var err error
if strings.HasPrefix(repoList, "https://") || strings.HasPrefix(repoList, "http://") {
var b bytes.Buffer
err = readFromURL(repoList, bufio.NewWriter(&b))
if err != nil {
panic(fmt.Errorf("error reading '%v' url contents: %v", repoList, err))
}
fileContent = b.Bytes()
} else {
fileContent, err = os.ReadFile(repoList)
if err != nil {
panic(fmt.Errorf("error reading '%v' file contents: %v", repoList, err))
}
}
err = yaml.Unmarshal(fileContent, &registry)
@ -84,6 +99,27 @@ func initReg() RegistryList {
return registry
}
// Essentially curl url | writer
func readFromURL(url string, writer io.Writer) error {
httpTransport := new(http.Transport)
httpTransport.Proxy = http.ProxyFromEnvironment
c := &http.Client{Transport: httpTransport}
r, err := c.Get(url)
if err != nil {
return err
}
defer r.Body.Close()
if r.StatusCode >= 400 {
return fmt.Errorf("%v returned %d", url, r.StatusCode)
}
_, err = io.Copy(writer, r.Body)
if err != nil {
return err
}
return nil
}
var (
initRegistry = RegistryList{
GcAuthenticatedRegistry: "gcr.io/authenticated-image-pulling",