Skip to content

Commit

Permalink
ztp: revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelsoccupied committed Feb 23, 2022
1 parent 378573d commit 6899c60
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions ztp/siteconfig-generator/siteConfig/siteConfigBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,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
Expand All @@ -256,6 +262,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)
Expand Down Expand Up @@ -412,4 +432,4 @@ func (scbuilder *SiteConfigBuilder) splitYamls(yamls []byte) ([][]byte, error) {
}

return resources, nil
}
}

0 comments on commit 6899c60

Please sign in to comment.