Skip to content

Commit 46a3cb3

Browse files
authored
Fix make operator-local command (#2171)
1 parent d8415ba commit 46a3cb3

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

pkg/config/config.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/cortexlabs/cortex/pkg/consts"
2525
batch "github.com/cortexlabs/cortex/pkg/crds/apis/batch/v1alpha1"
2626
"github.com/cortexlabs/cortex/pkg/lib/aws"
27+
cr "github.com/cortexlabs/cortex/pkg/lib/configreader"
2728
"github.com/cortexlabs/cortex/pkg/lib/errors"
2829
"github.com/cortexlabs/cortex/pkg/lib/hash"
2930
"github.com/cortexlabs/cortex/pkg/lib/k8s"
@@ -60,6 +61,20 @@ func InitConfigs(clusterConfig *clusterconfig.Config, operatorMetadata *clusterc
6061
OperatorMetadata = operatorMetadata
6162
}
6263

64+
func getClusterConfigFromConfigMap() (clusterconfig.Config, error) {
65+
configMapData, err := K8s.GetConfigMapData("cluster-config")
66+
if err != nil {
67+
return clusterconfig.Config{}, err
68+
}
69+
clusterConfig := clusterconfig.Config{}
70+
err = cr.ParseYAMLBytes(&clusterConfig, clusterconfig.FullManagedValidation, []byte(configMapData["cluster.yaml"]))
71+
if err != nil {
72+
return clusterconfig.Config{}, err
73+
}
74+
75+
return clusterConfig, nil
76+
}
77+
6378
func Init() error {
6479
var err error
6580
var clusterNamespace string
@@ -103,6 +118,22 @@ func Init() error {
103118
clusterNamespace = clusterConfig.Namespace
104119
istioNamespace = clusterConfig.IstioNamespace
105120

121+
if K8s, err = k8s.New(clusterNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
122+
return err
123+
}
124+
125+
if K8sIstio, err = k8s.New(istioNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
126+
return err
127+
}
128+
129+
if !OperatorMetadata.IsOperatorInCluster {
130+
cc, err := getClusterConfigFromConfigMap()
131+
if err != nil {
132+
return err
133+
}
134+
clusterConfig.Bucket = cc.Bucket
135+
}
136+
106137
exists, err := AWS.DoesBucketExist(clusterConfig.Bucket)
107138
if err != nil {
108139
return err
@@ -126,14 +157,6 @@ func Init() error {
126157
fmt.Println(errors.Message(err))
127158
}
128159

129-
if K8s, err = k8s.New(clusterNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
130-
return err
131-
}
132-
133-
if K8sIstio, err = k8s.New(istioNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
134-
return err
135-
}
136-
137160
prometheusURL := os.Getenv("CORTEX_PROMETHEUS_URL")
138161
if len(prometheusURL) == 0 {
139162
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", clusterNamespace)

pkg/lib/configreader/reader.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,20 @@ func ParseYAMLFile(dest interface{}, validation *StructValidation, filePath stri
10381038
return nil
10391039
}
10401040

1041+
func ParseYAMLBytes(dest interface{}, validation *StructValidation, data []byte) error {
1042+
fileInterface, err := ReadYAMLBytes(data)
1043+
if err != nil {
1044+
return nil
1045+
}
1046+
1047+
errs := Struct(dest, fileInterface, validation)
1048+
if errors.HasError(errs) {
1049+
return errors.FirstError(errs...)
1050+
}
1051+
1052+
return nil
1053+
}
1054+
10411055
func ReadYAMLFile(filePath string) (interface{}, error) {
10421056
fileBytes, err := files.ReadFileBytes(filePath)
10431057
if err != nil {

0 commit comments

Comments
 (0)