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

[do not merge] Default Kubernetes routes to http when the scheme is missing #323

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 6 additions & 5 deletions app/services/integration/kubernetes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def initialize(url, service, port)
tls_options = {
insecureEdgeTerminationPolicy: 'Redirect',
termination: 'edge'
} if uri.class == URI::HTTPS || uri.scheme.blank?
} if uri.class == URI::HTTPS

super({
host: uri.host || uri.path,
Expand Down Expand Up @@ -181,17 +181,18 @@ def build_routes(name, specs = [], owner: get_owner, **metadata)

def build_provider_routes(entry)
data = entry.data
domain, admin_domain = data.values_at('domain', 'admin_domain')
domain = data.fetch('base_url', data.fetch('domain'))
admin_domain = data.fetch('admin_base_url', data.fetch('admin_domain'))
metadata = { labels: labels_for_provider(entry), annotations: annotations_for(entry) }

if admin_domain == domain # master account
build_routes('zync-3scale-master-', [
RouteSpec.new(data.fetch('domain'), 'system-master', 'http')
RouteSpec.new(domain, 'system-master', 'http')
], **metadata)
else
build_routes('zync-3scale-provider-', [
RouteSpec.new(data.fetch('domain'), 'system-developer', 'http'),
RouteSpec.new(data.fetch('admin_domain'), 'system-provider', 'http')
RouteSpec.new(domain, 'system-developer', 'http'),
RouteSpec.new(admin_domain, 'system-provider', 'http')
], **metadata)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/services/kubernetes_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RouteSpec < ActiveSupport::TestCase
assert_equal json, spec.to_hash
end

test 'defaults to https when scheme is missing' do
test 'defaults to http when scheme is missing' do
url = 'my-api.example.com'
service_name = 'My API'
port = 7443
Expand All @@ -103,7 +103,7 @@ class RouteSpec < ActiveSupport::TestCase
host: "my-api.example.com",
port: {targetPort: 7443},
to: {kind: "Service", name: "My API"},
tls: {insecureEdgeTerminationPolicy: "Redirect", termination: "edge"}
tls: nil
}
assert_equal json, spec.to_hash
end
Expand Down