|
1 | 1 | package agent |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
| 5 | + "compress/gzip" |
4 | 6 | "context" |
| 7 | + "encoding/base64" |
| 8 | + "io" |
5 | 9 |
|
6 | 10 | "github.com/Azure/agentbaker/pkg/agent/datamodel" |
7 | 11 | agenttoggles "github.com/Azure/agentbaker/pkg/agent/toggles" |
@@ -276,6 +280,49 @@ var _ = Describe("AgentBaker API implementation tests", func() { |
276 | 280 | _, err = agentBaker.GetNodeBootstrapping(context.Background(), config) |
277 | 281 | Expect(err).NotTo(HaveOccurred()) |
278 | 282 | }) |
| 283 | + |
| 284 | + It("should include ANC hotfix config file in customData when toggle is set", func() { |
| 285 | + toggles := &testToggles{ |
| 286 | + ancHotfixVersion: "0.1.2", |
| 287 | + } |
| 288 | + agentBaker, err := NewAgentBaker() |
| 289 | + Expect(err).NotTo(HaveOccurred()) |
| 290 | + agentBaker = agentBaker.WithToggles(toggles) |
| 291 | + |
| 292 | + nodeBootStrapping, err := agentBaker.GetNodeBootstrapping(context.Background(), config) |
| 293 | + Expect(err).NotTo(HaveOccurred()) |
| 294 | + |
| 295 | + customData := decodeCustomData(nodeBootStrapping.CustomData) |
| 296 | + Expect(customData).To(ContainSubstring("/opt/azure/containers/aks-node-controller-hotfix.json")) |
| 297 | + Expect(customData).To(ContainSubstring(`{"version":"0.1.2"}`)) |
| 298 | + }) |
| 299 | + |
| 300 | + It("should NOT include ANC hotfix config file in customData when toggle is empty", func() { |
| 301 | + agentBaker, err := NewAgentBaker() |
| 302 | + Expect(err).NotTo(HaveOccurred()) |
| 303 | + |
| 304 | + nodeBootStrapping, err := agentBaker.GetNodeBootstrapping(context.Background(), config) |
| 305 | + Expect(err).NotTo(HaveOccurred()) |
| 306 | + |
| 307 | + customData := decodeCustomData(nodeBootStrapping.CustomData) |
| 308 | + Expect(customData).NotTo(ContainSubstring("aks-node-controller-hotfix.json")) |
| 309 | + }) |
| 310 | + |
| 311 | + It("should NOT include ANC hotfix config file for Windows nodes", func() { |
| 312 | + config.AgentPoolProfile.Distro = datamodel.CustomizedWindowsOSImage |
| 313 | + toggles := &testToggles{ |
| 314 | + ancHotfixVersion: "0.1.2", |
| 315 | + } |
| 316 | + agentBaker, err := NewAgentBaker() |
| 317 | + Expect(err).NotTo(HaveOccurred()) |
| 318 | + agentBaker = agentBaker.WithToggles(toggles) |
| 319 | + |
| 320 | + nodeBootStrapping, err := agentBaker.GetNodeBootstrapping(context.Background(), config) |
| 321 | + Expect(err).NotTo(HaveOccurred()) |
| 322 | + |
| 323 | + // Windows custom data won't contain cloud-init write_files |
| 324 | + Expect(nodeBootStrapping.CustomData).NotTo(ContainSubstring("aks-node-controller-hotfix")) |
| 325 | + }) |
279 | 326 | }) |
280 | 327 |
|
281 | 328 | Context("GetLatestSigImageConfig", func() { |
@@ -506,3 +553,18 @@ var _ = Describe("AgentBaker API implementation tests", func() { |
506 | 553 |
|
507 | 554 | }) |
508 | 555 | }) |
| 556 | + |
| 557 | +// decodeCustomData decodes the base64+gzip encoded customData string back to the raw cloud-init YAML. |
| 558 | +func decodeCustomData(encoded string) string { |
| 559 | + decoded, err := base64.StdEncoding.DecodeString(encoded) |
| 560 | + Expect(err).NotTo(HaveOccurred()) |
| 561 | + reader, err := gzip.NewReader(bytes.NewReader(decoded)) |
| 562 | + if err != nil { |
| 563 | + // not gzipped, return as-is (e.g. Windows) |
| 564 | + return string(decoded) |
| 565 | + } |
| 566 | + defer reader.Close() |
| 567 | + data, err := io.ReadAll(reader) |
| 568 | + Expect(err).NotTo(HaveOccurred()) |
| 569 | + return string(data) |
| 570 | +} |
0 commit comments