Skip to content

Commit

Permalink
Fixes #27418 - Support docker pull with pulp3
Browse files Browse the repository at this point in the history
This supports docker pull with pulp3. Crane (pulp2) is still supported and the
registry URL is dynamically determined based on the support for Docker blobs.

Previously, the RegistryResource class would run code when loaded, setting up
the inherited class variables. This commit moves this and the new logic to a class
method. Since there are now backend calls (to check for pulp3) to set up the class
variables, it seems like this should be a more deliberate action. This also makes testing
much easier.

I'm open to other suggestions on how to handle the class inheritance and the class variables.

To test:
- Modify foreman/config/settings.plugins.d/katello.yaml, adding the pulp_registry_url
```yaml
  :container_image_registry:
    :crane_url: https://localhost:5000
    :pulp_registry_url: http://localhost:24816
    :registry_ca_cert_file: /etc/pki/katello/certs/katello-default-ca.crt
```
- Set up docker on pulp3 box. You will need an up-to-date box since pulp/pulp_docker#391 was merged
- Sync repos, you can use https://cloud.docker.com/u/jomitsch/repository/docker/jomitsch/workflow-test for a small one.
- docker login $HOSTNAME
- docker pull $HOSTNAME/default_organization-docker-workflow_test (check name in docker repo details)
- docker pull should be successful

It's worth trying out some other repos or registries (like quay.io) and also we should ensure pulp2 functionality is not expected

There will be installer changes to come that will update both dev and prod's katello.yml, these will need to be merged along
with this PR

I also updated the rubocop_todo as it was throwing warnings for duplicate entries.
  • Loading branch information
John Mitsch committed Aug 7, 2019
1 parent d67e4ab commit 8226770
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 14

# Offense count: 875
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 200

# Offense count: 23
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Expand Down
34 changes: 25 additions & 9 deletions app/lib/katello/resources/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,38 @@ def self.logger

def self.get(path, headers = {:accept => :json})
logger.debug "Sending GET request to Registry: #{path}"
client = RegistryResource.rest_client(Net::HTTP::Get, :get, path)
client = RegistryResource.load_class.rest_client(Net::HTTP::Get, :get, path)
client.get(headers)
end
end

class RegistryResource < HttpResource
if SETTINGS[:katello][:container_image_registry]
cfg = SETTINGS[:katello][:container_image_registry]
url = cfg[:crane_url]
uri = URI.parse(url)
self.prefix = uri.path
self.site = "#{uri.scheme}://#{uri.host}:#{uri.port}"
self.ca_cert_file = cfg[:crane_ca_cert_file]
end
extend Concerns::SmartProxyExtensions

class << self
def load_class
container_config = SETTINGS.dig(:katello, :container_image_registry)
registry_url = nil

if container_config
crane_url = container_config[:crane_url]
pulp_registry_url = container_config[:pulp_registry_url]
registry_url = crane_url if crane_url
# pulp 3 acts as its own registry
if pulp_registry_url && content_pulp3_support?(::Katello::DockerBlob::CONTENT_TYPE)
registry_url = pulp_registry_url
end
end

logger.send(:error, "No container registry url specified") unless registry_url

uri = URI.parse(registry_url)
self.prefix = uri.path
self.site = "#{uri.scheme}://#{uri.host}:#{uri.port}"
self.ca_cert_file = container_config[:registry_ca_cert_file]
self
end

def process_response(response)
debug_level = response.code >= 400 ? :error : :debug
logger.send(debug_level, "Registry request returned with code #{response.code}")
Expand Down
26 changes: 26 additions & 0 deletions test/lib/resources/registry_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'katello_test_helper'

module Katello
module Resources
class RegistryTest < ActiveSupport::TestCase
before do
SETTINGS[:katello][:container_image_registry] = {
crane_url: "https://localhost:5000",
pulp_registry_url: "http://localhost:24816"
}
end

def test_pulp3_registry_url
Registry::RegistryResource.expects(:content_pulp3_support?).returns(true)
pulp_registry_url = SETTINGS[:katello][:container_image_registry][:pulp_registry_url]
assert_equal Registry::RegistryResource.load_class.site, pulp_registry_url
end

def test_crane_registry_url
Registry::RegistryResource.expects(:content_pulp3_support?).returns(false)
crane_url = SETTINGS[:katello][:container_image_registry][:crane_url]
assert_equal Registry::RegistryResource.load_class.site, crane_url
end
end
end
end

0 comments on commit 8226770

Please sign in to comment.