Skip to content

Commit

Permalink
Merge pull request #911 from Ace-Tang/add_hub_ns
Browse files Browse the repository at this point in the history
feature: add default registry namespace
  • Loading branch information
HusterWan authored Mar 21, 2018
2 parents b1053a7 + 1c9822c commit 92579c3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type Config struct {
// DefaultRegistry is daemon's default registry which is to pull/push/search images.
DefaultRegistry string

// DefaultRegistryNS is daemon's default registry namespace used in pull/push/search images.
DefaultRegistryNS string

// Home directory.
HomeDir string `json:"home-dir,omitempty"`

Expand Down
14 changes: 7 additions & 7 deletions daemon/mgr/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ type ImageMgr interface {
type ImageManager struct {
// DefaultRegistry is the default registry of daemon.
// When users do not specify image repo in image name,
// daemon will automatically pull images from DefaultRegistry.
// daemon will automatically pull images with DefaultRegistry and DefaultNamespace.
DefaultRegistry string
// DefaultNamespace is the default namespace used in DefaultRegistry.
DefaultNamespace string

// client is a pointer to the containerd client.
// It is used to interact with containerd.
Expand All @@ -57,13 +59,11 @@ type ImageManager struct {

// NewImageManager initializes a brand new image manager.
func NewImageManager(cfg *config.Config, client *ctrd.Client) (*ImageManager, error) {
if !strings.HasSuffix(cfg.DefaultRegistry, "/") {
cfg.DefaultRegistry += "/"
}
mgr := &ImageManager{
DefaultRegistry: cfg.DefaultRegistry,
client: client,
cache: newImageCache(),
DefaultRegistry: cfg.DefaultRegistry,
DefaultNamespace: cfg.DefaultRegistryNS,
client: client,
cache: newImageCache(),
}

if err := mgr.loadImages(); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion daemon/mgr/image_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mgr

import (
"path/filepath"
"regexp"
"strings"

Expand All @@ -19,7 +20,7 @@ func (mgr *ImageManager) addRegistry(input string) string {
if _, ok := reference.Domain(input); ok {
return input
}
return mgr.DefaultRegistry + input
return filepath.Join(mgr.DefaultRegistry, mgr.DefaultNamespace, input)
}

// isNumericID checks whether input is numeric ID
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func setupFlags(cmd *cobra.Command) {
flagSet.BoolVar(&cfg.IsLxcfsEnabled, "enable-lxcfs", false, "Enable Lxcfs to make container to isolate /proc")
flagSet.StringVar(&cfg.LxcfsBinPath, "lxcfs", "/usr/local/bin/lxcfs", "Specify the path of lxcfs binary")
flagSet.StringVar(&cfg.LxcfsHome, "lxcfs-home", "/var/lib/lxc/lxcfs", "Specify the mount dir of lxcfs")
flagSet.StringVar(&cfg.DefaultRegistry, "default-registry", "registry.hub.docker.com/library/", "Default Image Registry")
flagSet.StringVar(&cfg.DefaultRegistry, "default-registry", "registry.hub.docker.com", "Default Image Registry")
flagSet.StringVar(&cfg.DefaultRegistryNS, "default-registry-namespace", "library", "Default Image Registry namespace")
flagSet.StringVar(&cfg.ImageProxy, "image-proxy", "", "Http proxy to pull image")
flagSet.StringVar(&cfg.QuotaDriver, "quota-driver", "", "Set quota driver(grpquota/prjquota), if not set, it will set by kernel version")
flagSet.StringVar(&cfg.ConfigFile, "config-file", "/etc/pouch/config.json", "Configuration file of pouchd")
Expand Down
3 changes: 2 additions & 1 deletion pkg/reference/def.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reference

// Reference represents image name which may include domain/name:tag or only digest.
// Reference represents image name which may include hub/namespace/name:tag
// like registry.hub.docker.com/library/ubuntu or only digest.
type Reference interface {
String() string
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/reference/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func WithDefaultTagIfMissing(named Named) Named {
return named
}

// Domain retrieves domain information.
// Domain retrieves domain information. Domain include registry address and
// repository namespace, like registry.hub.docker.com/library/ubuntu.
func Domain(named string) (string, bool) {
i := strings.IndexRune(named, '/')
i := strings.LastIndexByte(named, '/')

// FIXME: The domain should contain the . or :, how to handle the case
// which image name contains . or :?
Expand Down
2 changes: 1 addition & 1 deletion pkg/reference/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDomain(t *testing.T) {
{
name: "Normal",
input: "docker.io/library/nginx:alpine",
domain: "docker.io",
domain: "docker.io/library",
ok: true,
}, {
name: "IP Registry",
Expand Down

0 comments on commit 92579c3

Please sign in to comment.