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

Distinguish names, refs, and canonical forms #817

Merged
merged 2 commits into from
Oct 31, 2017
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
5 changes: 3 additions & 2 deletions cluster/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/cluster"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/registry"
"github.com/weaveworks/flux/ssh"
)
Expand Down Expand Up @@ -350,12 +351,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 := image.ParseRef(container.Image)
if err != nil {
c.logger.Log("err", err.Error())
continue
}
imageCreds[r] = creds
imageCreds[r.Name] = creds
}
}

Expand Down
4 changes: 2 additions & 2 deletions cluster/kubernetes/manifests.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kubernetes

import (
"github.com/weaveworks/flux"
kresource "github.com/weaveworks/flux/cluster/kubernetes/resource"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/resource"
)

Expand All @@ -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 image.Ref) ([]byte, error) {
return updatePodController(def, container, image)
}

Expand Down
8 changes: 4 additions & 4 deletions cluster/kubernetes/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"regexp"
"strings"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/image"
)

// updatePodController takes the body of a Deployment resource definition
Expand All @@ -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 image.Ref) ([]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 image.Ref, 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 := image.ParseRef(c.Image)
if err != nil {
return fmt.Errorf("could not parse image %s", c.Image)
}
Expand Down
4 changes: 2 additions & 2 deletions cluster/kubernetes/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"os"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/image"
)

type update struct {
Expand All @@ -18,7 +18,7 @@ type update struct {
}

func testUpdate(t *testing.T, u update) {
id, err := flux.ParseImageID(u.updatedImage)
id, err := image.ParseRef(u.updatedImage)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cluster/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/resource"
)
Expand All @@ -18,7 +19,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 image.Ref) ([]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
5 changes: 3 additions & 2 deletions cluster/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cluster

import (
"github.com/weaveworks/flux"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/resource"
"github.com/weaveworks/flux/ssh"
Expand All @@ -16,7 +17,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 image.Ref) ([]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 +53,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 image.Ref) ([]byte, error) {
return m.UpdateDefinitionFunc(def, container, newImageID)
}

Expand Down
9 changes: 5 additions & 4 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/weaveworks/flux/event"
"github.com/weaveworks/flux/git"
"github.com/weaveworks/flux/guid"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/job"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/registry"
Expand Down Expand Up @@ -417,10 +418,10 @@ 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, _ := image.ParseRef(c.Image)
res[i] = flux.Container{
Name: c.Name,
Current: flux.Image{
Current: image.Info{
ID: id,
},
}
Expand All @@ -430,12 +431,12 @@ 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, _ := image.ParseRef(c.Image)
repo := id.CanonicalName()
available := images[repo]
res = append(res, flux.Container{
Name: c.Name,
Current: flux.Image{
Current: image.Info{
ID: id,
},
Available: available,
Expand Down
13 changes: 7 additions & 6 deletions daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/weaveworks/flux/event"
"github.com/weaveworks/flux/git"
"github.com/weaveworks/flux/git/gittest"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/job"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/registry"
Expand Down Expand Up @@ -395,10 +396,10 @@ func mockDaemon(t *testing.T) (*Daemon, func(), *cluster.Mock, *mockEventWriter)

var imageRegistry registry.Registry
{
img1, _ := flux.ParseImage(currentHelloImage, time.Now())
img2, _ := flux.ParseImage(newHelloImage, time.Now().Add(1*time.Second))
img3, _ := flux.ParseImage("another/service:latest", time.Now().Add(1*time.Second))
imageRegistry = registry.NewMockRegistry([]flux.Image{
img1, _ := image.ParseInfo(currentHelloImage, time.Now())
img2, _ := image.ParseInfo(newHelloImage, time.Now().Add(1*time.Second))
img3, _ := image.ParseInfo("another/service:latest", time.Now().Add(1*time.Second))
imageRegistry = registry.NewMockRegistry([]image.Info{
img1,
img2,
img3,
Expand Down Expand Up @@ -506,8 +507,8 @@ func (w *wait) ForSyncStatus(d *Daemon, rev string, expectedNumCommits int) []st
return revs
}

func imageIDs(status []flux.ImageStatus) []flux.Image {
var availableImgs []flux.Image
func imageIDs(status []flux.ImageStatus) []image.Info {
var availableImgs []image.Info
for _, i := range status {
for _, c := range i.Containers {
availableImgs = append(availableImgs, c.Available...)
Expand Down
5 changes: 3 additions & 2 deletions daemon/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/update"
)
Expand Down Expand Up @@ -45,14 +46,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 := image.ParseRef(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
5 changes: 3 additions & 2 deletions flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/ssh"
)

Expand Down Expand Up @@ -263,8 +264,8 @@ type ControllerStatus struct {

type Container struct {
Name string
Current Image
Available []Image
Current image.Info
Available []image.Info
}

// --- config types
Expand Down
Loading