//RefreshState makes sure that we update our representation of the state of the world to match the latest observation
RefreshState makes sure that we update our representation of the state of the world to match the latest observation
// RefreshState makes sure that we update our representation of the state of the world to match the latest observation
func (s *InMemorySyncState) RefreshState(apps []argov1alpha1.Application, stage syncv1alpha1.ProgressiveSyncStage) {
	s.Mutex.Lock()
	defer s.Mutex.Unlock()
	unmarkedApps := s.getUnmarkedApps(apps, stage)
	if _, ok := s.MaxParallelPerStage[stage.Name]; !ok {
		maxTargets, _ := intstr.GetScaledValueFromIntOrPercent(&stage.MaxTargets, len(unmarkedApps), false)
		maxParallel, _ := intstr.GetScaledValueFromIntOrPercent(&stage.MaxParallel, len(unmarkedApps), false)
		if maxTargets == 0 {
			maxTargets = 1
		}
		if maxParallel == 0 {
			maxParallel = 1
		}
		s.MaxParallelPerStage[stage.Name] = maxParallel
		s.MaxTargetsPerStage[stage.Name] = maxTargets
	}
	_, ok := s.SyncedAppsPerStage[stage.Name]
	if !ok {
		s.SyncedAppsPerStage[stage.Name] = 0
	}
	appsToMark := s.MaxTargetsPerStage[stage.Name] - s.SyncedAppsPerStage[stage.Name]
	if len(unmarkedApps) < appsToMark {
		appsToMark = len(unmarkedApps)
	}
	for i := 0; i < appsToMark; i++ {
		s.SyncedAtStage[unmarkedApps[i].Name] = stage.Name
		s.SyncedAppsPerStage[stage.Name]++
	}
}
func ( s * InMemorySyncState ) RefreshState ( apps [ ] argov1alpha1 . Application , stage syncv1alpha1 . ProgressiveSyncStage ) { s . Mutex . Lock ( ) defer s . Mutex . Unlock ( ) unmarkedApps := s . getUnmarkedApps ( apps , stage ) if _ , ok := s . MaxParallelPerStage [ stage . Name ] ; ! ok { maxTargets , _ := intstr . GetScaledValueFromIntOrPercent ( & stage . MaxTargets , len ( unmarkedApps ) , false ) maxParallel , _ := intstr . GetScaledValueFromIntOrPercent ( & stage . MaxParallel , len ( unmarkedApps ) , false ) if maxTargets == 0 { maxTargets = 1 } if maxParallel == 0 { maxParallel = 1 } s . MaxParallelPerStage [ stage . Name ] = maxParallel s . MaxTargetsPerStage [ stage . Name ] = maxTargets } _ , ok := s . SyncedAppsPerStage [ stage . Name ] if ! ok { s . SyncedAppsPerStage [ stage . Name ] = 0 } appsToMark := s . MaxTargetsPerStage [ stage . Name ] - s . SyncedAppsPerStage [ stage . Name ] if len ( unmarkedApps ) < appsToMark { appsToMark = len ( unmarkedApps ) } for i := 0 ; i < appsToMark ; i ++ { s . SyncedAtStage [ unmarkedApps [ i ] . Name ] = stage . Name s . SyncedAppsPerStage [ stage . Name ] ++ } }
RefreshState makes sure that we update our representation of the state of the world to match the latest observation
RefreshState makes sure that we update our representation of the state of the world to match the latest observation
//TODO: While this buys us time for now, as it calculates correctly MaxTargets and MaxParallel // even when they are percentages, this will break if the users have changed those fields in progressive sync spec // because we only initialize it once // We should react to the event of progressive sync spec being changed and invalidate these maps // Validation should never allow the user to explicitly use zero values for maxTargets or maxParallel. // Due the rounding down when scaled, they might resolve to 0. // If one of them resolve to 0, we set it to 1.