-
Notifications
You must be signed in to change notification settings - Fork 286
/
registryMirror.go
66 lines (53 loc) · 1.92 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
54
55
56
57
58
59
60
61
62
63
64
65
66
package e2e
import (
"encoding/base64"
"fmt"
"net"
"os"
"regexp"
"github.com/go-logr/logr"
"github.com/aws/eks-anywhere/internal/pkg/ssm"
e2etests "github.com/aws/eks-anywhere/test/framework"
)
func (e *E2ESession) setupRegistryMirrorEnv(testRegex string) error {
re := regexp.MustCompile(`^.*RegistryMirror.*$`)
if !re.MatchString(testRegex) {
return nil
}
requiredEnvVars := e2etests.RequiredRegistryMirrorEnvVars()
for _, eVar := range requiredEnvVars {
if val, ok := os.LookupEnv(eVar); ok {
e.testEnvVars[eVar] = val
}
}
endpoint := e.testEnvVars[e2etests.RegistryEndpointVar]
port := e.testEnvVars[e2etests.RegistryPortVar]
caCert := e.testEnvVars[e2etests.RegistryCACertVar]
// Since Tinkerbell uses a separate harbor registry,
// we need to setup cert for that registry for Tinkerbell tests.
re = regexp.MustCompile(`^.*Tinkerbell.*$`)
if re.MatchString(testRegex) {
endpoint = e.testEnvVars[e2etests.RegistryEndpointTinkerbellVar]
port = e.testEnvVars[e2etests.RegistryPortTinkerbellVar]
caCert = e.testEnvVars[e2etests.RegistryCACertTinkerbellVar]
}
if endpoint != "" && port != "" && caCert != "" {
return e.mountRegistryCert(caCert, net.JoinHostPort(endpoint, port))
}
return nil
}
func (e *E2ESession) mountRegistryCert(cert string, endpoint string) error {
command := fmt.Sprintf("sudo mkdir -p /etc/docker/certs.d/%s", endpoint)
if err := ssm.Run(e.session, logr.Discard(), e.instanceId, command); err != nil {
return fmt.Errorf("creating directory in instance: %v", err)
}
decodedCert, err := base64.StdEncoding.DecodeString(cert)
if err != nil {
return fmt.Errorf("failed to decode certificate: %v", err)
}
command = fmt.Sprintf("sudo cat <<EOF>> /etc/docker/certs.d/%s/ca.crt\n%s\nEOF", endpoint, string(decodedCert))
if err := ssm.Run(e.session, logr.Discard(), e.instanceId, command); err != nil {
return fmt.Errorf("mounting certificate in instance: %v", err)
}
return err
}