-
Notifications
You must be signed in to change notification settings - Fork 287
/
registryMirror.go
53 lines (47 loc) · 1.64 KB
/
registryMirror.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package framework
import (
"context"
"encoding/base64"
"net"
"os"
"github.com/aws/eks-anywhere/internal/pkg/api"
)
const (
RegistryEndpointVar = "T_REGISTRY_MIRROR_ENDPOINT"
RegistryPortVar = "T_REGISTRY_MIRROR_PORT"
RegistryUsernameVar = "T_REGISTRY_MIRROR_USERNAME"
RegistryPasswordVar = "T_REGISTRY_MIRROR_PASSWORD"
RegistryCACertVar = "T_REGISTRY_MIRROR_CA_CERT"
)
var registryMirrorRequiredEnvVars = []string{RegistryEndpointVar, RegistryPortVar, RegistryUsernameVar, RegistryPasswordVar, RegistryCACertVar}
func WithRegistryMirrorEndpointAndCert() ClusterE2ETestOpt {
return func(e *ClusterE2ETest) {
checkRequiredEnvVars(e.T, registryMirrorRequiredEnvVars)
endpoint := os.Getenv(RegistryEndpointVar)
hostPort := net.JoinHostPort(endpoint, os.Getenv(RegistryPortVar))
username := os.Getenv(RegistryUsernameVar)
password := os.Getenv(RegistryPasswordVar)
err := buildDocker(e.T).Login(context.Background(), hostPort, username, password)
if err != nil {
e.T.Fatalf("error logging into docker registry %s: %v", hostPort, err)
}
certificate, err := base64.StdEncoding.DecodeString(os.Getenv(RegistryCACertVar))
if err == nil {
e.clusterFillers = append(e.clusterFillers,
api.WithRegistryMirror(endpoint, string(certificate)),
)
}
// Set env vars for helm login/push
err = os.Setenv("REGISTRY_USERNAME", username)
if err != nil {
e.T.Fatalf("unable to set REGISTRY_USERNAME: %v", err)
}
err = os.Setenv("REGISTRY_PASSWORD", password)
if err != nil {
e.T.Fatalf("unable to set REGISTRY_PASSWORD: %v", err)
}
}
}
func RequiredRegistryMirrorEnvVars() []string {
return registryMirrorRequiredEnvVars
}