Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit f56af80

Browse files
Teal Stannardweymanfsweinstein22
committed
**V3**: domains show corresponding protocols
- used config yaml propertie 'kubernetes.host_url' to check for istio vs routing release [#169139749] Co-authored-by: Teal Stannard <tstannard@pivotal.io> Co-authored-by: Weyman Fung <wfung@pivotal.io> Co-authored-by: Sarah Weinstein <sweinstein@pivotal.io>
1 parent b595b6c commit f56af80

File tree

8 files changed

+109
-18
lines changed

8 files changed

+109
-18
lines changed

app/presenters/v3/domain_presenter.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def to_hash
2424
name: domain.name,
2525
internal: domain.internal,
2626
router_group: hashified_router_group(domain.router_group_guid),
27+
supported_protocols: protocols,
2728
metadata: {
2829
labels: hashified_labels(domain.labels),
2930
annotations: hashified_annotations(domain.annotations),
@@ -58,6 +59,14 @@ def domain
5859
@resource
5960
end
6061

62+
def protocols
63+
# If Kubernetes is enabled that implies that we are using istio
64+
k8s_enabled = !VCAP::CloudController::Config.config.get(:kubernetes, :host_url).blank?
65+
return ['tcp'] if !k8s_enabled && domain.router_group_guid
66+
67+
return ['http']
68+
end
69+
6170
def hashified_router_group(router_group_guid)
6271
router_group_guid ? { guid: router_group_guid } : nil
6372
end

docs/v3/source/includes/api_resources/_domains.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "test-domain.com",
77
"internal": false,
88
"router_group": null,
9+
"supported_protocols": ["http"],
910
"metadata": {
1011
"labels": <%= metadata.fetch(:labels, {}).to_json(space: ' ', object_nl: ' ')%>,
1112
"annotations": <%= metadata.fetch(:annotations, {}).to_json(space: ' ', object_nl: ' ')%>
@@ -62,6 +63,7 @@
6263
"name": "test-domain.com",
6364
"internal": false,
6465
"router_group": { "guid": "5806148f-cce6-4d86-7fbd-aa269e3f6f3f" },
66+
"supported_protocols": ["tcp"],
6567
"metadata": {
6668
"labels": {},
6769
"annotations": {}

docs/v3/source/includes/resources/domains/_create.md.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Name | Type | Description
4141
| ----------- | -------- | ------------------------------------------------------------------------ | ------- |
4242
| **internal** | _boolean_ | Whether the domain is used for internal (container-to-container) traffic. | false |
4343
| **router_group.guid** | _uuid_ | The desired router group guid. <br>_Note: cannot be used when `internal` is set to `true` or domain is scoped to an org._ | null |
44+
| **supported_protocols** | _list of strings_ | The protocols that are supported by the domain. | |
4445
| **organization** | [_to-one relationship_](#to-one-relationships) | A relationship to the organization the domain will be scoped to. <br>_Note: cannot be used when `internal` is set to `true` or domain is associated with a router group._ | |
4546
| **shared_organizations** | [_to-many relationship_](#to-many-relationships) | A relationship to organizations the domain will be shared with. <br>_Note: cannot be used without an organization relationship_ | |
4647
| **metadata.labels** | [_label object_](#labels) | Labels applied to the domain. | |

docs/v3/source/includes/resources/domains/_object.md.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Example Domain object
1616
| **name** | _string_ | The name of the domain.<br>Must be between 3 ~ 253 characters and follow [RFC 1035](https://tools.ietf.org/html/rfc1035). |
1717
| **internal** | _boolean_ | Whether the domain is used for internal (container-to-container) traffic. |
1818
| **router_group.guid** | _uuid_ | The guid of the desired router group to route TCP traffic through. If set, the domain will only be available for TCP traffic. |
19+
| **supported_protocols** | _list of strings_ | The protocols that are supported by the domain. |
1920
| **organization** | [_to-one relationship_](#to-one-relationships) | The organization the domain is scoped to. If set, the domain will only be available in that organization. Otherwise, the domain will be globally available. |
2021
| **shared_organizations** | [_to-many relationship_](#to-many-relationships) | Organizations the domain is shared with. If set, the domain will be available in these organizations in addition to the organization the domain is scoped to. |
2122
| **links** | [_links object_](#links) | Links to related resources. |

spec/request/domains_spec.rb

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
name: visible_owned_private_domain.name,
7474
internal: false,
7575
router_group: nil,
76+
supported_protocols: ['http'],
7677
metadata: {
7778
labels: {},
7879
annotations: {}
@@ -102,6 +103,7 @@
102103
name: visible_shared_private_domain.name,
103104
internal: false,
104105
router_group: nil,
106+
supported_protocols: ['http'],
105107
metadata: {
106108
labels: {},
107109
annotations: {}
@@ -131,6 +133,7 @@
131133
name: not_visible_private_domain.name,
132134
internal: false,
133135
router_group: nil,
136+
supported_protocols: ['http'],
134137
metadata: {
135138
labels: {},
136139
annotations: {}
@@ -160,6 +163,7 @@
160163
name: shared_domain.name,
161164
internal: false,
162165
router_group: nil,
166+
supported_protocols: ['http'],
163167
metadata: {
164168
labels: {},
165169
annotations: {}
@@ -758,20 +762,21 @@
758762
name: params[:name],
759763
internal: false,
760764
router_group: { guid: 'some-router-guid' },
761-
metadata: {
762-
labels: { key: 'value' },
763-
annotations: { key2: 'value2' }
764-
},
765-
relationships: {
766-
organization: {
767-
data: nil
768-
},
769-
shared_organizations: {
770-
data: []
771-
}
765+
supported_protocols: ['http'],
766+
metadata: {
767+
labels: { key: 'value' },
768+
annotations: { key2: 'value2' }
769+
},
770+
relationships: {
771+
organization: {
772+
data: nil
772773
},
773-
links: {
774-
self: { href: %r(#{Regexp.escape(link_prefix)}/v3/domains/#{UUID_REGEX}) },
774+
shared_organizations: {
775+
data: []
776+
}
777+
},
778+
links: {
779+
self: { href: %r(#{Regexp.escape(link_prefix)}/v3/domains/#{UUID_REGEX}) },
775780
route_reservations: { href: %r(#{Regexp.escape(link_prefix)}/v3/domains/#{UUID_REGEX}/route_reservations) },
776781
router_group: { href: %r(#{Regexp.escape(link_prefix)}/routing/v1/router_groups/some-router-guid) },
777782
}
@@ -849,6 +854,7 @@
849854
name: params[:name],
850855
internal: false,
851856
router_group: nil,
857+
supported_protocols: ['http'],
852858
metadata: {
853859
labels: { key: 'value' },
854860
annotations: { key2: 'value2' }
@@ -1793,6 +1799,7 @@
17931799
name: shared_domain.name,
17941800
internal: false,
17951801
router_group: nil,
1802+
supported_protocols: ['http'],
17961803
metadata: {
17971804
labels: {},
17981805
annotations: {}
@@ -1837,6 +1844,7 @@
18371844
name: private_domain.name,
18381845
internal: false,
18391846
router_group: nil,
1847+
supported_protocols: ['http'],
18401848
metadata: {
18411849
labels: {},
18421850
annotations: {}
@@ -1897,6 +1905,7 @@
18971905
name: private_domain.name,
18981906
internal: false,
18991907
router_group: nil,
1908+
supported_protocols: ['http'],
19001909
metadata: {
19011910
labels: {},
19021911
annotations: {}
@@ -1994,6 +2003,7 @@
19942003
name: domain.name,
19952004
internal: false,
19962005
router_group: nil,
2006+
supported_protocols: ['http'],
19972007
relationships: {
19982008
organization: {
19992009
data: nil
@@ -2046,6 +2056,7 @@
20462056
name: domain.name,
20472057
internal: false,
20482058
router_group: nil,
2059+
supported_protocols: ['http'],
20492060
relationships: {
20502061
organization: {
20512062
data: { guid: org.guid }
@@ -2103,6 +2114,7 @@
21032114
name: domain.name,
21042115
internal: false,
21052116
router_group: nil,
2117+
supported_protocols: ['http'],
21062118
relationships: {
21072119
organization: {
21082120
data: { guid: domain.owning_organization_guid }

spec/request/organizations_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ module VCAP::CloudController
354354
name: shared_domain.name,
355355
internal: false,
356356
router_group: nil,
357+
supported_protocols: ['http'],
357358
metadata: {
358359
labels: {},
359360
annotations: {}
@@ -380,6 +381,7 @@ module VCAP::CloudController
380381
name: owned_private_domain.name,
381382
internal: false,
382383
router_group: nil,
384+
supported_protocols: ['http'],
383385
metadata: {
384386
labels: {},
385387
annotations: {}
@@ -408,6 +410,7 @@ module VCAP::CloudController
408410
name: shared_private_domain.name,
409411
internal: false,
410412
router_group: nil,
413+
supported_protocols: ['http'],
411414
metadata: {
412415
labels: {},
413416
annotations: {}
@@ -768,6 +771,7 @@ module VCAP::CloudController
768771
name: shared_private_domain.name,
769772
internal: false,
770773
router_group: nil,
774+
supported_protocols: ['http'],
771775
metadata: {
772776
labels: {},
773777
annotations: {}
@@ -805,6 +809,7 @@ module VCAP::CloudController
805809
name: shared_domain.name,
806810
internal: false,
807811
router_group: nil,
812+
supported_protocols: ['http'],
808813
metadata: {
809814
labels: {},
810815
annotations: {}

spec/request/routes_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
name: domain1.name,
162162
internal: false,
163163
router_group: nil,
164+
supported_protocols: ['http'],
164165
metadata: {
165166
labels: {},
166167
annotations: {}
@@ -189,6 +190,36 @@
189190
name: domain2.name,
190191
internal: false,
191192
router_group: nil,
193+
supported_protocols: ['http'],
194+
metadata: {
195+
labels: {},
196+
annotations: {}
197+
},
198+
relationships: {
199+
organization: {
200+
data: nil
201+
},
202+
shared_organizations: {
203+
data: []
204+
}
205+
},
206+
links: {
207+
self: { href: "#{link_prefix}/v3/domains/#{domain1.guid}" },
208+
route_reservations: { href: %r(#{Regexp.escape(link_prefix)}\/v3/domains/#{domain1.guid}/route_reservations) }
209+
}
210+
}
211+
end
212+
213+
let(:domain2) { VCAP::CloudController::SharedDomain.make(name: 'second-domain.example.com') }
214+
let(:domain2_json) do
215+
{
216+
guid: domain2.guid,
217+
created_at: iso8601,
218+
updated_at: iso8601,
219+
name: domain2.name,
220+
internal: false,
221+
router_group: nil,
222+
supported_protocols: ['http'],
192223
metadata: {
193224
labels: {},
194225
annotations: {}
@@ -837,6 +868,7 @@
837868
name: domain.name,
838869
internal: false,
839870
router_group: nil,
871+
supported_protocols: ['http'],
840872
metadata: {
841873
labels: {},
842874
annotations: {}

spec/unit/presenters/v3/domain_presenter_spec.rb

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module VCAP::CloudController::Presenters::V3
4141
expect(subject[:updated_at]).to be_a(Time)
4242
expect(subject[:name]).to eq(domain.name)
4343
expect(subject[:internal]).to eq(domain.internal)
44+
expect(subject[:supported_protocols]).to eq(['http'])
4445
expect(subject[:metadata][:labels]).to eq({ 'maine.gov/potato' => 'mashed' })
4546
expect(subject[:metadata][:annotations]).to eq({ 'contacts' => 'Bill tel(1111111) email(bill@fixme), Bob tel(222222) pager(3333333#555) email(bob@fixme)' })
4647
expect(subject[:relationships][:organization][:data]).to be_nil
@@ -85,6 +86,7 @@ module VCAP::CloudController::Presenters::V3
8586
expect(subject[:updated_at]).to be_a(Time)
8687
expect(subject[:name]).to eq(domain.name)
8788
expect(subject[:internal]).to eq(domain.internal)
89+
expect(subject[:supported_protocols]).to eq(['http'])
8890
expect(subject[:metadata][:labels]).to eq({ 'maine.gov/potato' => 'mashed' })
8991
expect(subject[:metadata][:annotations]).to eq({ 'contacts' => 'Bill tel(1111111) email(bill@fixme), Bob tel(222222) pager(3333333#555) email(bob@fixme)' })
9092
expect(subject[:relationships][:organization]).to eq({
@@ -133,6 +135,12 @@ module VCAP::CloudController::Presenters::V3
133135
end
134136

135137
context 'when the domain has a router group' do
138+
before do
139+
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:kubernetes, :host_url).and_return(nil)
140+
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:external_domain).and_return('api2.vcap.me')
141+
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:external_protocol).and_return('https')
142+
end
143+
136144
let(:org) { VCAP::CloudController::Organization.make(guid: 'org') }
137145
let(:domain) do
138146
VCAP::CloudController::PrivateDomain.make(
@@ -164,16 +172,37 @@ module VCAP::CloudController::Presenters::V3
164172
expect(subject[:updated_at]).to be_a(Time)
165173
expect(subject[:name]).to eq(domain.name)
166174
expect(subject[:router_group][:guid]).to eq('some-router-guid')
175+
expect(subject[:supported_protocols]).to eq(['tcp'])
167176
expect(subject[:metadata][:labels]).to eq({ 'maine.gov/potato' => 'mashed' })
168177
expect(subject[:metadata][:annotations]).to eq({ 'contacts' => 'Bill tel(1111111) email(bill@fixme), Bob tel(222222) pager(3333333#555) email(bob@fixme)' })
169178
expect(subject[:relationships][:organization]).to eq({
170179
data: { guid: domain.owning_organization.guid }
171180
})
172-
expect(subject[:links][:self][:href]).to eq("#{link_prefix}/v3/domains/#{domain.guid}")
173-
expect(subject[:links][:organization][:href]).to eq("#{link_prefix}/v3/organizations/#{domain.owning_organization.guid}")
174-
expect(subject[:links][:route_reservations][:href]).to eq("#{link_prefix}/v3/domains/#{domain.guid}/route_reservations")
175-
expect(subject[:links][:router_group][:href]).to eq("#{link_prefix}/routing/v1/router_groups/some-router-guid")
176-
expect(subject[:links][:shared_organizations][:href]).to eq("#{link_prefix}/v3/domains/#{domain.guid}/relationships/shared_organizations")
181+
expect(subject[:links][:self][:href]).to eq("https://api2.vcap.me/v3/domains/#{domain.guid}")
182+
expect(subject[:links][:organization][:href]).to eq("https://api2.vcap.me/v3/organizations/#{domain.owning_organization.guid}")
183+
expect(subject[:links][:route_reservations][:href]).to eq("https://api2.vcap.me/v3/domains/#{domain.guid}/route_reservations")
184+
expect(subject[:links][:router_group][:href]).to eq('https://api2.vcap.me/routing/v1/router_groups/some-router-guid')
185+
expect(subject[:links][:shared_organizations][:href]).to eq("https://api2.vcap.me/v3/domains/#{domain.guid}/relationships/shared_organizations")
186+
end
187+
188+
context 'when the kubernetes host url is blank' do
189+
before do
190+
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:kubernetes, :host_url).and_return('')
191+
end
192+
193+
it 'shows the tcp protocol' do
194+
expect(subject[:supported_protocols]).to eq(['tcp'])
195+
end
196+
end
197+
198+
context 'when the kubernetes section is not set in the config' do
199+
before do
200+
allow(VCAP::CloudController::Config).to receive_message_chain(:config).and_return(VCAP::CloudController::Config.new({}, context: :api))
201+
end
202+
203+
it 'shows the tcp protocol' do
204+
expect(subject[:supported_protocols]).to eq(['tcp'])
205+
end
177206
end
178207

179208
context 'and the routing API is disabled' do

0 commit comments

Comments
 (0)