Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ankicabarisic authored Aug 6, 2024
1 parent 3e0e113 commit 25f418e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,4 @@ gradle-app.setting

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
!/docker/docker-compose.yaml
58 changes: 43 additions & 15 deletions sal-service/src/main/resources/wait_for_master.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,51 @@ def checkIPFromServers() {
println "Unable to retrieve the public IP from any server."
}

def getKubeToken(){
def soutToken = new StringBuilder(), serrToken = new StringBuilder()
// def proc = "kubeadm token create \"$(kubeadm token generate)\" --print-join-command --ttl=1h > /tmp/join_call.txt".execute()
def procToken = "kubeadm token generate".execute()
procToken.consumeProcessOutput(soutToken, serrToken)
procToken.waitForOrKill(1000)
println "out> ${soutToken}\nerr> ${serrToken}"

def soutCommand = new StringBuilder(), serrCommand = new StringBuilder()
procCommand="kubeadm token create ${soutToken} --print-join-command --ttl=1h".execute()
procCommand.consumeProcessOutput(soutCommand, serrCommand)
procCommand.waitForOrKill(1000)
println "out> ${soutCommand}\nerr> ${serrCommand}"
variables.put("kubeCommand", soutCommand)
def getKubeToken(int retryCount = 5, int retryDelay = 1000) {
for (int attempt = 1; attempt <= retryCount; attempt++) {
println "Attempt ${attempt} of ${retryCount}"

// Generate token
def soutToken = new StringBuilder(), serrToken = new StringBuilder()
def procToken = "kubeadm token generate".execute()
procToken.consumeProcessOutput(soutToken, serrToken)
procToken.waitForOrKill(1000)
println "Token generation - out> ${soutToken}\nerr> ${serrToken}"

if (serrToken.toString().trim()) {
println "Error generating token: ${serrToken}"
sleep(retryDelay)
continue
}

def token = soutToken.toString().trim()

// Create join command
def soutCommand = new StringBuilder(), serrCommand = new StringBuilder()
def procCommand = "kubeadm token create ${token} --print-join-command --ttl=1h".execute()
procCommand.consumeProcessOutput(soutCommand, serrCommand)
procCommand.waitForOrKill(1000)
println "Join command generation - out> ${soutCommand}\nerr> ${serrCommand}"

if (serrCommand.toString().trim() || soutCommand.toString().trim().isEmpty()) {
println "Error generating join command: ${serrCommand}"
sleep(retryDelay)
continue
}

// Store the join command and return
def joinCommand = soutCommand.toString().trim()
variables.put("kubeCommand", joinCommand)
println "kubeCommand stored: ${joinCommand}"
return
}

println "Failed to generate kube join command after ${retryCount} attempts."
}

getKubeToken()
// Call the function with the desired number of retries
getKubeToken(5, 1000) // Retry 3 times with a delay of 1000ms (1 second) between attempts


// Call the function to check the IP
result = checkIPFromServers()

0 comments on commit 25f418e

Please sign in to comment.