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

Fixes #38028 - Update smart proxy URI methods for load balancer setups #11229

Merged
merged 2 commits into from
Dec 5, 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
14 changes: 11 additions & 3 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ def alternate_content_sources
SmartProxy.joins(:smart_proxy_alternate_content_sources).where('katello_smart_proxy_alternate_content_sources.smart_proxy_id' => self.id)
end

def registration_host
def registration_url
url = self.setting('Registration', 'registration_url').presence || self.url
URI.parse(url).host
URI(url)
Comment on lines +134 to +136
Copy link
Member Author

Choose a reason for hiding this comment

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

I added the bare registration_url method here so that Foreman can do things to the URI object it returns, directly (e.g. using its path and port).

end

def registration_host
registration_url.host
end

def load_balanced?
Expand Down Expand Up @@ -598,12 +602,16 @@ def pulp_content_url
URI(setting(SmartProxy::PULP3_FEATURE, 'content_app_url'))
end

def load_balancer_pulp_content_url
URI::HTTPS.build(host: registration_url.host, path: pulp_content_url.path)
end
Comment on lines 602 to +607
Copy link
Member Author

Choose a reason for hiding this comment

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

hopefully setting(SmartProxy::PULP3_FEATURE, 'content_app_url') doesn't contain any crucial information that would be lost by only using its path.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ianballou Would this url be different for a smart proxy that uses an external Pulp? Is that setup supported with load balanced smart proxies?

Copy link
Member

Choose a reason for hiding this comment

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

We should be able to rely on the path always being /pulp/content


def audit_capsule_sync
write_audit(action: "sync capsule", comment: _('Successfully synced capsule.'), audited_changes: {})
end

class ::SmartProxy::Jail < ::Safemode::Jail
allow :rhsm_url, :pulp_content_url
allow :rhsm_url, :pulp_content_url, :load_balancer_pulp_content_url, :registration_url
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/katello/api/v2/content_facet/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ node :lifecycle_environment do |content_facet|
end

child :content_source => :content_source do
attributes :id, :name, :url
attributes :id, :name, :url, :registration_host
node(:load_balanced) { |content_source| content_source.load_balanced? }
end

child :kickstart_repository => :kickstart_repository do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { translate as __ } from 'foremanReact/common/I18n';
import {
DescriptionList,
Expand Down Expand Up @@ -55,12 +56,14 @@ const RegistrationCard = ({ isExpandedGlobal, hostDetails }) => {
const subscriptionFacetAttributes
= propsToCamelCase(hostDetails?.subscription_facet_attributes || {});
const {
registeredAt, activationKeys, user,
registeredAt, registeredThrough, activationKeys, user,
}
= subscriptionFacetAttributes;
const contentFacetAttributes
= propsToCamelCase(hostDetails?.content_facet_attributes || {});
const { contentSourceName } = contentFacetAttributes;
const { contentSource } = propsToCamelCase(contentFacetAttributes || {});
const { loadBalanced, registrationHost } = propsToCamelCase(contentSource || {});
const login = user?.login;
if (!registeredAt) return null;
return (
Expand All @@ -79,9 +82,32 @@ const RegistrationCard = ({ isExpandedGlobal, hostDetails }) => {
<DescriptionListTerm>{__('Registered by')}</DescriptionListTerm>
<RegisteredBy user={login} activationKeys={activationKeys} />
</DescriptionListGroup>
<DescriptionListGroup>
<DescriptionListTerm>{__('Registered to')}</DescriptionListTerm>
<DescriptionListDescription>{registeredThrough}</DescriptionListDescription>
</DescriptionListGroup>
{loadBalanced && (
<DescriptionListGroup>
<DescriptionListTerm>{__('Load balancer')}</DescriptionListTerm>
<DescriptionListDescription>{registrationHost}</DescriptionListDescription>
</DescriptionListGroup>
)}
<DescriptionListGroup>
<DescriptionListTerm>{__('Content source')}</DescriptionListTerm>
<DescriptionListDescription>{contentSourceName}</DescriptionListDescription>
{!loadBalanced && (
<DescriptionListDescription>{contentSourceName}</DescriptionListDescription>
)}
{loadBalanced && (
<DescriptionListDescription>
<FormattedMessage
id="load-balancer-content-source-text"
defaultMessage={__('Content may come from {contentSourceName} or any other Smart Proxy behind the load balancer.')}
values={{
contentSourceName: <strong>{contentSourceName}</strong>,
}}
/>
</DescriptionListDescription>
)}
</DescriptionListGroup>
</DescriptionList>
</CardTemplate>
Expand Down
Loading