From b7bb7cb246eb639629f204c2aca2b446bfb4b244 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Wed, 7 Aug 2024 15:42:45 +0100 Subject: [PATCH] Support ssh-key for k3sup plan Fixes: #436 Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- cmd/plan.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cmd/plan.go b/cmd/plan.go index 0bdc70f..c921949 100644 --- a/cmd/plan.go +++ b/cmd/plan.go @@ -84,7 +84,14 @@ Examples JSON input file: tlsSanStr = fmt.Sprintf(` \ --tls-san %s`, tlsSan) } - // sshKey, _ := cmd.Flags().GetString("ssh-key") + + sshKey, _ := cmd.Flags().GetString("ssh-key") + + sshKeySt := "" + if len(sshKey) > 0 { + sshKeySt = fmt.Sprintf(` \ +--ssh-key %s`, sshKey) + } bgStr := "" if background { @@ -116,20 +123,21 @@ Examples JSON input file: --user %s \ --cluster \ --local-path %s \ ---context %s%s%s +--context %s%s%s%s `, host.IP, user, kubeconfig, contextName, tlsSanStr, - serverExtraArgsSt) + serverExtraArgsSt, + sshKeySt) script += fmt.Sprintf(` echo "Fetching the server's node-token into memory" -export NODE_TOKEN=$(k3sup node-token --host %s --user %s) -`, host.IP, user) +export NODE_TOKEN=$(k3sup node-token --host %s --user %s%s) +`, host.IP, user, sshKeySt) serversAdded = 1 primaryServer = host @@ -141,8 +149,8 @@ export NODE_TOKEN=$(k3sup node-token --host %s --user %s) --server-host %s \ --server \ --node-token "$NODE_TOKEN" \ ---user %s%s%s%s -`, host.IP, primaryServer.IP, user, tlsSanStr, serverExtraArgsSt, bgStr) +--user %s%s%s%s%s +`, host.IP, primaryServer.IP, user, tlsSanStr, serverExtraArgsSt, sshKeySt, bgStr) serversAdded++ } else { @@ -152,8 +160,8 @@ export NODE_TOKEN=$(k3sup node-token --host %s --user %s) --host %s \ --server-host %s \ --node-token "$NODE_TOKEN" \ ---user %s%s%s -`, host.IP, primaryServer.IP, user, agentExtraArgsSt, bgStr) +--user %s%s%s%s +`, host.IP, primaryServer.IP, user, agentExtraArgsSt, sshKeySt, bgStr) } if nodeLimit > 0 && i+1 >= nodeLimit {