in pkg/agent/baker.go [1750:1780]
func GenerateLocalDNSCoreFile(
config *datamodel.NodeBootstrappingConfiguration,
profile *datamodel.AgentPoolProfile,
tmpl string,
) (string, error) {
parameters := getParameters(config)
variables := getCustomDataVariables(config)
bakerFuncMap := getBakerFuncMap(config, parameters, variables)
if profile.LocalDNSProfile == nil {
return "", fmt.Errorf("localdns profile is nil")
}
if !profile.ShouldEnableLocalDNS() {
return "", fmt.Errorf("EnableLocalDNS is set to false, corefile will not be generated")
}
funcMapForHasSuffix := template.FuncMap{
"hasSuffix": strings.HasSuffix,
}
localDNSCoreFileData := profile.GetLocalDNSCoreFileData()
localDNSCorefileTemplate := template.Must(template.New("localdnscorefile").Funcs(bakerFuncMap).Funcs(funcMapForHasSuffix).Parse(tmpl))
// Generate the Corefile content.
var corefileBuffer bytes.Buffer
if err := localDNSCorefileTemplate.Execute(&corefileBuffer, localDNSCoreFileData); err != nil {
return "", fmt.Errorf("failed to execute localdns corefile template: %w", err)
}
// Return gzipped base64 encoded Corefile. Used in nodecustomdata.
return getBase64EncodedGzippedCustomScriptFromStr(corefileBuffer.String()), nil
}