Skip to content

Make --print-config display yaml that is consumable by cortex configure #2324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions cli/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,10 @@ var _clusterInfoCmd = &cobra.Command{

if _flagClusterInfoDebug {
cmdDebug(awsClient, accessConfig)
} else if _flagClusterInfoPrintConfig {
cmdPrintConfig(awsClient, accessConfig, _flagOutput)
} else {
cmdInfo(awsClient, accessConfig, stacks, _flagClusterInfoPrintConfig, _flagOutput, _flagClusterDisallowPrompt)
cmdInfo(awsClient, accessConfig, stacks, _flagOutput, _flagClusterDisallowPrompt)
}
},
}
Expand Down Expand Up @@ -853,7 +855,27 @@ var _clusterHealthCmd = &cobra.Command{
},
}

func cmdInfo(awsClient *awslib.Client, accessConfig *clusterconfig.AccessConfig, stacks clusterstate.ClusterStacks, printConfig bool, outputType flags.OutputType, disallowPrompt bool) {
func cmdPrintConfig(awsClient *awslib.Client, accessConfig *clusterconfig.AccessConfig, outputType flags.OutputType) {
clusterConfig := refreshCachedClusterConfig(awsClient, accessConfig, outputType == flags.PrettyOutputType)

infoInterface := clusterConfig.CoreConfig

if outputType == flags.JSONOutputType {
outputBytes, err := libjson.Marshal(infoInterface)
if err != nil {
exit.Error(err)
}
fmt.Println(string(outputBytes))
} else {
outputBytes, err := yaml.Marshal(infoInterface)
if err != nil {
exit.Error(err)
}
fmt.Println(string(outputBytes))
}
}

func cmdInfo(awsClient *awslib.Client, accessConfig *clusterconfig.AccessConfig, stacks clusterstate.ClusterStacks, outputType flags.OutputType, disallowPrompt bool) {
clusterConfig := refreshCachedClusterConfig(awsClient, accessConfig, outputType == flags.PrettyOutputType)

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

var infoInterface interface{}
if printConfig {
infoInterface = infoResponse.ClusterConfig.Config
} else {
infoInterface = map[string]interface{}{
"cluster_config": infoResponse.ClusterConfig.Config,
"cluster_metadata": infoResponse.ClusterConfig.OperatorMetadata,
"worker_node_infos": infoResponse.WorkerNodeInfos,
"operator_node_infos": infoResponse.OperatorNodeInfos,
"endpoint_operator": operatorEndpoint,
"endpoint_api": apiEndpoint,
}
infoInterface := map[string]interface{}{
"cluster_config": infoResponse.ClusterConfig.Config,
"cluster_metadata": infoResponse.ClusterConfig.OperatorMetadata,
"worker_node_infos": infoResponse.WorkerNodeInfos,
"operator_node_infos": infoResponse.OperatorNodeInfos,
"endpoint_operator": operatorEndpoint,
"endpoint_api": apiEndpoint,
}

var outputBytes []byte
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/lib_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func existingCachedClusterConfigPaths() []string {
}

func readCachedClusterConfigFile(clusterConfig *clusterconfig.Config, filePath string) error {
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullManagedValidation, filePath)
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullConfigValidation, filePath)
if errors.HasError(errs) {
return errors.FirstError(errs...)
}
Expand All @@ -70,7 +70,7 @@ func readCachedClusterConfigFile(clusterConfig *clusterconfig.Config, filePath s
}

func readUserClusterConfigFile(clusterConfig *clusterconfig.Config, filePath string) error {
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullManagedValidation, filePath)
errs := cr.ParseYAMLFile(clusterConfig, clusterconfig.FullConfigValidation, filePath)
if errors.HasError(errs) {
return errors.Append(errors.FirstError(errs...), fmt.Sprintf("\n\ncluster configuration schema can be found at https://docs.cortex.dev/v/%s/", consts.CortexVersionMinor))
}
Expand Down
21 changes: 9 additions & 12 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func getClusterConfigFromConfigMap() (clusterconfig.Config, error) {
return clusterconfig.Config{}, err
}
clusterConfig := clusterconfig.Config{}
err = cr.ParseYAMLBytes(&clusterConfig, clusterconfig.FullManagedValidation, []byte(configMapData["cluster.yaml"]))
err = cr.ParseYAMLBytes(&clusterConfig, clusterconfig.FullConfigValidation, []byte(configMapData["cluster.yaml"]))
if err != nil {
return clusterconfig.Config{}, err
}
Expand All @@ -78,8 +78,6 @@ func getClusterConfigFromConfigMap() (clusterconfig.Config, error) {

func Init() error {
var err error
var clusterNamespace string
var istioNamespace string

clusterConfigPath := os.Getenv("CORTEX_CLUSTER_CONFIG_PATH")
if clusterConfigPath == "" {
Expand Down Expand Up @@ -112,14 +110,11 @@ func Init() error {
IsOperatorInCluster: strings.ToLower(os.Getenv("CORTEX_OPERATOR_IN_CLUSTER")) != "false",
}

clusterNamespace = clusterConfig.Namespace
istioNamespace = clusterConfig.IstioNamespace

if K8s, err = k8s.New(clusterNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
if K8s, err = k8s.New(consts.DefaultNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
return err
}

if K8sIstio, err = k8s.New(istioNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
if K8sIstio, err = k8s.New(consts.IstioNamespace, OperatorMetadata.IsOperatorInCluster, nil, scheme); err != nil {
return err
}

Expand Down Expand Up @@ -157,7 +152,7 @@ func Init() error {

prometheusURL := os.Getenv("CORTEX_PROMETHEUS_URL")
if len(prometheusURL) == 0 {
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", clusterNamespace)
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", consts.DefaultNamespace)
}

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

MetricsClient, err = statsd.New("prometheus-statsd-exporter.default:9125")
if err != nil {
return errors.Wrap(errors.WithStack(err), "unable to initialize metrics client")
if OperatorMetadata.IsOperatorInCluster {
MetricsClient, err = statsd.New(fmt.Sprintf("prometheus-statsd-exporter.%s:9125", consts.DefaultNamespace))
if err != nil {
return errors.Wrap(errors.WithStack(err), "unable to initialize metrics client")
}
}

return nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var (
CortexVersion = "master" // CORTEX_VERSION
CortexVersionMinor = "master" // CORTEX_VERSION_MINOR

DefaultNamespace = "default"
IstioNamespace = "istio-system"

DefaultMaxQueueLength = int64(100)
DefaultMaxConcurrency = int64(1)

Expand Down
2 changes: 1 addition & 1 deletion pkg/crds/controllers/batch/batchjob_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (r *BatchJobReconciler) updateStatus(ctx context.Context, batchJob *batch.B
func (r *BatchJobReconciler) checkWorkersOOM(ctx context.Context, batchJob *batch.BatchJob) (bool, error) {
workerJobPods := kcore.PodList{}
if err := r.List(ctx, &workerJobPods,
client.InNamespace(r.ClusterConfig.Namespace),
client.InNamespace(consts.DefaultNamespace),
client.MatchingLabels{
"jobID": batchJob.Name,
"apiName": batchJob.Spec.APIName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/crds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
}

if prometheusURL == "" {
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", clusterConfig.Namespace)
prometheusURL = fmt.Sprintf("http://prometheus.%s:9090", consts.DefaultNamespace)
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down
1 change: 0 additions & 1 deletion pkg/operator/operator/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func ClusterTelemetry() error {
}
telemetry.Event("operator.cron", properties,
config.ClusterConfig.CoreConfig.TelemetryEvent(),
config.ClusterConfig.ManagedConfig.TelemetryEvent(),
)

return nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/resources/realtimeapi/k8s_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package realtimeapi
import (
"fmt"

"github.com/cortexlabs/cortex/pkg/config"
"github.com/cortexlabs/cortex/pkg/consts"
"github.com/cortexlabs/cortex/pkg/lib/k8s"
"github.com/cortexlabs/cortex/pkg/lib/pointer"
Expand Down Expand Up @@ -135,7 +134,7 @@ func virtualServiceSpec(api *spec.API) *istioclientnetworking.VirtualService {
consts.CortexTargetServiceHeader: fmt.Sprintf(
"http://%s.%s:%d",
workloads.K8sName(api.Name),
config.ClusterConfig.Namespace,
consts.DefaultNamespace,
consts.ProxyPortInt32,
),
},
Expand Down
Loading