Skip to content

Commit a102504

Browse files
DevinwongCopilot
andcommitted
agent: plumb ANC hotfix version from toggle to cloud-init
Add server-side support for delivering aks-node-controller hotfix version to nodes via cloud-init write_files: - Add GetANCHotfixVersion() to Toggles interface + default impl - Add ANCHotfixVersion field to NodeBootstrappingConfiguration - Resolve toggle BEFORE template rendering in GetNodeBootstrapping - Add GetANCHotfixVersion template function in baker.go - Add conditional write_files entry in nodecustomdata.yml that writes /opt/azure/containers/aks-node-controller-hotfix.json when set - Update test mock to satisfy new interface method The hotfix JSON file is consumed by ANC selfUpdate() (PR #8257) which reads it at startup to determine if a PMC package upgrade is needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 66e839a commit a102504

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

pkg/agent/bakerapi_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package agent
22

33
import (
4+
"bytes"
5+
"compress/gzip"
46
"context"
7+
"encoding/base64"
8+
"io"
59

610
"github.com/Azure/agentbaker/pkg/agent/datamodel"
711
agenttoggles "github.com/Azure/agentbaker/pkg/agent/toggles"
@@ -276,6 +280,49 @@ var _ = Describe("AgentBaker API implementation tests", func() {
276280
_, err = agentBaker.GetNodeBootstrapping(context.Background(), config)
277281
Expect(err).NotTo(HaveOccurred())
278282
})
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+
})
279326
})
280327

281328
Context("GetLatestSigImageConfig", func() {
@@ -506,3 +553,18 @@ var _ = Describe("AgentBaker API implementation tests", func() {
506553

507554
})
508555
})
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

Comments
 (0)