Browse Source

Merge pull request #1053 from weaveworks/issue/1051-dont-deploy-untagged

Log in places we might encounter an untagged image
Michael Bridgen 2 years ago
parent
commit
d0ebc7160c
No account linked to committer's email address
3 changed files with 16 additions and 5 deletions
  1. 4
    0
      daemon/images.go
  2. 10
    4
      registry/cache/warming.go
  3. 2
    1
      update/images.go

+ 4
- 0
daemon/images.go View File

@@ -56,6 +56,10 @@ func (d *Daemon) pollForNewImages(logger log.Logger) {
56 56
 			logger.Log("repo", repo, "pattern", pattern)
57 57
 
58 58
 			if latest, ok := imageMap.LatestImage(repo, pattern); ok && latest.ID != currentImageID {
59
+				if latest.ID.Tag == "" {
60
+					logger.Log("msg", "untagged image in available images", "action", "skip", "available", repo)
61
+					continue
62
+				}
59 63
 				newImage := currentImageID.WithNewTag(latest.ID.Tag)
60 64
 				changes.Add(service.ID, container, newImage)
61 65
 				logger.Log("msg", "added image to changes", "newimage", newImage)

+ 10
- 4
registry/cache/warming.go View File

@@ -63,7 +63,7 @@ func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGrou
63 63
 	// NB the implicit contract here is that the prioritised
64 64
 	// image has to have been running the last time we
65 65
 	// requested the credentials.
66
-	priorityWarm := func (name image.Name) {
66
+	priorityWarm := func(name image.Name) {
67 67
 		logger.Log("priority", name.String())
68 68
 		if creds, ok := imageCreds[name]; ok {
69 69
 			w.warm(ctx, logger, name, creds)
@@ -97,7 +97,7 @@ func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGrou
97 97
 			select {
98 98
 			case <-stop:
99 99
 				logger.Log("stopping", "true")
100
-				return 
100
+				return
101 101
 			case <-refresh:
102 102
 				imageCreds = imagesToFetchFunc()
103 103
 				backlog = imageCredsToBacklog(imageCreds)
@@ -108,7 +108,6 @@ func (w *Warmer) Loop(logger log.Logger, stop <-chan struct{}, wg *sync.WaitGrou
108 108
 	}
109 109
 }
110 110
 
111
-
112 111
 func imageCredsToBacklog(imageCreds registry.ImageCreds) []backlogItem {
113 112
 	backlog := make([]backlogItem, len(imageCreds))
114 113
 	var i int
@@ -178,15 +177,22 @@ func (w *Warmer) warm(ctx context.Context, logger log.Logger, id image.Name, cre
178 177
 		bytes, expiry, err := w.cache.GetKey(key)
179 178
 		// If err, then we don't have it yet. Update.
180 179
 		switch {
180
+		case tag == "":
181
+			errorLogger.Log("err", "empty tag in fetched tags", "tags", tags)
182
+			repo.LastError = "empty tag in fetched tags"
183
+			return // abort and let the error be written
181 184
 		case err != nil:
182 185
 			missing++
183 186
 		case time.Until(expiry) < refreshWhenExpiryWithin:
184 187
 			expired++
188
+		case len(bytes) == 0:
189
+			errorLogger.Log("err", "empty byte array from cache", "tag", tag)
190
+			missing++
185 191
 		default:
186 192
 			var image image.Info
187 193
 			if err := json.Unmarshal(bytes, &image); err == nil {
188 194
 				newImages[tag] = image
189
-				continue
195
+				continue // i.e., no need to update this one
190 196
 			}
191 197
 			missing++
192 198
 		}

+ 2
- 1
update/images.go View File

@@ -120,7 +120,8 @@ func exactImages(reg registry.Registry, images []image.Ref) (ImageMap, error) {
120 120
 }
121 121
 
122 122
 // Checks whether the given image exists in the repository.
123
-// Return true if exist, false otherwise
123
+// Return true if exist, false otherwise.
124
+// FIXME(michael): never returns an error; should it?
124 125
 func imageExists(reg registry.Registry, imageID image.Ref) (bool, error) {
125 126
 	_, err := reg.GetImage(imageID)
126 127
 	if err != nil {

Loading…
Cancel
Save