Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Distinguish names, refs, and canonical forms
Browse files Browse the repository at this point in the history
An image name (e.g., "alpine") is used for different things than an
image ref (e.g., "alpine:3.5"). So, be clear about which we're using.

For some purposes we want to use the canonical form of an image name
or ref; so, make those distinct types as well.
  • Loading branch information
squaremo committed Oct 27, 2017
1 parent 40ac8e7 commit 3764145
Show file tree
Hide file tree
Showing 28 changed files with 292 additions and 231 deletions.
4 changes: 2 additions & 2 deletions cluster/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ func mergeCredentials(c *Cluster, namespace string, podTemplate apiv1.PodTemplat

// Now create the service and attach the credentials
for _, container := range podTemplate.Spec.Containers {
r, err := flux.ParseImageID(container.Image)
r, err := flux.ParseImageRef(container.Image)
if err != nil {
c.logger.Log("err", err.Error())
continue
}
imageCreds[r] = creds
imageCreds[r.Name()] = creds
}
}

Expand Down
2 changes: 1 addition & 1 deletion cluster/kubernetes/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (c *Manifests) ParseManifests(allDefs []byte) (map[string]resource.Resource
return kresource.ParseMultidoc(allDefs, "exported")
}

func (c *Manifests) UpdateDefinition(def []byte, container string, image flux.ImageID) ([]byte, error) {
func (c *Manifests) UpdateDefinition(def []byte, container string, image flux.ImageRef) ([]byte, error) {
return updatePodController(def, container, image)
}

Expand Down
6 changes: 3 additions & 3 deletions cluster/kubernetes/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
//
// This function has many additional requirements that are likely in flux. Read
// the source to learn about them.
func updatePodController(def []byte, container string, newImageID flux.ImageID) ([]byte, error) {
func updatePodController(def []byte, container string, newImageID flux.ImageRef) ([]byte, error) {
// Sanity check
obj, err := definitionObj(def)
if err != nil {
Expand Down Expand Up @@ -77,7 +77,7 @@ func updatePodController(def []byte, container string, newImageID flux.ImageID)
// ports:
// - containerPort: 80
// ```
func tryUpdate(def []byte, container string, newImage flux.ImageID, out io.Writer) error {
func tryUpdate(def []byte, container string, newImage flux.ImageRef, out io.Writer) error {
manifest, err := parseManifest(def)
if err != nil {
return err
Expand All @@ -95,7 +95,7 @@ func tryUpdate(def []byte, container string, newImage flux.ImageID, out io.Write
if c.Name != container {
continue
}
currentImage, err := flux.ParseImageID(c.Image)
currentImage, err := flux.ParseImageRef(c.Image)
if err != nil {
return fmt.Errorf("could not parse image %s", c.Image)
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/kubernetes/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type update struct {
}

func testUpdate(t *testing.T, u update) {
id, err := flux.ParseImageID(u.updatedImage)
id, err := flux.ParseImageRef(u.updatedImage)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Manifests interface {
FindDefinedServices(path string) (map[flux.ResourceID][]string, error)
// Update the definitions in a manifests bytes according to the
// spec given.
UpdateDefinition(def []byte, container string, newImageID flux.ImageID) ([]byte, error)
UpdateDefinition(def []byte, container string, newImageID flux.ImageRef) ([]byte, error)
// Load all the resource manifests under the path given
LoadManifests(paths ...string) (map[string]resource.Resource, error)
// Parse the manifests given in an exported blob
Expand Down
4 changes: 2 additions & 2 deletions cluster/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Mock struct {
SyncFunc func(SyncDef) error
PublicSSHKeyFunc func(regenerate bool) (ssh.PublicKey, error)
FindDefinedServicesFunc func(path string) (map[flux.ResourceID][]string, error)
UpdateDefinitionFunc func(def []byte, container string, newImageID flux.ImageID) ([]byte, error)
UpdateDefinitionFunc func(def []byte, container string, newImageID flux.ImageRef) ([]byte, error)
LoadManifestsFunc func(paths ...string) (map[string]resource.Resource, error)
ParseManifestsFunc func([]byte) (map[string]resource.Resource, error)
UpdateManifestFunc func(path, resourceID string, f func(def []byte) ([]byte, error)) error
Expand Down Expand Up @@ -52,7 +52,7 @@ func (m *Mock) FindDefinedServices(path string) (map[flux.ResourceID][]string, e
return m.FindDefinedServicesFunc(path)
}

func (m *Mock) UpdateDefinition(def []byte, container string, newImageID flux.ImageID) ([]byte, error) {
func (m *Mock) UpdateDefinition(def []byte, container string, newImageID flux.ImageRef) ([]byte, error) {
return m.UpdateDefinitionFunc(def, container, newImageID)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxsvc/fluxsvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func setup(t *testing.T) {
t.Fatal(err)
}

imageID, _ := flux.ParseImageID("quay.io/weaveworks/helloworld:v1")
imageID, _ := flux.ParseImageRef("quay.io/weaveworks/helloworld:v1")
mockPlatform = &remote.MockPlatform{
ListServicesAnswer: []flux.ControllerStatus{
flux.ControllerStatus{
Expand Down
4 changes: 2 additions & 2 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (d *Daemon) LogEvent(ev event.Event) error {
func containers2containers(cs []cluster.Container) []flux.Container {
res := make([]flux.Container, len(cs))
for i, c := range cs {
id, _ := flux.ParseImageID(c.Image)
id, _ := flux.ParseImageRef(c.Image)
res[i] = flux.Container{
Name: c.Name,
Current: flux.Image{
Expand All @@ -430,7 +430,7 @@ func containers2containers(cs []cluster.Container) []flux.Container {

func containersWithAvailable(service cluster.Controller, images update.ImageMap) (res []flux.Container) {
for _, c := range service.ContainersOrNil() {
id, _ := flux.ParseImageID(c.Image)
id, _ := flux.ParseImageRef(c.Image)
repo := id.CanonicalName()
available := images[repo]
res = append(res, flux.Container{
Expand Down
4 changes: 2 additions & 2 deletions daemon/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func (d *Daemon) pollForNewImages(logger log.Logger) {
for _, container := range service.ContainersOrNil() {
logger := log.With(logger, "service", service.ID, "container", container.Name, "currentimage", container.Image)

currentImageID, err := flux.ParseImageID(container.Image)
currentImageID, err := flux.ParseImageRef(container.Image)
if err != nil {
logger.Log("error", err)
continue
}

pattern := getTagPattern(candidateServices, service.ID, container.Name)
repo := currentImageID.CanonicalName()
repo := currentImageID.Name()
logger.Log("repo", repo, "pattern", pattern)

if latest := imageMap.LatestImage(repo, pattern); latest != nil && latest.ID != currentImageID {
Expand Down
Loading

0 comments on commit 3764145

Please sign in to comment.