-
Notifications
You must be signed in to change notification settings - Fork 274
/
envars.go
51 lines (43 loc) 路 1.79 KB
/
envars.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
package vsphere
import (
"fmt"
"os"
"strconv"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/config"
)
func SetupEnvVars(datacenterConfig *anywherev1.VSphereDatacenterConfig) error {
if vSphereUsername, ok := os.LookupEnv(config.EksavSphereUsernameKey); ok && len(vSphereUsername) > 0 {
if err := os.Setenv(vSphereUsernameKey, vSphereUsername); err != nil {
return fmt.Errorf("unable to set %s: %v", config.EksavSphereUsernameKey, err)
}
} else {
return fmt.Errorf("%s is not set or is empty", config.EksavSphereUsernameKey)
}
if vSpherePassword, ok := os.LookupEnv(config.EksavSpherePasswordKey); ok && len(vSpherePassword) > 0 {
if err := os.Setenv(vSpherePasswordKey, vSpherePassword); err != nil {
return fmt.Errorf("unable to set %s: %v", config.EksavSpherePasswordKey, err)
}
} else {
return fmt.Errorf("%s is not set or is empty", config.EksavSpherePasswordKey)
}
if err := os.Setenv(vSphereServerKey, datacenterConfig.Spec.Server); err != nil {
return fmt.Errorf("unable to set %s: %v", vSphereServerKey, err)
}
if err := os.Setenv(expClusterResourceSetKey, "true"); err != nil {
return fmt.Errorf("unable to set %s: %v", expClusterResourceSetKey, err)
}
// TODO: move this somewhere else since it's not vSphere specific
if _, ok := os.LookupEnv(eksaLicense); !ok {
if err := os.Setenv(eksaLicense, ""); err != nil {
return fmt.Errorf("unable to set %s: %v", eksaLicense, err)
}
}
if err := os.Setenv(govcInsecure, strconv.FormatBool(datacenterConfig.Spec.Insecure)); err != nil {
return fmt.Errorf("unable to set %s: %v", govcInsecure, err)
}
if err := os.Setenv(govcDatacenterKey, datacenterConfig.Spec.Datacenter); err != nil {
return fmt.Errorf("unable to set %s: %v", govcDatacenterKey, err)
}
return nil
}