Skip to content

Commit 7c46544

Browse files
Merge pull request #3203 from openshift-cherrypick-robot/cherry-pick-3199-to-release-4.18
[release-4.18] OCPBUGS-60770: add k8s-cacert to hybrid overlay cmd
2 parents 9c20667 + 5af9ef3 commit 7c46544

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

pkg/services/services.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func hybridOverlayConfiguration(vxlanPort string, debug bool) servicescm.Service
108108
hybridOverlayServiceCmd := fmt.Sprintf("%s --node NODE_NAME --bootstrap-kubeconfig=%s --cert-dir=%s --cert-duration=24h "+
109109
"--windows-service --logfile "+"%s\\hybrid-overlay.log", windows.HybridOverlayPath, windows.KubeconfigPath, windows.CniConfDir,
110110
windows.HybridOverlayLogDir)
111+
112+
// append cacert option pointing to the trusted CA bundle path
113+
hybridOverlayServiceCmd = fmt.Sprintf("%s --k8s-cacert %s", hybridOverlayServiceCmd, windows.TrustedCABundlePath)
114+
111115
if len(vxlanPort) > 0 {
112116
hybridOverlayServiceCmd = fmt.Sprintf("%s --hybrid-overlay-vxlan-port %s", hybridOverlayServiceCmd, vxlanPort)
113117
}

pkg/services/services_test.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55

66
config "github.com/openshift/api/config/v1"
77
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/openshift/windows-machine-config-operator/pkg/windows"
811
)
912

1013
func TestGetHostnameCmd(t *testing.T) {
@@ -41,3 +44,109 @@ func TestGetHostnameCmd(t *testing.T) {
4144
})
4245
}
4346
}
47+
48+
func TestHybridOverlayConfiguration(t *testing.T) {
49+
tests := []struct {
50+
name string
51+
vxlanPort string
52+
debug bool
53+
expectedCmdContains []string
54+
expectedCmdNotContains []string
55+
}{
56+
{
57+
name: "Basic configuration with no optional flags",
58+
vxlanPort: "",
59+
debug: false,
60+
expectedCmdContains: []string{
61+
windows.HybridOverlayPath,
62+
"--node NODE_NAME",
63+
"--bootstrap-kubeconfig=" + windows.KubeconfigPath,
64+
"--cert-dir=" + windows.CniConfDir,
65+
"--cert-duration=24h",
66+
"--windows-service",
67+
"--logfile",
68+
windows.HybridOverlayLogDir + "\\hybrid-overlay.log",
69+
"--k8s-cacert " + windows.TrustedCABundlePath,
70+
},
71+
expectedCmdNotContains: []string{
72+
"--hybrid-overlay-vxlan-port",
73+
"--loglevel 5",
74+
},
75+
},
76+
{
77+
name: "Configuration with debug logging enabled",
78+
vxlanPort: "",
79+
debug: true,
80+
expectedCmdContains: []string{
81+
windows.HybridOverlayPath,
82+
"--node NODE_NAME",
83+
"--bootstrap-kubeconfig=" + windows.KubeconfigPath,
84+
"--cert-dir=" + windows.CniConfDir,
85+
"--cert-duration=24h",
86+
"--windows-service",
87+
"--logfile",
88+
windows.HybridOverlayLogDir + "\\hybrid-overlay.log",
89+
"--k8s-cacert " + windows.TrustedCABundlePath,
90+
"--loglevel 5",
91+
},
92+
expectedCmdNotContains: []string{
93+
"--hybrid-overlay-vxlan-port",
94+
},
95+
},
96+
{
97+
name: "Configuration with all optional flags enabled",
98+
vxlanPort: "4789",
99+
debug: true,
100+
expectedCmdContains: []string{
101+
windows.HybridOverlayPath,
102+
"--node NODE_NAME",
103+
"--bootstrap-kubeconfig=" + windows.KubeconfigPath,
104+
"--cert-dir=" + windows.CniConfDir,
105+
"--cert-duration=24h",
106+
"--windows-service",
107+
"--logfile",
108+
windows.HybridOverlayLogDir + "\\hybrid-overlay.log",
109+
"--k8s-cacert " + windows.TrustedCABundlePath,
110+
"--hybrid-overlay-vxlan-port 4789",
111+
"--loglevel 5",
112+
},
113+
expectedCmdNotContains: []string{},
114+
},
115+
}
116+
117+
for _, test := range tests {
118+
t.Run(test.name, func(t *testing.T) {
119+
result := hybridOverlayConfiguration(test.vxlanPort, test.debug)
120+
121+
assert.Equal(t, windows.HybridOverlayServiceName, result.Name,
122+
"Service name should match expected value")
123+
assert.False(t, result.Bootstrap,
124+
"Service should not be a bootstrap service")
125+
assert.Equal(t, uint(2), result.Priority,
126+
"Service priority should be 2")
127+
assert.Equal(t, []string{windows.KubeletServiceName}, result.Dependencies,
128+
"Service should depend on kubelet service")
129+
assert.Nil(t, result.PowershellPreScripts,
130+
"Service should not have PowerShell pre-scripts")
131+
132+
require.Len(t, result.NodeVariablesInCommand, 1,
133+
"Service should have exactly one node variable")
134+
assert.Equal(t, "NODE_NAME", result.NodeVariablesInCommand[0].Name,
135+
"Node variable name should be NODE_NAME")
136+
assert.Equal(t, "{.metadata.name}", result.NodeVariablesInCommand[0].NodeObjectJsonPath,
137+
"Node variable JSON path should match expected format")
138+
139+
for _, expectedStr := range test.expectedCmdContains {
140+
assert.Contains(t, result.Command, expectedStr,
141+
"Command should contain: %s\nActual command: %s",
142+
expectedStr, result.Command)
143+
}
144+
145+
for _, unexpectedStr := range test.expectedCmdNotContains {
146+
assert.NotContains(t, result.Command, unexpectedStr,
147+
"Command should not contain: %s\nActual command: %s",
148+
unexpectedStr, result.Command)
149+
}
150+
})
151+
}
152+
}

0 commit comments

Comments
 (0)