-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
plural cd services template
(#509)
This will make it a much smoother experience to test .liquid or .tpl files as they are being developed. Should be functionally equivalent to the process done in-agent.
- Loading branch information
1 parent
97979db
commit 9b031ce
Showing
6 changed files
with
158 additions
and
30 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package template | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
console "github.com/pluralsh/console-client-go" | ||
"github.com/pluralsh/polly/template" | ||
) | ||
|
||
func RenderYaml(path string, bindings map[string]interface{}) ([]byte, error) { | ||
content, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if strings.HasSuffix(path, ".tpl") { | ||
return template.RenderTpl(content, bindings) | ||
} | ||
|
||
if strings.HasSuffix(path, ".liquid") { | ||
return template.RenderLiquid(content, bindings) | ||
} | ||
|
||
return content, fmt.Errorf("Not a .liquid or .tpl file") | ||
} | ||
|
||
func RenderService(path string, svc *console.ServiceDeploymentExtended) ([]byte, error) { | ||
bindings := map[string]interface{}{ | ||
"Configuration": configMap(svc), | ||
"Cluster": clusterConfiguration(svc.Cluster), | ||
"Contexts": contexts(svc), | ||
} | ||
|
||
for k, v := range bindings { | ||
bindings[strings.ToLower(k)] = v | ||
} | ||
|
||
return RenderYaml(path, bindings) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package template | ||
|
||
import ( | ||
"strings" | ||
|
||
console "github.com/pluralsh/console-client-go" | ||
) | ||
|
||
func clusterConfiguration(cluster *console.BaseClusterFragment) 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, | ||
"Metadata": cluster.Metadata, | ||
} | ||
|
||
for k, v := range res { | ||
res[strings.ToLower(k)] = v | ||
} | ||
res["kasUrl"] = cluster.KasURL | ||
res["currentVersion"] = cluster.CurrentVersion | ||
|
||
return res | ||
} | ||
|
||
func configMap(svc *console.ServiceDeploymentExtended) map[string]string { | ||
res := map[string]string{} | ||
for _, config := range svc.Configuration { | ||
res[config.Name] = config.Value | ||
} | ||
|
||
return res | ||
} | ||
|
||
func contexts(svc *console.ServiceDeploymentExtended) map[string]map[string]interface{} { | ||
res := map[string]map[string]interface{}{} | ||
for _, context := range svc.Contexts { | ||
res[context.Name] = context.Configuration | ||
} | ||
return res | ||
} |