Skip to content

Commit

Permalink
ensure newlines are added to custom windows agent environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonWAffel committed Dec 18, 2024
1 parent 966420b commit 5e2d63d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/capr/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func WindowsInstallScript(ctx context.Context, token string, envVars []corev1.En
if envVar.Value == "" {
continue
}
envVarBuf.WriteString(capr.FormatWindowsEnvVar(envVar, false))
envVarBuf.WriteString(capr.FormatWindowsEnvVar(envVar, false) + "\n")
}
server := ""
if settings.ServerURL.Get() != "" {
Expand Down
24 changes: 23 additions & 1 deletion pkg/capr/installer/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package installer
import (
"context"
"fmt"
"github.com/rancher/rancher/pkg/capr"
"testing"

"github.com/rancher/rancher/pkg/settings"
Expand All @@ -25,7 +26,23 @@ func TestInstaller_WindowsInstallScript(t *testing.T) {

CACertEncoded := systemtemplate.CAChecksum()

script, err := WindowsInstallScript(context.TODO(), "test", []corev1.EnvVar{}, "localhost", "/var/lib/rancher/rke2")
agentVar1 := corev1.EnvVar{
Name: "TestEnvVar1",
Value: "TestEnvVarValue",
}

agentVar2 := corev1.EnvVar{
Name: "TestEnvVar2",
Value: "TestEnvVarValue",
}

formattedAgentVar1 := capr.FormatWindowsEnvVar(agentVar1, false)
formattedAgentVar2 := capr.FormatWindowsEnvVar(agentVar2, false)

script, err := WindowsInstallScript(context.TODO(), "test", []corev1.EnvVar{
agentVar1,
agentVar2,
}, "localhost", "/var/lib/rancher/rke2")

// assert
a.Nil(err)
Expand All @@ -37,4 +54,9 @@ func TestInstaller_WindowsInstallScript(t *testing.T) {
a.Contains(string(script), "$env:CSI_PROXY_URL")
a.Contains(string(script), "$env:CSI_PROXY_VERSION")
a.Contains(string(script), "$env:CSI_PROXY_KUBELET_PATH")
a.Contains(string(script), "$env:TestEnvVar1")
a.Contains(string(script), "$env:TestEnvVar2")

// ensure agent env vars are not on the same line
a.NotContains(string(script), formattedAgentVar1+formattedAgentVar2)
}

0 comments on commit 5e2d63d

Please sign in to comment.