Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: resolve imports from services #300

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/open-policy-agent/gatekeeper/v3 v3.17.1
github.com/orcaman/concurrent-map/v2 v2.0.1
github.com/pkg/errors v0.9.1
github.com/pluralsh/console/go/client v1.21.0
github.com/pluralsh/console/go/client v1.21.2
github.com/pluralsh/controller-reconcile-helper v0.1.0
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
github.com/pluralsh/polly v0.1.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rK
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pluralsh/console/go/client v1.21.0 h1:l7gltTPY8gR4qhK0RV8WYBP3MdpwJe96AIclTti9Hz0=
github.com/pluralsh/console/go/client v1.21.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
github.com/pluralsh/console/go/client v1.21.2 h1:bYbgporkQx8yDrKARF2tsKh4o15fwtT4yDLTkyPmi9M=
github.com/pluralsh/console/go/client v1.21.2/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
github.com/pluralsh/controller-reconcile-helper v0.1.0 h1:BV3dYZFH5rn8ZvZjtpkACSv/GmLEtRftNQj/Y4ddHEo=
github.com/pluralsh/controller-reconcile-helper v0.1.0/go.mod h1:RxAbvSB4/jkvx616krCdNQXPbpGJXW3J1L3rASxeFOA=
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw=
Expand Down
1 change: 1 addition & 0 deletions pkg/manifests/template/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func renderLiquid(input []byte, svc *console.GetServiceDeploymentForAgent_Servic
"configuration": configMap(svc),
"cluster": clusterConfiguration(svc.Cluster),
"contexts": contexts(svc),
"imports": imports(svc),
}
return template.RenderLiquid(input, bindings)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/manifests/template/tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func renderTpl(input []byte, svc *console.GetServiceDeploymentForAgent_ServiceDe
"Configuration": configMap(svc),
"Cluster": clusterConfiguration(svc.Cluster),
"Contexts": contexts(svc),
"Imports": imports(svc),
}

return template.RenderTpl(input, bindings)
Expand Down
11 changes: 11 additions & 0 deletions pkg/manifests/template/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ func contexts(svc *console.GetServiceDeploymentForAgent_ServiceDeployment) map[s
}
return res
}

func imports(svc *console.GetServiceDeploymentForAgent_ServiceDeployment) map[string]map[string]string {
res := map[string]map[string]string{}
for _, imp := range svc.Imports {
res[imp.Stack.Name] = map[string]string{}
for _, out := range imp.Outputs {
res[imp.Stack.Name][out.Name] = out.Value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output values are always strings currently? We probably should document that when it's time to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the schema the output values are always strings

}
}
return res
}
59 changes: 59 additions & 0 deletions pkg/manifests/template/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package template

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
console "github.com/pluralsh/console/go/client"
"github.com/samber/lo"
)

var _ = Describe("Kustomize template", func() {

svc := &console.GetServiceDeploymentForAgent_ServiceDeployment{
Namespace: "default",
Kustomize: &console.GetServiceDeploymentForAgent_ServiceDeployment_Kustomize{
Path: "",
},
Imports: []*console.GetServiceDeploymentForAgent_ServiceDeployment_Imports{
{
ID: "1",
Stack: &console.GetServiceDeploymentForAgent_ServiceDeployment_Imports_Stack{
ID: lo.ToPtr("1"),
Name: "1",
},
Outputs: []*console.GetServiceDeploymentForAgent_ServiceDeployment_Imports_Outputs{
{
Name: "ansible_instance_ids",
Value: "[\"i-05066719bbd2ea672\",\"i-0810e18d30b5cd564\",\"i-0c2a356e403cd67ec\"]",
},
{
Name: "ansible_key_pair_name",
Value: "ansible-ssh-key",
},
},
},
{
ID: "2",
Stack: &console.GetServiceDeploymentForAgent_ServiceDeployment_Imports_Stack{
ID: lo.ToPtr("2"),
Name: "2",
},
Outputs: []*console.GetServiceDeploymentForAgent_ServiceDeployment_Imports_Outputs{
{
Name: "stacks_iam_role",
Value: "arn:aws:iam::312272277431:role/boot-test-plrl-stacks",
},
},
},
},
}
Context("Render imports", func() {
It("should successfully render the imports", func() {
resp := imports(svc)
Expect(len(resp)).To(Equal(2))
Expect(len(resp["1"])).To(Equal(2))
Expect(len(resp["2"])).To(Equal(1))
})

})
})
Loading