Skip to content

Commit 9c40847

Browse files
committed
adds DATACRUNCH_STARTUP_SCRIPT_FILE env var
1 parent 2f55d90 commit 9c40847

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

cluster-autoscaler/cloudprovider/datacrunch/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ DATACRUNCH_CLUSTER_CONFIG_FILE="/path/to/config.json" # File path
7878

7979
# Optional: Startup script configuration
8080
DATACRUNCH_STARTUP_SCRIPT="#!/bin/bash\necho 'Hello World'" # Global startup script
81+
DATACRUNCH_STARTUP_SCRIPT_FILE="<path to file>" # Is only read when DATACRUNCH_STARTUP_SCRIPT is empty
8182
DATACRUNCH_DELETE_SCRIPTS_AFTER_BOOT="true" # Auto-delete scripts after execution
8283
```
8384

@@ -197,7 +198,7 @@ spec:
197198
You can configure startup scripts in three ways (in order of precedence):
198199
199200
1. **Per-nodepool scripts** (highest precedence): Set `startup_script_base64` in nodepool configuration
200-
2. **Global startup script**: Set `DATACRUNCH_STARTUP_SCRIPT` environment variable
201+
2. **Global startup script**: Set `DATACRUNCH_STARTUP_SCRIPT` or `DATACRUNCH_STARTUP_SCRIPT_FILE` environment variables. `DATACRUNCH_STARTUP_SCRIPT` takes precedence.
201202
3. **No startup script**: Instances will boot with default image configuration
202203

203204
Example per-nodepool script configuration:

cluster-autoscaler/cloudprovider/datacrunch/datacrunch_manager.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type datacrunchManager struct {
4141
clusterConfig *ClusterConfig
4242
cachedServerType *serverTypeCache
4343
cachedServers *serversCache
44-
startupScript string
4544
}
4645

4746
// ClusterConfig holds the configuration for all the nodepools
@@ -102,7 +101,6 @@ func newManager() (*datacrunchManager, error) {
102101
clusterConfigBase64 := os.Getenv("DATACRUNCH_CLUSTER_CONFIG")
103102
clusterConfigBaseJSON := os.Getenv("DATACRUNCH_CLUSTER_CONFIG_JSON")
104103
clusterConfigFile := os.Getenv("DATACRUNCH_CLUSTER_CONFIG_FILE")
105-
startupScript := os.Getenv("DATACRUNCH_STARTUP_SCRIPT")
106104

107105
if clusterConfigBase64 == "" && clusterConfigFile == "" && clusterConfigBaseJSON == "" {
108106
return nil, errors.New("one of `DATACRUNCH_CLUSTER_CONFIG`, `DATACRUNCH_CLUSTER_CONFIG_FILE` or `DATACRUNCH_CLUSTER_CONFIG_JSON` must be specified")
@@ -137,7 +135,6 @@ func newManager() (*datacrunchManager, error) {
137135
clusterConfig: clusterConfig,
138136
cachedServerType: newServerTypeCache(ctx, client),
139137
cachedServers: newServersCache(ctx, client),
140-
startupScript: startupScript,
141138
}
142139

143140
return m, nil

cluster-autoscaler/cloudprovider/datacrunch/datacrunch_node_group.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,16 @@ func createServer(n *datacrunchNodeGroup) error {
609609
startupScriptName := fmt.Sprintf("autoscaler-startup-script-%s", nodeName)
610610

611611
var startupScriptID string
612-
startupScript := n.manager.startupScript
612+
startupScript := os.Getenv("DATACRUNCH_STARTUP_SCRIPT")
613+
startupScriptFile := os.Getenv("DATACRUNCH_STARTUP_SCRIPT_FILE")
614+
if startupScript == "" && startupScriptFile != "" {
615+
startupScriptBytes, err := os.ReadFile(startupScriptFile)
616+
if err != nil {
617+
return fmt.Errorf("failed to read startup script file: %v", err)
618+
}
619+
startupScript = string(startupScriptBytes)
620+
}
621+
613622
if n.manager.clusterConfig.NodeConfigs[n.id].StartupScriptBase64 != "" {
614623
startupScriptBytes, err := base64.StdEncoding.DecodeString(n.manager.clusterConfig.NodeConfigs[n.id].StartupScriptBase64)
615624
if err != nil {

0 commit comments

Comments
 (0)