Skip to content

Commit a844e2a

Browse files
vishalbolluMiguel Varela Ramos
authored and
Miguel Varela Ramos
committed
Make --print-config display yaml that is consumable by cortex configure (#2324)
1 parent edf1204 commit a844e2a

File tree

9 files changed

+107
-160
lines changed

9 files changed

+107
-160
lines changed

cli/cmd/cluster.go

+31-14
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,10 @@ var _clusterInfoCmd = &cobra.Command{
455455

456456
if _flagClusterInfoDebug {
457457
cmdDebug(awsClient, accessConfig)
458+
} else if _flagClusterInfoPrintConfig {
459+
cmdPrintConfig(awsClient, accessConfig, _flagOutput)
458460
} else {
459-
cmdInfo(awsClient, accessConfig, stacks, _flagClusterInfoPrintConfig, _flagOutput, _flagClusterDisallowPrompt)
461+
cmdInfo(awsClient, accessConfig, stacks, _flagOutput, _flagClusterDisallowPrompt)
460462
}
461463
},
462464
}
@@ -853,7 +855,27 @@ var _clusterHealthCmd = &cobra.Command{
853855
},
854856
}
855857

856-
func cmdInfo(awsClient *awslib.Client, accessConfig *clusterconfig.AccessConfig, stacks clusterstate.ClusterStacks, printConfig bool, outputType flags.OutputType, disallowPrompt bool) {
858+
func cmdPrintConfig(awsClient *awslib.Client, accessConfig *clusterconfig.AccessConfig, outputType flags.OutputType) {
859+
clusterConfig := refreshCachedClusterConfig(awsClient, accessConfig, outputType == flags.PrettyOutputType)
860+
861+
infoInterface := clusterConfig.CoreConfig
862+
863+
if outputType == flags.JSONOutputType {
864+
outputBytes, err := libjson.Marshal(infoInterface)
865+
if err != nil {
866+
exit.Error(err)
867+
}
868+
fmt.Println(string(outputBytes))
869+
} else {
870+
outputBytes, err := yaml.Marshal(infoInterface)
871+
if err != nil {
872+
exit.Error(err)
873+
}
874+
fmt.Println(string(outputBytes))
875+
}
876+
}
877+
878+
func cmdInfo(awsClient *awslib.Client, accessConfig *clusterconfig.AccessConfig, stacks clusterstate.ClusterStacks, outputType flags.OutputType, disallowPrompt bool) {
857879
clusterConfig := refreshCachedClusterConfig(awsClient, accessConfig, outputType == flags.PrettyOutputType)
858880

859881
operatorLoadBalancer, err := getLoadBalancer(accessConfig.ClusterName, OperatorLoadBalancer, awsClient)
@@ -875,18 +897,13 @@ func cmdInfo(awsClient *awslib.Client, accessConfig *clusterconfig.AccessConfig,
875897
}
876898
infoResponse.ClusterConfig.Config = clusterConfig
877899

878-
var infoInterface interface{}
879-
if printConfig {
880-
infoInterface = infoResponse.ClusterConfig.Config
881-
} else {
882-
infoInterface = map[string]interface{}{
883-
"cluster_config": infoResponse.ClusterConfig.Config,
884-
"cluster_metadata": infoResponse.ClusterConfig.OperatorMetadata,
885-
"worker_node_infos": infoResponse.WorkerNodeInfos,
886-
"operator_node_infos": infoResponse.OperatorNodeInfos,
887-
"endpoint_operator": operatorEndpoint,
888-
"endpoint_api": apiEndpoint,
889-
}
900+
infoInterface := map[string]interface{}{
901+
"cluster_config": infoResponse.ClusterConfig.Config,
902+
"cluster_metadata": infoResponse.ClusterConfig.OperatorMetadata,
903+
"worker_node_infos": infoResponse.WorkerNodeInfos,
904+
"operator_node_infos": infoResponse.OperatorNodeInfos,
905+
"endpoint_operator": operatorEndpoint,
906+
"endpoint_api": apiEndpoint,
890907
}
891908

892909
var outputBytes []byte

cli/cmd/lib_cluster_config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func existingCachedClusterConfigPaths() []string {
6161
}
6262

6363
func readCachedClusterConfigFile(clusterConfig *clusterconfig.Config, filePath string) error {
64-
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullManagedValidation, filePath)
64+
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullConfigValidation, filePath)
6565
if errors.HasError(errs) {
6666
return errors.FirstError(errs...)
6767
}
@@ -70,7 +70,7 @@ func readCachedClusterConfigFile(clusterConfig *clusterconfig.Config, filePath s
7070
}
7171

7272
func readUserClusterConfigFile(clusterConfig *clusterconfig.Config, filePath string) error {
73-
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullManagedValidation, filePath)
73+
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullConfigValidation, filePath)
7474
if errors.HasError(errs) {
7575
return errors.Append(errors.FirstError(errs...), fmt.Sprintf("\n\ncluster configuration schema can be found at https://docs.cortex.dev/v/%s/", consts.CortexVersionMinor))
7676
}

pkg/config/config.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func getClusterConfigFromConfigMap() (clusterconfig.Config, error) {
6868
return clusterconfig.Config{}, err
6969
}
7070
clusterConfig := clusterconfig.Config{}
71-
err = cr.ParseYAMLBytes(&clusterConfig, clusterconfig.FullManagedValidation, []byte(configMapData["cluster.yaml"]))
71+
err = cr.ParseYAMLBytes(&clusterConfig, clusterconfig.FullConfigValidation, []byte(configMapData["cluster.yaml"]))
7272
if err != nil {
7373
return clusterconfig.Config{}, err
7474
}
@@ -78,8 +78,6 @@ func getClusterConfigFromConfigMap() (clusterconfig.Config, error) {
7878

7979
func Init() error {
8080
var err error
81-
var clusterNamespace string
82-
var istioNamespace string
8381

8482
clusterConfigPath := os.Getenv("CORTEX_CLUSTER_CONFIG_PATH")
8583
if clusterConfigPath == "" {
@@ -112,14 +110,11 @@ func Init() error {
112110
IsOperatorInCluster: strings.ToLower(os.Getenv("CORTEX_OPERATOR_IN_CLUSTER")) != "false",
113111
}
114112

115-
clusterNamespace = clusterConfig.Namespace
116-
istioNamespace = clusterConfig.IstioNamespace
117-
118-
if K8s, err = k8s.New(clusterNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
113+
if K8s, err = k8s.New(consts.DefaultNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
119114
return err
120115
}
121116

122-
if K8sIstio, err = k8s.New(istioNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
117+
if K8sIstio, err = k8s.New(consts.IstioNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
123118
return err
124119
}
125120

@@ -157,7 +152,7 @@ func Init() error {
157152

158153
prometheusURL := os.Getenv("CORTEX_PROMETHEUS_URL")
159154
if len(prometheusURL) == 0 {
160-
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", clusterNamespace)
155+
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", consts.DefaultNamespace)
161156
}
162157

163158
promClient, err := promapi.NewClient(promapi.Config{
@@ -172,9 +167,11 @@ func Init() error {
172167
return err
173168
}
174169

175-
MetricsClient, err = statsd.New("prometheus-statsd-exporter.default:9125")
176-
if err != nil {
177-
return errors.Wrap(errors.WithStack(err), "unable to initialize metrics client")
170+
if OperatorMetadata.IsOperatorInCluster {
171+
MetricsClient, err = statsd.New(fmt.Sprintf("prometheus-statsd-exporter.%s:9125", consts.DefaultNamespace))
172+
if err != nil {
173+
return errors.Wrap(errors.WithStack(err), "unable to initialize metrics client")
174+
}
178175
}
179176

180177
return nil

pkg/consts/consts.go

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var (
2727
CortexVersion = "master" // CORTEX_VERSION
2828
CortexVersionMinor = "master" // CORTEX_VERSION_MINOR
2929

30+
DefaultNamespace = "default"
31+
IstioNamespace = "istio-system"
32+
3033
DefaultMaxQueueLength = int64(100)
3134
DefaultMaxConcurrency = int64(1)
3235

pkg/crds/controllers/batch/batchjob_controller_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func (r *BatchJobReconciler) updateStatus(ctx context.Context, batchJob *batch.B
529529
func (r *BatchJobReconciler) checkWorkersOOM(ctx context.Context, batchJob *batch.BatchJob) (bool, error) {
530530
workerJobPods := kcore.PodList{}
531531
if err := r.List(ctx, &workerJobPods,
532-
client.InNamespace(r.ClusterConfig.Namespace),
532+
client.InNamespace(consts.DefaultNamespace),
533533
client.MatchingLabels{
534534
"jobID": batchJob.Name,
535535
"apiName": batchJob.Spec.APIName,

pkg/crds/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func main() {
105105
}
106106

107107
if prometheusURL == "" {
108-
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", clusterConfig.Namespace)
108+
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", consts.DefaultNamespace)
109109
}
110110

111111
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{

pkg/operator/operator/cron.go

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ func ClusterTelemetry() error {
8484
}
8585
telemetry.Event("operator.cron", properties,
8686
config.ClusterConfig.CoreConfig.TelemetryEvent(),
87-
config.ClusterConfig.ManagedConfig.TelemetryEvent(),
8887
)
8988

9089
return nil

pkg/operator/resources/realtimeapi/k8s_specs.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package realtimeapi
1919
import (
2020
"fmt"
2121

22-
"github.com/cortexlabs/cortex/pkg/config"
2322
"github.com/cortexlabs/cortex/pkg/consts"
2423
"github.com/cortexlabs/cortex/pkg/lib/k8s"
2524
"github.com/cortexlabs/cortex/pkg/lib/pointer"
@@ -135,7 +134,7 @@ func virtualServiceSpec(api *spec.API) *istioclientnetworking.VirtualService {
135134
consts.CortexTargetServiceHeader: fmt.Sprintf(
136135
"http://%s.%s:%d",
137136
workloads.K8sName(api.Name),
138-
config.ClusterConfig.Namespace,
137+
consts.DefaultNamespace,
139138
consts.ProxyPortInt32,
140139
),
141140
},

0 commit comments

Comments
 (0)