From c9da2b8cc10d60b63960b6635242bd1e36b1c53d Mon Sep 17 00:00:00 2001 From: John Dietz Date: Tue, 12 Mar 2024 01:43:34 -0400 Subject: [PATCH] adjust detokenize for k3s tokens (#309) --- pkg/providerConfigs/detokenize.go | 61 ++++++++++++++++--------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/pkg/providerConfigs/detokenize.go b/pkg/providerConfigs/detokenize.go index 270a76d3..24d28881 100644 --- a/pkg/providerConfigs/detokenize.go +++ b/pkg/providerConfigs/detokenize.go @@ -97,37 +97,38 @@ func detokenizeGitops(path string, tokens *GitopsDirectoryValues, gitProtocol st newContents = strings.Replace(newContents, "", tokens.ForceDestroy, -1) newContents = strings.Replace(newContents, "", tokens.GoogleUniqueness, -1) - // k3s - newContents = strings.Replace(newContents, "", tokens.K3sServersPrivateIps[0], -1) - // TODO: this is a hack to get around - // need to be refactored into a single function with args - var terraformServersPrivateIpsList string - jsonBytes, err := json.Marshal(tokens.K3sServersPrivateIps) - if err != nil { - log.Fatal().Msgf("detokenise issue on %s", err) + if tokens.CloudProvider == "k3s" { + // k3s + newContents = strings.Replace(newContents, "", tokens.K3sServersPrivateIps[0], -1) + // TODO: this is a hack to get around + // need to be refactored into a single function with args + var terraformServersPrivateIpsList string + jsonBytes, err := json.Marshal(tokens.K3sServersPrivateIps) + if err != nil { + log.Fatal().Msgf("detokenise issue on %s", err) + } + terraformServersPrivateIpsList = string(jsonBytes) + newContents = strings.Replace(newContents, "", terraformServersPrivateIpsList, -1) + + var terraformServersPublicIpsList string + jsonBytes2, err := json.Marshal(tokens.K3sServersPublicIps) + if err != nil { + log.Fatal().Msgf("detokenise issue on %s", err) + } + terraformServersPublicIpsList = string(jsonBytes2) + newContents = strings.Replace(newContents, "", terraformServersPublicIpsList, -1) + + var terraformServersArgsList string + jsonBytes3, err := json.Marshal(tokens.K3sServersArgs) + if err != nil { + log.Fatal().Msgf("detokenise issue on %s", err) + } + terraformServersArgsList = string(jsonBytes3) + newContents = strings.Replace(newContents, "", terraformServersArgsList, -1) + + newContents = strings.Replace(newContents, "", tokens.SshUser, -1) + newContents = strings.Replace(newContents, "", tokens.SshPrivateKey, -1) } - terraformServersPrivateIpsList = string(jsonBytes) - newContents = strings.Replace(newContents, "", terraformServersPrivateIpsList, -1) - - var terraformServersPublicIpsList string - jsonBytes2, err := json.Marshal(tokens.K3sServersPublicIps) - if err != nil { - log.Fatal().Msgf("detokenise issue on %s", err) - } - terraformServersPublicIpsList = string(jsonBytes2) - newContents = strings.Replace(newContents, "", terraformServersPublicIpsList, -1) - - var terraformServersArgsList string - jsonBytes3, err := json.Marshal(tokens.K3sServersArgs) - if err != nil { - log.Fatal().Msgf("detokenise issue on %s", err) - } - terraformServersArgsList = string(jsonBytes3) - newContents = strings.Replace(newContents, "", terraformServersArgsList, -1) - - newContents = strings.Replace(newContents, "", tokens.SshUser, -1) - newContents = strings.Replace(newContents, "", tokens.SshPrivateKey, -1) - newContents = strings.Replace(newContents, "", tokens.ArgoCDIngressURL, -1) newContents = strings.Replace(newContents, "", tokens.ArgoCDIngressNoHTTPSURL, -1) newContents = strings.Replace(newContents, "", tokens.ArgoWorkflowsIngressURL, -1)