Skip to content

Commit 44bb600

Browse files
authored
Restart deployments depending on cluster config during cx configure (#2367)
1 parent 17583ad commit 44bb600

File tree

6 files changed

+32
-54
lines changed

6 files changed

+32
-54
lines changed

cmd/activator/main.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"os/signal"
2525
"strconv"
26+
"strings"
2627
"time"
2728

2829
"github.com/cortexlabs/cortex/pkg/activator"
@@ -32,7 +33,6 @@ import (
3233
"github.com/cortexlabs/cortex/pkg/lib/k8s"
3334
"github.com/cortexlabs/cortex/pkg/lib/logging"
3435
"github.com/cortexlabs/cortex/pkg/lib/telemetry"
35-
"github.com/cortexlabs/cortex/pkg/types/clusterconfig"
3636
"github.com/cortexlabs/cortex/pkg/types/userconfig"
3737
"go.uber.org/zap"
3838
istioinformers "istio.io/client-go/pkg/informers/externalversions"
@@ -43,12 +43,11 @@ import (
4343

4444
func main() {
4545
var (
46-
port int
47-
adminPort int
48-
inCluster bool
49-
autoscalerURL string
50-
namespace string
51-
clusterConfigPath string
46+
port int
47+
adminPort int
48+
inCluster bool
49+
autoscalerURL string
50+
namespace string
5251
)
5352

5453
flag.IntVar(&port, "port", 8000, "port where the activator server will be exposed")
@@ -59,7 +58,6 @@ func main() {
5958
"kubernetes namespace where the cortex APIs are deployed "+
6059
"(can be set through the CORTEX_NAMESPACE env variable)",
6160
)
62-
flag.StringVar(&clusterConfigPath, "cluster-config", "", "cluster config path")
6361
flag.Parse()
6462

6563
log := logging.GetLogger()
@@ -72,16 +70,9 @@ func main() {
7270
log.Fatal("--autoscaler-url is a required option")
7371
case namespace == "":
7472
log.Fatal("--namespace is a required option")
75-
case clusterConfigPath == "":
76-
log.Fatal("--cluster-config flag is required")
7773
}
7874

79-
clusterConfig, err := clusterconfig.NewForFile(clusterConfigPath)
80-
if err != nil {
81-
exit(log, err)
82-
}
83-
84-
awsClient, err := aws.NewForRegion(clusterConfig.Region)
75+
awsClient, err := aws.New()
8576
if err != nil {
8677
exit(log, err)
8778
}
@@ -91,8 +82,10 @@ func main() {
9182
exit(log, err)
9283
}
9384

85+
telemetryEnabled := strings.ToLower(os.Getenv("CORTEX_TELEMETRY_DISABLE")) != "true"
86+
9487
err = telemetry.Init(telemetry.Config{
95-
Enabled: clusterConfig.Telemetry,
88+
Enabled: telemetryEnabled,
9689
UserID: userID,
9790
Properties: map[string]string{
9891
"kind": userconfig.RealtimeAPIKind.String(),

cmd/autoscaler/main.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"os/signal"
2626
"strconv"
27+
"strings"
2728
"time"
2829

2930
"github.com/cortexlabs/cortex/pkg/autoscaler"
@@ -32,7 +33,6 @@ import (
3233
"github.com/cortexlabs/cortex/pkg/lib/k8s"
3334
"github.com/cortexlabs/cortex/pkg/lib/logging"
3435
"github.com/cortexlabs/cortex/pkg/lib/telemetry"
35-
"github.com/cortexlabs/cortex/pkg/types/clusterconfig"
3636
"github.com/cortexlabs/cortex/pkg/types/userconfig"
3737
"github.com/gorilla/mux"
3838
promapi "github.com/prometheus/client_golang/api"
@@ -49,11 +49,10 @@ import (
4949

5050
func main() {
5151
var (
52-
port int
53-
inCluster bool
54-
prometheusURL string
55-
namespace string
56-
clusterConfigPath string
52+
port int
53+
inCluster bool
54+
prometheusURL string
55+
namespace string
5756
)
5857

5958
flag.IntVar(&port, "port", 8000, "port where the autoscaler server will be exposed")
@@ -65,7 +64,6 @@ func main() {
6564
"kubernetes namespace where the cortex APIs are deployed "+
6665
"(can be set through the CORTEX_NAMESPACE env variable)",
6766
)
68-
flag.StringVar(&clusterConfigPath, "cluster-config", "", "cluster config path")
6967
flag.Parse()
7068

7169
log := logging.GetLogger()
@@ -78,16 +76,9 @@ func main() {
7876
log.Fatal("--prometheus-url is a required option")
7977
case namespace == "":
8078
log.Fatal("--namespace is a required option")
81-
case clusterConfigPath == "":
82-
log.Fatal("--cluster-config flag is required")
8379
}
8480

85-
clusterConfig, err := clusterconfig.NewForFile(clusterConfigPath)
86-
if err != nil {
87-
exit(log, err)
88-
}
89-
90-
awsClient, err := aws.NewForRegion(clusterConfig.Region)
81+
awsClient, err := aws.New()
9182
if err != nil {
9283
exit(log, err)
9384
}
@@ -97,8 +88,10 @@ func main() {
9788
exit(log, err)
9889
}
9990

91+
telemetryEnabled := strings.ToLower(os.Getenv("CORTEX_TELEMETRY_DISABLE")) != "true"
92+
10093
err = telemetry.Init(telemetry.Config{
101-
Enabled: clusterConfig.Telemetry,
94+
Enabled: telemetryEnabled,
10295
UserID: userID,
10396
Properties: map[string]string{
10497
"kind": userconfig.RealtimeAPIKind.String(),

manager/install.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ function cluster_configure() {
103103
python render_template.py $CORTEX_CLUSTER_CONFIG_FILE manifests/cluster-autoscaler.yaml.j2 | kubectl apply -f - >/dev/null
104104
echo ""
105105

106+
restart_controller_manager
107+
106108
restart_operator
107109

108110
validate_cortex
@@ -276,6 +278,14 @@ function start_controller_manager() {
276278
echo ""
277279
}
278280

281+
function restart_controller_manager() {
282+
echo -n "○ restarting controller manager "
283+
284+
kubectl rollout restart deployments/operator-controller-manager >/dev/null
285+
286+
echo ""
287+
}
288+
279289
function resize_nodegroups() {
280290
if [ -z "$CORTEX_NODEGROUP_NAMES_TO_SCALE" ]; then
281291
return

manager/manifests/activator.yaml.j2

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ spec:
8181
- "--port=8000"
8282
- "--autoscaler-url=http://autoscaler.default:8000"
8383
- "--namespace=default"
84-
- "--cluster-config=/configs/cluster/cluster.yaml"
8584
ports:
8685
- name: http
8786
containerPort: 8000
@@ -111,15 +110,6 @@ spec:
111110
envFrom:
112111
- configMapRef:
113112
name: env-vars
114-
volumeMounts:
115-
- mountPath: /configs/cluster/cluster.yaml
116-
name: cluster-config
117-
subPath: cluster.yaml
118-
volumes:
119-
- configMap:
120-
defaultMode: 420
121-
name: cluster-config
122-
name: cluster-config
123113
---
124114

125115
apiVersion: v1

manager/manifests/autoscaler.yaml.j2

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ spec:
8484
- "--port=8000"
8585
- "--prometheus-url=http://prometheus.prometheus:9090"
8686
- "--namespace=default"
87-
- "--cluster-config=/configs/cluster/cluster.yaml"
8887
ports:
8988
- containerPort: 8000
9089
livenessProbe:
@@ -102,16 +101,6 @@ spec:
102101
envFrom:
103102
- configMapRef:
104103
name: env-vars
105-
volumeMounts:
106-
- mountPath: /configs/cluster/cluster.yaml
107-
name: cluster-config
108-
subPath: cluster.yaml
109-
volumes:
110-
- configMap:
111-
defaultMode: 420
112-
name: cluster-config
113-
name: cluster-config
114-
115104
---
116105

117106
apiVersion: v1

pkg/crds/config/manager/manager.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ spec:
1111
matchLabels:
1212
control-plane: controller-manager
1313
replicas: 1
14+
strategy:
15+
rollingUpdate:
16+
maxSurge: 0
1417
template:
1518
metadata:
1619
labels:

0 commit comments

Comments
 (0)