/
dev.go
81 lines (67 loc) · 1.98 KB
/
dev.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package liveconfig
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"fmt"
"os"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func (d *dev) HiveRestConfig(ctx context.Context, shard int) (*rest.Config, error) {
// shards above 0 have _shard appended to it
envVar := hiveKubeconfigPathEnvVar
if shard != 0 {
envVar = fmt.Sprintf("%s_%d", hiveKubeconfigPathEnvVar, shard)
}
// Use an override kubeconfig path if one is provided
kubeConfigPath := os.Getenv(envVar)
if kubeConfigPath != "" {
restConfig, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
if err != nil {
return nil, err
}
return restConfig, nil
}
// Hive shards are planned but not deployed or implemented yet
d.hiveCredentialsMutex.RLock()
cached, exists := d.cachedCredentials[shard]
d.hiveCredentialsMutex.RUnlock()
if exists {
return rest.CopyConfig(cached), nil
}
// Lock the RWMutex as we're starting to fetch so that new readers will wait
// for the existing Azure API call to be done.
d.hiveCredentialsMutex.Lock()
defer d.hiveCredentialsMutex.Unlock()
kubeConfig, err := getAksShardKubeconfig(ctx, d.managedClustersClient, d.location, shard)
if err != nil {
return nil, err
}
d.cachedCredentials[shard] = kubeConfig
return rest.CopyConfig(kubeConfig), nil
}
func (d *dev) InstallViaHive(ctx context.Context) (bool, error) {
installViaHive := os.Getenv(hiveInstallerEnableEnvVar)
if installViaHive != "" {
return true, nil
}
return false, nil
}
func (d *dev) DefaultInstallerPullSpecOverride(ctx context.Context) string {
return os.Getenv(hiveDefaultPullSpecEnvVar)
}
func (p *dev) AdoptByHive(ctx context.Context) (bool, error) {
adopt := os.Getenv(hiveAdoptEnableEnvVar)
if adopt != "" {
return true, nil
}
return false, nil
}
func (d *dev) UseCheckAccess(ctx context.Context) (bool, error) {
checkAccess := os.Getenv(useCheckAccess)
if checkAccess == "enabled" {
return true, nil
}
return false, nil
}