Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
| ... | ... |
@@ -111,7 +111,8 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string) (*apity |
| 111 | 111 |
digestImage, err := c.imageWithDigestString(ctx, ctnr.Image, authConfig) |
| 112 | 112 |
if err != nil {
|
| 113 | 113 |
logrus.Warnf("unable to pin image %s to digest: %s", ctnr.Image, err.Error())
|
| 114 |
- resp.Warnings = append(resp.Warnings, fmt.Sprintf("unable to pin image %s to digest: %s", ctnr.Image, err.Error()))
|
|
| 114 |
+ // warning in the client response should be concise |
|
| 115 |
+ resp.Warnings = append(resp.Warnings, digestWarning(ctnr.Image)) |
|
| 115 | 116 |
} else if ctnr.Image != digestImage {
|
| 116 | 117 |
logrus.Debugf("pinning image %s by digest: %s", ctnr.Image, digestImage)
|
| 117 | 118 |
ctnr.Image = digestImage |
| ... | ... |
@@ -200,7 +201,8 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ |
| 200 | 200 |
digestImage, err := c.imageWithDigestString(ctx, newCtnr.Image, authConfig) |
| 201 | 201 |
if err != nil {
|
| 202 | 202 |
logrus.Warnf("unable to pin image %s to digest: %s", newCtnr.Image, err.Error())
|
| 203 |
- resp.Warnings = append(resp.Warnings, fmt.Sprintf("unable to pin image %s to digest: %s", newCtnr.Image, err.Error()))
|
|
| 203 |
+ // warning in the client response should be concise |
|
| 204 |
+ resp.Warnings = append(resp.Warnings, digestWarning(newCtnr.Image)) |
|
| 204 | 205 |
} else if newCtnr.Image != digestImage {
|
| 205 | 206 |
logrus.Debugf("pinning image %s by digest: %s", newCtnr.Image, digestImage)
|
| 206 | 207 |
newCtnr.Image = digestImage |
| ... | ... |
@@ -351,7 +353,7 @@ func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authC |
| 351 | 351 |
namedRef, ok := ref.(reference.Named) |
| 352 | 352 |
if !ok {
|
| 353 | 353 |
if _, ok := ref.(reference.Digested); ok {
|
| 354 |
- return "", errors.New("image reference is an image ID")
|
|
| 354 |
+ return image, nil |
|
| 355 | 355 |
} |
| 356 | 356 |
return "", errors.Errorf("unknown image reference format: %s", image)
|
| 357 | 357 |
} |
| ... | ... |
@@ -383,3 +385,10 @@ func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authC |
| 383 | 383 |
// reference already contains a digest, so just return it |
| 384 | 384 |
return reference.FamiliarString(ref), nil |
| 385 | 385 |
} |
| 386 |
+ |
|
| 387 |
+// digestWarning constructs a formatted warning string |
|
| 388 |
+// using the image name that could not be pinned by digest. The |
|
| 389 |
+// formatting is hardcoded, but could me made smarter in the future |
|
| 390 |
+func digestWarning(image string) string {
|
|
| 391 |
+ return fmt.Sprintf("image %s could not be accessed on a registry to record\nits digest. Each node will access %s independently,\npossibly leading to different nodes running different\nversions of the image.\n", image, image)
|
|
| 392 |
+} |