Skip to content

Commit 2529cda

Browse files
committed
fixes race condition during cloud init
1 parent ef3b1ee commit 2529cda

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cluster-autoscaler/cloudprovider/datacrunch/datacrunch_node_group.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ if [ "{{ .DELETE_SCRIPT }}" = "true" ]; then
7979
fi
8080
fi
8181
82-
# 3.Get instance ID based on $HOSTNAME
82+
# 3.Get instance ID based on node name
8383
INSTANCE_ID=$(curl -s https://api.datacrunch.io/v1/instances \
8484
--header "Authorization: Bearer $ACCESS_TOKEN" | \
85-
jq -r --arg HOSTNAME "$HOSTNAME" '.[] | select(.hostname == $HOSTNAME) | .id')
85+
jq -r --arg HOSTNAME "{{ .NODENAME }}" '.[] | select(.hostname == {{ .NODENAME }}) | .id')
8686
8787
if [ -n "$INSTANCE_ID" ]; then
88-
echo "Instance ID for hostname $HOSTNAME is $INSTANCE_ID"
88+
echo "Instance ID for hostname {{ .NODENAME }} is $INSTANCE_ID"
8989
else
90-
echo "No instance found for hostname $HOSTNAME"
90+
echo "No instance found for hostname {{ .NODENAME }}"
9191
fi
9292
`
9393
)
@@ -527,7 +527,7 @@ func processPreScriptTemplate(preScriptTemplate string, data interface{}) (strin
527527
return script.String(), nil
528528
}
529529

530-
func buildPreScript(n *datacrunchNodeGroup, scriptName string) (string, error) {
530+
func buildPreScript(scriptName string, nodeName string) (string, error) {
531531
// Get credentials from environment
532532
clientID := os.Getenv("DATACRUNCH_CLIENT_ID")
533533
clientSecret := os.Getenv("DATACRUNCH_CLIENT_SECRET")
@@ -544,6 +544,7 @@ func buildPreScript(n *datacrunchNodeGroup, scriptName string) (string, error) {
544544
"DATACRUNCH_CLIENT_SECRET": clientSecret,
545545
"SCRIPT_NAME": scriptName,
546546
"DELETE_SCRIPT": fmt.Sprintf("%t", deleteScriptsAfterBoot),
547+
"NODENAME": nodeName,
547548
}
548549

549550
// Process the template
@@ -630,7 +631,7 @@ func createServer(n *datacrunchNodeGroup) error {
630631

631632
if startupScript != "" {
632633
// Build pre-script from template
633-
preScript, err := buildPreScript(n, startupScriptName)
634+
preScript, err := buildPreScript(startupScriptName, nodeName)
634635
if err != nil {
635636
return fmt.Errorf("failed to build pre-script: %v", err)
636637
}

0 commit comments

Comments
 (0)