MCPcopy
hub / github.com/cortexlabs/cortex / Init

Function Init

pkg/config/config.go:79–178  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

77}
78
79func Init() error {
80 var err error
81
82 clusterConfigPath := os.Getenv("CORTEX_CLUSTER_CONFIG_PATH")
83 if clusterConfigPath == "" {
84 clusterConfigPath = consts.DefaultInClusterConfigPath
85 }
86
87 clusterConfig, err := clusterconfig.NewForFile(clusterConfigPath)
88 if err != nil {
89 return err
90 }
91
92 ClusterConfig = clusterConfig
93
94 AWS, err = aws.NewForRegion(clusterConfig.Region)
95 if err != nil {
96 return err
97 }
98
99 accountID, hashedAccountID, err := AWS.CheckCredentials()
100 if err != nil {
101 return err
102 }
103
104 clusterConfig.AccountID = accountID
105
106 OperatorMetadata = &clusterconfig.OperatorMetadata{
107 APIVersion: consts.CortexVersion,
108 OperatorID: hashedAccountID,
109 ClusterID: hash.String(clusterConfig.ClusterName + clusterConfig.Region + hashedAccountID),
110 IsOperatorInCluster: strings.ToLower(os.Getenv("CORTEX_OPERATOR_IN_CLUSTER")) != "false",
111 }
112
113 if K8s, err = k8s.New(consts.DefaultNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
114 return err
115 }
116
117 if K8sIstio, err = k8s.New(consts.IstioNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
118 return err
119 }
120
121 if !OperatorMetadata.IsOperatorInCluster {
122 cc, err := getClusterConfigFromConfigMap()
123 if err != nil {
124 return err
125 }
126 clusterConfig.Bucket = cc.Bucket
127 clusterConfig.ClusterUID = cc.ClusterUID
128 }
129
130 exists, err := AWS.DoesBucketExist(clusterConfig.Bucket)
131 if err != nil {
132 return err
133 }
134 if !exists {
135 return errors.ErrorUnexpected("the specified bucket does not exist", clusterConfig.Bucket)
136 }

Callers 1

mainFunction · 0.92

Calls 12

NewForFileFunction · 0.92
NewForRegionFunction · 0.92
StringFunction · 0.92
NewFunction · 0.92
ErrorUnexpectedFunction · 0.92
InitFunction · 0.92
MessageFunction · 0.92
WrapFunction · 0.92
WithStackFunction · 0.92
CheckCredentialsMethod · 0.80
DoesBucketExistMethod · 0.80

Tested by

no test coverage detected