Exemple #1
0
// getImageInfo for a given image ID, returns the *v1alpha.Image object.
//
// FIXME(yifan): We should get the image manifest from the tree store.
// See https://github.com/coreos/rkt/issues/1659
func getImageInfo(store *store.Store, imageID string) (*v1alpha.Image, error) {
	aciInfo, err := store.GetACIInfoWithBlobKey(imageID)
	if err != nil {
		log.Printf("Failed to get ACI info for image ID %q: %v", imageID, err)
		return nil, err
	}

	image, _, err := aciInfoToV1AlphaAPIImage(store, aciInfo)
	if err != nil {
		log.Printf("Failed to convert ACI to v1alphaAPIImage for image ID %q: %v", imageID, err)
		return nil, err
	}
	return image, nil
}
Exemple #2
0
// getImageInfo for a given image ID, returns the *v1alpha.Image object.
func getImageInfo(store *store.Store, imageID string) (*v1alpha.Image, error) {
	key, err := store.ResolveKey(imageID)
	if err != nil {
		stderr.PrintE(fmt.Sprintf("failed to resolve the image ID %q", imageID), err)
		return nil, err
	}

	aciInfo, err := store.GetACIInfoWithBlobKey(key)
	if err != nil {
		stderr.PrintE(fmt.Sprintf("failed to get ACI info for image %q", key), err)
		return nil, err
	}

	image, _, err := aciInfoToV1AlphaAPIImage(store, aciInfo)
	if err != nil {
		stderr.PrintE(fmt.Sprintf("failed to convert ACI to v1alphaAPIImage for image %q", key), err)
		return nil, err
	}
	return image, nil
}
Exemple #3
0
func rmImages(s *store.Store, images []string) error {
	done := 0
	errors := 0
	staleErrors := 0
	imageMap := make(map[string]string)
	imageCounter := make(map[string]int)

	for _, pkey := range images {
		errors++
		h, err := types.NewHash(pkey)
		if err != nil {
			var found bool
			keys, found, err := s.ResolveName(pkey)
			if len(keys) > 0 {
				errors += len(keys) - 1
			}
			if err != nil {
				stderr("rkt: %v", err)
				continue
			}
			if !found {
				stderr("rkt: image name %q not found", pkey)
				continue
			}
			for _, key := range keys {
				imageMap[key] = pkey
				imageCounter[key]++
			}
		} else {
			key, err := s.ResolveKey(h.String())
			if err != nil {
				stderr("rkt: image ID %q not valid: %v", pkey, err)
				continue
			}
			if key == "" {
				stderr("rkt: image ID %q doesn't exist", pkey)
				continue
			}

			aciinfo, err := s.GetACIInfoWithBlobKey(key)
			if err != nil {
				stderr("rkt: error retrieving aci infos for image %q: %v", key, err)
				continue
			}
			imageMap[key] = aciinfo.Name
			imageCounter[key]++
		}
	}

	// Adjust the error count by subtracting duplicate IDs from it,
	// therefore allowing only one error per ID.
	for _, c := range imageCounter {
		if c > 1 {
			errors -= c - 1
		}
	}

	for key, name := range imageMap {
		if err := s.RemoveACI(key); err != nil {
			if serr, ok := err.(*store.StoreRemovalError); ok {
				staleErrors++
				stderr("rkt: some files cannot be removed for image %q (%q): %v", key, name, serr)
			} else {
				stderr("rkt: error removing aci for image %q (%q): %v", key, name, err)
				continue
			}
		}
		stdout("rkt: successfully removed aci for image: %q (%q)", key, name)
		errors--
		done++
	}

	if done > 0 {
		stderr("rkt: %d image(s) successfully removed", done)
	}

	// If anything didn't complete, return exit status of 1
	if (errors + staleErrors) > 0 {
		if staleErrors > 0 {
			stderr("rkt: %d image(s) removed but left some stale files", staleErrors)
		}
		if errors > 0 {
			stderr("rkt: %d image(s) cannot be removed", errors)
		}
		return fmt.Errorf("error(s) found while removing images")
	}

	return nil
}
Exemple #4
0
func rmImages(s *store.Store, images []string) error {
	done := 0
	errors := 0
	staleErrors := 0
	for _, pkey := range images {
		var (
			keys []string
			name string
		)
		errors++
		h, err := types.NewHash(pkey)
		if err != nil {
			var found bool
			keys, found, err = s.ResolveName(pkey)
			if len(keys) > 0 {
				errors += len(keys) - 1
			}
			if err != nil {
				stderr("rkt: %v", err)
				continue
			}
			if !found {
				stderr("rkt: image name %q not found", pkey)
				continue
			}
			name = pkey
		} else {
			key, err := s.ResolveKey(h.String())
			if err != nil {
				stderr("rkt: image ID %q not valid: %v", pkey, err)
				continue
			}
			if key == "" {
				stderr("rkt: image ID %q doesn't exist", pkey)
				continue
			}

			aciinfo, err := s.GetACIInfoWithBlobKey(key)
			if err != nil {
				stderr("rkt: error retrieving aci infos for image %q: %v", key, err)
				continue
			}
			name = aciinfo.Name
			keys = append(keys, key)
		}

		for _, key := range keys {
			if err = s.RemoveACI(key); err != nil {
				if serr, ok := err.(*store.StoreRemovalError); ok {
					staleErrors++
					stderr("rkt: some files cannot be removed for image %q (%q): %v", key, name, serr)
				} else {
					stderr("rkt: error removing aci for image %q (%q): %v", key, name, err)
					continue
				}
			}
			stdout("rkt: successfully removed aci for image: %q (%q)", key, name)
			errors--
			done++
		}
	}

	if done > 0 {
		stderr("rkt: %d image(s) successfully removed", done)
	}

	// If anything didn't complete, return exit status of 1
	if (errors + staleErrors) > 0 {
		if staleErrors > 0 {
			stderr("rkt: %d image(s) removed but left some stale files", staleErrors)
		}
		if errors > 0 {
			stderr("rkt: %d image(s) cannot be removed", errors)
		}
		return fmt.Errorf("error(s) found while removing images")
	}

	return nil
}