-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to set a mirror for the default SUSE registry.
This feature is only applicable for SLE15 based CaaSP installations, as those will no longer use container-feeder, but download the docker images from a registry instead. By default this registry will be the official suse registry (registry.suse.com), but the customer always has the possibility to mirror it, in which case he can then set this mirror during installation. This mirror will then be used a fallback, if the official registry can not be reached.
- Loading branch information
Florian Bergmann
committed
Dec 11, 2018
1 parent
598bdde
commit 2bc26b6
Showing
8 changed files
with
266 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "json" | ||
require "yaml" | ||
|
||
module Y2Caasp | ||
module CFA | ||
# Represents a Salt Minion master configuration file. | ||
# | ||
# Does not use CFA, as the Augeas JSON module seems terribly complex for | ||
# this use case. | ||
class MirrorConf | ||
attr_accessor :data | ||
DOCKER_CONF_DIR = "/etc/docker/".freeze | ||
PATH = "#{DOCKER_CONF_DIR}daemon.json".freeze | ||
|
||
def initialize | ||
@data = if File.exist?(PATH) | ||
JSON.load(File.read(PATH)) | ||
else | ||
{ "iptables".freeze => false, | ||
"log-level".freeze => "warn" } | ||
end | ||
end | ||
|
||
def mirror_url=(mirror_url) | ||
registries_data = [{ "Mirrors" => [{ "URL" => mirror_url }], | ||
"Prefix" => "https://registry.suse.com" }] | ||
if @data["registrries"].nil? | ||
@data["registries"] = registries_data | ||
else | ||
existing = @data["registries"][0] | ||
existing.merge(registries_data[0]) | ||
@data["registries"] = [existing] | ||
end | ||
end | ||
|
||
def save | ||
inst_conf_dir = File.join(Yast::Installation.destdir, DOCKER_CONF_DIR) | ||
inst_path = File.join(Yast::Installation.destdir, PATH) | ||
::FileUtils.mkdir_p(inst_conf_dir) unless File.exist?(inst_conf_dir) | ||
File.open(inst_path, "w") { |file| file.write(@data.to_json) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "json" | ||
require "yaml" | ||
|
||
module Y2Caasp | ||
module CFA | ||
# Represents a Salt Minion master configuration file. | ||
|
||
# This class stores the mirror configuration in a yaml file for use in | ||
# Velum. This file is required, as Velum needs to copy these mirrors into | ||
# the database, so they can be distributed throughout the cluster, but the | ||
# CaaSP team doesn't want to be bound to the docker specific configuration | ||
# file | ||
class MirrorConfYaml | ||
DOCKER_CONF_DIR = "/etc/docker/".freeze | ||
# The docker file will be read from the installed system, so it should have | ||
# been configured before calling this configuration module. | ||
DOCKER_CONF_PATH = File.join(Yast::Installation.destdir, | ||
"#{DOCKER_CONF_DIR}daemon.json".freeze) | ||
PATH = "#{DOCKER_CONF_DIR}mirrors.yaml".freeze | ||
|
||
# This class needs to be initialized with a valid docker config | ||
# (MirrorConf.data) that contains a configured mirror | ||
def initialize | ||
@data = if File.exist?(DOCKER_CONF_PATH) | ||
JSON.load(File.read(DOCKER_CONF_PATH)) | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def as_yaml | ||
return "" if @data["registries"].nil? || @data["registries"][0].nil? | ||
yaml_data = { | ||
"SUSE registry" => { | ||
"url" => @data["registries"][0]["Prefix"], | ||
"mirrors" => { | ||
"YaST Mirror" => { | ||
"url" => @data["registries"][0]["Mirrors"][0]["URL"] | ||
} | ||
} | ||
} | ||
} | ||
yaml_data.to_yaml | ||
end | ||
|
||
def save | ||
inst_conf_dir = File.join(Yast::Installation.destdir, DOCKER_CONF_DIR) | ||
inst_path = File.join(Yast::Installation.destdir, PATH) | ||
::FileUtils.mkdir_p(inst_conf_dir) unless File.exist?(inst_conf_dir) | ||
File.open(inst_path, "w") { |file| file.write(as_yaml) } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# encoding: utf-8 | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2018 SUSE LLC | ||
# | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, contact SUSE. | ||
# | ||
# To contact SUSE about this file by physical or electronic mail, you may find | ||
# current contact information at www.suse.com. | ||
# ------------------------------------------------------------------------------ | ||
|
||
require "yast" | ||
require "cwm/widget" | ||
require "installation/system_role" | ||
|
||
module Y2Caasp | ||
module Widgets | ||
# This widget is responsible to validate and store the registry host. | ||
# The host must be a valid IP of FQDN. | ||
class ContainerRegistryMirror < CWM::InputField | ||
attr_reader :default_host | ||
|
||
def initialize(default_host = "") | ||
@default_host = default_host | ||
textdomain "caasp" | ||
end | ||
|
||
def label | ||
_("Container registry mirror") | ||
end | ||
|
||
def help | ||
# TRANSLATORS: a help text for the controller node input field | ||
_("<h3>The Container Registry Mirror</h3>") + | ||
# TRANSLATORS: a help text for the controller node input field | ||
_("<p>Enter the host, that runs the registry mirror." \ | ||
"It must have all container-images required to run CaaS Platform available.</p>") | ||
end | ||
|
||
# It stores the value of the input field if validates | ||
# | ||
# @see #validate | ||
def store | ||
# this is a role widget so a role must be selected before saving | ||
raise("No role selected") unless role | ||
role["registry_mirror"] = value | ||
end | ||
|
||
# The input field is initialized with previous stored value | ||
def init | ||
self.value = if role && role["registry_mirror"] | ||
role["registry_mirror"] | ||
else | ||
@default_host | ||
end | ||
end | ||
|
||
# It returns true if the value is a valid IP or a valid FQDN, if not it | ||
# displays a popup error. | ||
# | ||
# @return [Boolean] true if valid IP or FQDN | ||
def validate | ||
return true if Yast::IP.Check(value) || Yast::Hostname.CheckFQ(value) | ||
|
||
Yast::Popup.Error( | ||
# TRANSLATORS: error message for invalid administration node location | ||
_("Not a valid location for the mirror, please enter a valid IP or Hostname") | ||
) | ||
|
||
false | ||
end | ||
|
||
private | ||
|
||
# All other widgets have this | ||
def role | ||
::Installation::SystemRole.current_role | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"registries": [ | ||
{ | ||
"Mirrors": [ | ||
{ | ||
"URL": "https://registry.suse.com/" | ||
} | ||
], | ||
"Prefix": "https://none.none" | ||
} | ||
], | ||
"iptables":false, | ||
"log-level": "warn" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file defines whether to use container-feeder packaged images or a | ||
# registry. | ||
# | ||
# If use_registry is set to false, the system should use container-feeder images | ||
# and ignore the host and namespace. | ||
# | ||
# namespace: denotes the root namespace under which all images can be found. | ||
use_registry: false | ||
host: registry.suse.de | ||
namespace: devel/casp/3.0/controllernode/images_container_base/sles12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters