From efeca2615a6fc85039c5526cecee64c3cc3d7aa9 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Mon, 18 Mar 2024 05:49:59 -0400 Subject: [PATCH] Fix cluster casing (#145) We were previously just referencing the go struct for a cluster, which bleeds out go's atypical casing for struct keys. This will coerce things to something a bit more typical for end users in templates. --- pkg/manifests/template/raw.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/manifests/template/raw.go b/pkg/manifests/template/raw.go index ae08938e..ccaeb47c 100644 --- a/pkg/manifests/template/raw.go +++ b/pkg/manifests/template/raw.go @@ -60,7 +60,7 @@ func isTemplated(svc *console.GetServiceDeploymentForAgent_ServiceDeployment) bo func renderLiquid(input []byte, svc *console.GetServiceDeploymentForAgent_ServiceDeployment) ([]byte, error) { bindings := map[string]interface{}{ "configuration": configMap(svc), - "cluster": svc.Cluster, + "cluster": clusterConfiguration(svc.Cluster), "contexts": contexts(svc), } return liquidEngine.ParseAndRender(input, bindings) @@ -125,3 +125,23 @@ func (r *raw) Render(svc *console.GetServiceDeploymentForAgent_ServiceDeployment res = newSet.List() return res, nil } + +func clusterConfiguration(cluster *console.GetServiceDeploymentForAgent_ServiceDeployment_Cluster) map[string]interface{} { + res := map[string]interface{}{ + "ID": cluster.ID, + "Self": cluster.Self, + "Handle": cluster.Handle, + "Name": cluster.Name, + "Version": cluster.Version, + "CurrentVersion": cluster.CurrentVersion, + "KasUrl": cluster.KasURL, + } + + for k, v := range res { + res[strings.ToLower(k)] = v + } + res["kasUrl"] = cluster.KasURL + res["currentVersion"] = cluster.CurrentVersion + + return res +}