boskos/mason/storage.go
func (s *Storage) SyncConfigs(newConfigs []common.ResourcesConfig) error {
	s.configsLock.Lock()
	defer s.configsLock.Unlock()

	currentConfigs, err := s.GetConfigs()
	if err != nil {
		logrus.WithError(err).Error("cannot find configs")
		return err
	}

	currentSet := mapset.NewSet()
	newSet := mapset.NewSet()
	toUpdate := mapset.NewSet()

	configs := map[string]common.ResourcesConfig{}

	for _, c := range currentConfigs {
		currentSet.Add(c.Name)
		configs[c.Name] = c
	}

	for _, c := range newConfigs {
		newSet.Add(c.Name)
		if old, exists := configs[c.Name]; exists {
			if !reflect.DeepEqual(old, c) {
				toUpdate.Add(c.Name)
				configs[c.Name] = c
			}
		} else {
			configs[c.Name] = c
		}
	}

	var finalError error

	toDelete := currentSet.Difference(newSet)
	toAdd := newSet.Difference(currentSet)

	for _, n := range toDelete.ToSlice() {
		logrus.Infof("Deleting config %s", n.(string))
		if err := s.DeleteConfig(n.(string)); err != nil {
			logrus.WithError(err).Errorf("failed to delete config %s", n)
			finalError = multierror.Append(finalError, err)
		}
	}

	for _, n := range toAdd.ToSlice() {
		rc := configs[n.(string)]
		logrus.Infof("Adding config %s", n.(string))
		if err := s.AddConfig(rc); err != nil {
			logrus.WithError(err).Errorf("failed to create resources %s", n)
			finalError = multierror.Append(finalError, err)
		}
	}

	for _, n := range toUpdate.ToSlice() {
		rc := configs[n.(string)]
		logrus.Infof("Updating config %s", n.(string))
		if err := s.UpdateConfig(rc); err != nil {
			logrus.WithError(err).Errorf("failed to update resources %s", n)
			finalError = multierror.Append(finalError, err)
		}
	}

	return finalError
}
func (s *Storage) SyncConfigs(newConfigs []common.ResourcesConfig) error {
	s.configsLock.Lock()
	defer s.configsLock.Unlock()

	currentConfigs, err := s.GetConfigs()
	if err != nil {
		logrus.WithError(err).Error("cannot find configs")
		return err
	}

	currentSet := mapset.NewSet()
	newSet := mapset.NewSet()
	toUpdate := mapset.NewSet()

	configs := map[string]common.ResourcesConfig{}

	for _, c := range currentConfigs {
		currentSet.Add(c.Name)
		configs[c.Name] = c
	}

	for _, c := range newConfigs {
		newSet.Add(c.Name)
		if old, exists := configs[c.Name]; exists {
			if !reflect.DeepEqual(old, c) {
				toUpdate.Add(c.Name)
				configs[c.Name] = c
			}
		} else {
			configs[c.Name] = c
		}
	}

	var finalError error

	toDelete := currentSet.Difference(newSet)
	toAdd := newSet.Difference(currentSet)

	for _, n := range toDelete.ToSlice() {
		logrus.Infof("Deleting config %s", n.(string))
		if err := s.DeleteConfig(n.(string)); err != nil {
			logrus.WithError(err).Errorf("failed to delete config %s", n)
			finalError = multierror.Append(finalError, err)
		}
	}

	for _, n := range toAdd.ToSlice() {
		rc := configs[n.(string)]
		logrus.Infof("Adding config %s", n.(string))
		if err := s.AddConfig(rc); err != nil {
			logrus.WithError(err).Errorf("failed to create resources %s", n)
			finalError = multierror.Append(finalError, err)
		}
	}

	for _, n := range toUpdate.ToSlice() {
		rc := configs[n.(string)]
		logrus.Infof("Updating config %s", n.(string))
		if err := s.UpdateConfig(rc); err != nil {
			logrus.WithError(err).Errorf("failed to update resources %s", n)
			finalError = multierror.Append(finalError, err)
		}
	}

	return finalError
}
func ( s * Storage ) SyncConfigs ( newConfigs [ ] common . ResourcesConfig ) error { s . configsLock . Lock ( ) defer s . configsLock . Unlock ( ) currentConfigs , err := s . GetConfigs ( ) if err != nil { logrus . WithError ( err ) . Error ( " " ) return err } currentSet := mapset . NewSet ( ) newSet := mapset . NewSet ( ) toUpdate := mapset . NewSet ( ) configs := map [ string ] common . ResourcesConfig { } for _ , c := range currentConfigs { currentSet . Add ( c . Name ) configs [ c . Name ] = c } for _ , c := range newConfigs { newSet . Add ( c . Name ) if old , exists := configs [ c . Name ] ; exists { if ! reflect . DeepEqual ( old , c ) { toUpdate . Add ( c . Name ) configs [ c . Name ] = c } } else { configs [ c . Name ] = c } } var finalError error toDelete := currentSet . Difference ( newSet ) toAdd := newSet . Difference ( currentSet ) for _ , n := range toDelete . ToSlice ( ) { logrus . Infof ( " " , n . ( string ) ) if err := s . DeleteConfig ( n . ( string ) ) ; err != nil { logrus . WithError ( err ) . Errorf ( " " , n ) finalError = multierror . Append ( finalError , err ) } } for _ , n := range toAdd . ToSlice ( ) { rc := configs [ n . ( string ) ] logrus . Infof ( " " , n . ( string ) ) if err := s . AddConfig ( rc ) ; err != nil { logrus . WithError ( err ) . Errorf ( " " , n ) finalError = multierror . Append ( finalError , err ) } } for _ , n := range toUpdate . ToSlice ( ) { rc := configs [ n . ( string ) ] logrus . Infof ( " " , n . ( string ) ) if err := s . UpdateConfig ( rc ) ; err != nil { logrus . WithError ( err ) . Errorf ( " " , n ) finalError = multierror . Append ( finalError , err ) } } return finalError }
// SyncConfigs syncs new configs
SyncConfigs syncs new configs