From 435f28e97c5cf8f60ccaf21214aaa4de5574bded Mon Sep 17 00:00:00 2001 From: Nahian Pathan Date: Wed, 23 Feb 2022 15:32:16 -0500 Subject: [PATCH] ztp: revert changes --- .../siteConfig/siteConfigBuilder.go | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/ztp/siteconfig-generator/siteConfig/siteConfigBuilder.go b/ztp/siteconfig-generator/siteConfig/siteConfigBuilder.go index dc2b5980a8..c19b115824 100644 --- a/ztp/siteconfig-generator/siteConfig/siteConfigBuilder.go +++ b/ztp/siteconfig-generator/siteConfig/siteConfigBuilder.go @@ -248,8 +248,14 @@ func (scbuilder *SiteConfigBuilder) getClusterCR(clusterId int, siteConfigTemp S } mapIntf[k] = value } else if reflect.ValueOf(v).Kind() == reflect.String && - strings.HasPrefix(v.(string), "siteconfig.") { - valueIntf, err := siteConfigTemp.GetSiteConfigFieldValue(v.(string), clusterId, nodeId) + strings.HasPrefix(v.(string), "{{") && + strings.HasSuffix(v.(string), "}}") { + // We can be cleaner about this, but this translation is minimally invasive for 4.10: + key, err := translateTemplateKey(v.(string)) + if err != nil { + return nil, err + } + valueIntf, err := siteConfigTemp.GetSiteConfigFieldValue(key, clusterId, nodeId) if err == nil && valueIntf != nil && valueIntf != "" { mapIntf[k] = valueIntf @@ -262,6 +268,20 @@ func (scbuilder *SiteConfigBuilder) getClusterCR(clusterId int, siteConfigTemp S return mapIntf, nil } +func translateTemplateKey(key string) (string, error) { + key = strings.Trim(key, "{ }") + for search, replace := range map[string]string{ + ".Node.": "siteconfig.Spec.Clusters.Nodes.", + ".Cluster.": "siteconfig.Spec.Clusters.", + ".Site.": "siteconfig.Spec.", + } { + if strings.HasPrefix(key, search) { + return strings.Replace(key, search, replace, 1), nil + } + } + return "", fmt.Errorf("Key %q could not be translated", key) +} + func (scbuilder *SiteConfigBuilder) getWorkloadManifest(cpuSet string) (string, interface{}, error) { filePath := scbuilder.scBuilderExtraManifestPath + "/" + workloadPath crio, err := ReadExtraManifestResourceFile(filePath + "/" + workloadCrioFile) @@ -418,4 +438,4 @@ func (scbuilder *SiteConfigBuilder) splitYamls(yamls []byte) ([][]byte, error) { } return resources, nil -} +} \ No newline at end of file