Skip to content

Commit c9c1f00

Browse files
author
Kenneth Rosario
authored
Dedupe urls when creating vcap application env var as well (#965)
1 parent 72726b3 commit c9c1f00

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pkg/kf/cfutil/vcapapp.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cfutil
1616

1717
import (
1818
v1alpha1 "github.com/google/kf/v2/pkg/apis/kf/v1alpha1"
19+
"k8s.io/apimachinery/pkg/util/sets"
1920
)
2021

2122
const (
@@ -30,9 +31,9 @@ func CreateVcapApplication(app *v1alpha1.App) map[string]interface{} {
3031
// You can find a list of values here:
3132
// https://docs.run.pivotal.io/devguide/deploy-apps/environment-variable.html
3233

33-
urls := []string{}
34+
urls := sets.NewString()
3435
for _, r := range app.Status.Routes {
35-
urls = append(urls, r.URL)
36+
urls.Insert(r.URL)
3637
}
3738

3839
values := map[string]interface{}{
@@ -41,7 +42,7 @@ func CreateVcapApplication(app *v1alpha1.App) map[string]interface{} {
4142
// application_name The name assigned to the app when it was pushed.
4243
"application_name": app.Name,
4344
// application_uris The URIs assigned to the app.
44-
"application_uris": urls,
45+
"application_uris": urls.List(),
4546
// name Identical to application_name.
4647
"name": app.Name,
4748
// process_id The UID identifying the process. Only present in running app containers.
@@ -51,7 +52,7 @@ func CreateVcapApplication(app *v1alpha1.App) map[string]interface{} {
5152
// space_name Human-readable name of the space where the app is deployed.
5253
"space_name": app.Namespace,
5354
// uris Identical to application_uris.
54-
"uris": urls,
55+
"uris": urls.List(),
5556
}
5657

5758
return values

pkg/kf/cfutil/vcapapp_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ func ExampleCreateVcapApplication() {
2626
app.Name = "my-app"
2727
app.Namespace = "my-ns"
2828
app.UID = "12345"
29-
app.Status.Routes = []v1alpha1.AppRouteStatus{{URL: "app.example.com"}}
29+
app.Status.Routes = []v1alpha1.AppRouteStatus{
30+
{URL: "app.example.com", Status: v1alpha1.RouteBindingStatusOrphaned},
31+
{URL: "app.example.com", Status: v1alpha1.RouteBindingStatusUnknown},
32+
}
3033

3134
envMap := cfutil.CreateVcapApplication(app)
3235

0 commit comments

Comments
 (0)