// updateImages, refreshes the cache entries for the images passed. It may not succeed for all images.
// It returns the values stored in cache, the number of images it succeeded for and the number
// of images whose manifest wasn't found in the registry.
439930
func (c *repoCacheManager) updateImages(ctx context.Context, images []imageToUpdate) (map[string]image.Info, int, int) {
	// The upper bound for concurrent fetches against a single host is
	// w.Burst, so limit the number of fetching goroutines to that.
	fetchers := make(chan struct{}, c.burst)
	awaitFetchers := &sync.WaitGroup{}

	ctxc, cancel := context.WithCancel(ctx)
	defer cancel()

	var successCount int
	var manifestUnknownCount int
	var result = map[string]image.Info{}
	var warnAboutRateLimit sync.Once
updates:
	for _, up := range images {
		// to avoid race condition, when accessing it in the go routine
		upCopy := up
		select {
		case <-ctxc.Done():
			break updates
		case fetchers <- struct{}{}:
		}
		awaitFetchers.Add(1)
		go func() {
			defer func() { awaitFetchers.Done(); <-fetchers }()
			ctxcc, cancel := context.WithTimeout(ctxc, c.clientTimeout)
			defer cancel()
			entry, err := c.updateImage(ctxcc, upCopy)
			if err != nil {
				if err, ok := errors.Cause(err).(net.Error); (ok && err.Timeout()) || ctxcc.Err() == context.DeadlineExceeded {
					// This was due to a context timeout, don't bother logging
					return
				}
				switch {
				case strings.Contains(err.Error(), "429"):
					// abort the image tags fetching if we've been rate limited
					warnAboutRateLimit.Do(func() {
						c.logger.Log("warn", "aborting image tag fetching due to rate limiting, will try again later")
						cancel()
					})
				case strings.Contains(err.Error(), "manifest unknown"):
					// Registry is corrupted, keep going, this manifest may not be relevant for automatic updates
					c.Lock()
					manifestUnknownCount++
					c.Unlock()
					c.logger.Log("warn", fmt.Sprintf("manifest for tag %s missing in repository %s", up.ref.Tag, up.ref.Name),
						"impact", "flux will fail to auto-release workloads with matching images, ask the repository administrator to fix the inconsistency")
				default:
					c.logger.Log("err", err, "ref", up.ref)
				}
				return
			}
			c.Lock()
			successCount++
			if entry.ExcludedReason == "" {
				result[upCopy.ref.Tag] = entry.Info
			}
			c.Unlock()
		}()
	}
	awaitFetchers.Wait()
	return result, successCount, manifestUnknownCount
}
363026
func (f *Facade) SyncRegistryImages(ctx datastore.Context, force bool) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.SyncRegistryImages"))
	if err := f.DFSLock(ctx).LockWithTimeout("sync registry images", userLockTimeout); err != nil {
		glog.Warningf("Cannot sync registry images: %s", err)
		return err
	}
	defer f.DFSLock(ctx).Unlock()

	// get all the images that are currently in the index
	rImages, err := f.GetRegistryImages(ctx)
	if err != nil {
		return err
	}
	// we aren't going to try to sync deletes because that can get too messy;
	// only adds and updates
	for _, rImage := range rImages {
		img, err := f.zzk.GetRegistryImage(rImage.ID())
		if err != client.ErrNoNode && err != nil {
			return err
		}
		// only update the images where the uuid has changed and from the
		// upstream only, to make sure we don't override any changes that
		// occur out of band from the sync.  If force is set, then it is okay
		// to blanket reset everything.
		if force || img == nil || img.UUID != rImage.UUID {
			if err := f.SetRegistryImage(ctx, &rImage); err != nil {
				return err
			}
		}
	}
	return nil
}
1031629
func (user *User) UpdateCache(key string, update interface{}, res interface{}) error {

	exists := user.ctx.updateCacheVal("user", key, update, res)

	if !exists {
		log.WithField("key", key).Error("Can't update user cache value")
	}
	return nil
}
472776
func (f *Finder) FindImages(al *apps.Apps) error {
	return al.Walk(func(app *apps.App) error {
		h, err := f.FindImage(app.Image, app.Asc)
		if err != nil {
			return err
		}
		app.ImageID = *h
		return nil
	})
}
1371238
func (c *images) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *image.Image, err error) {
	result = &image.Image{}
	err = c.client.Patch(pt).
		Resource("images").
		SubResource(subresources...).
		Name(name).
		Body(data).
		Do().
		Into(result)
	return
}
208494
func (s *DescribeWorkspaceImagesOutput) SetImages(v []*WorkspaceImage) *DescribeWorkspaceImagesOutput {
	s.Images = v
	return s
}
150354
func ValidateImageStreamUpdate(newStream, oldStream *imageapi.ImageStream) field.ErrorList {
	return ValidateImageStreamUpdateWithWhitelister(nil, newStream, oldStream)
}
1341579
func (i *ImageService) UpdateConfig(maxDownloads, maxUploads *int) {
	if i.downloadManager != nil && maxDownloads != nil {
		i.downloadManager.SetConcurrency(*maxDownloads)
	}
	if i.uploadManager != nil && maxUploads != nil {
		i.uploadManager.SetConcurrency(*maxUploads)
	}
}
720925
func LoadImages(cmd bootstrapper.CommandRunner, images []string, cacheDir string) error {
	var g errgroup.Group
	// Load profile cluster config from file
	cc, err := config.Load()
	if err != nil && !os.IsNotExist(err) {
		glog.Errorln("Error loading profile config: ", err)
	}
	for _, image := range images {
		image := image
		g.Go(func() error {
			src := filepath.Join(cacheDir, image)
			src = sanitizeCacheDir(src)
			if err := loadImageFromCache(cmd, cc.KubernetesConfig, src); err != nil {
				glog.Warningf("Failed to load %s: %v", src, err)
				return errors.Wrapf(err, "loading image %s", src)
			}
			return nil
		})
	}
	if err := g.Wait(); err != nil {
		return errors.Wrap(err, "loading cached images")
	}
	glog.Infoln("Successfully loaded all cached images.")
	return nil
}
740297
func (p *preimageBeacon) AddPreimages(preimages ...lntypes.Preimage) error {
	// Exit early if no preimages are presented.
	if len(preimages) == 0 {
		return nil
	}

	// Copy the preimages to ensure the backing area can't be modified by
	// the caller when delivering notifications.
	preimageCopies := make([]lntypes.Preimage, 0, len(preimages))
	for _, preimage := range preimages {
		srvrLog.Infof("Adding preimage=%v to witness cache", preimage)
		preimageCopies = append(preimageCopies, preimage)
	}

	// First, we'll add the witness to the decaying witness cache.
	err := p.wCache.AddSha256Witnesses(preimages...)
	if err != nil {
		return err
	}

	p.Lock()
	defer p.Unlock()

	// With the preimage added to our state, we'll now send a new
	// notification to all subscribers.
	for _, client := range p.subscribers {
		go func(c *preimageSubscriber) {
			for _, preimage := range preimageCopies {
				select {
				case c.updateChan <- preimage:
				case <-c.quit:
					return
				}
			}
		}(client)
	}

	return nil
}
1258298
func (s *EnvironmentLanguage) SetImages(v []*EnvironmentImage) *EnvironmentLanguage {
	s.Images = v
	return s
}
360536
func (c *FakeImageStreams) Update(imageStream *image.ImageStream) (result *image.ImageStream, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewUpdateAction(imagestreamsResource, c.ns, imageStream), &image.ImageStream{})

	if obj == nil {
		return nil, err
	}
	return obj.(*image.ImageStream), err
}
1295929
func (p *PartitionedMemoryIdx) UpdateArchive(archive idx.Archive) {
	p.Partition[archive.Partition].UpdateArchive(archive)
}
44461
func newImageResolutionCache(imageClient imageinternalclient.ImageInterface, integratedRegistry rules.RegistryMatcher) (*imageResolutionCache, error) {
	imageCache, err := lru.New(128)
	if err != nil {
		return nil, err
	}
	return &imageResolutionCache{
		imageClient: imageClient,
		integrated:  integratedRegistry,
		cache:       imageCache,
		expiration:  time.Minute,
	}, nil
}
356527
func (c *imageStreamTags) Update(imageStreamTag *image.ImageStreamTag) (result *image.ImageStreamTag, err error) {
	result = &image.ImageStreamTag{}
	err = c.client.Put().
		Namespace(c.ns).
		Resource("imagestreamtags").
		Name(imageStreamTag.Name).
		Body(imageStreamTag).
		Do().
		Into(result)
	return
}
191105
func (g *gatewayCfg) updateURLs(infoURLs []string) {
	g.Lock()
	// Clear the map...
	g.urls = make(map[string]*url.URL, len(g.URLs)+len(infoURLs))
	// Add the urls from the config URLs array.
	for _, u := range g.URLs {
		g.urls[u.Host] = u
	}
	// Then add the ones from the infoURLs array we got.
	g.addURLs(infoURLs)
	g.Unlock()
}
676263
func waitCacheImages(g *errgroup.Group) {
	if !viper.GetBool(cacheImages) {
		return
	}
	console.OutStyle("waiting", "Waiting for image downloads to complete ...")
	if err := g.Wait(); err != nil {
		glog.Errorln("Error caching images: ", err)
	}
}