import logging


def ensure_instance_group_manager_matches(manager_cfg, instance_group_manager):
  """Ensures the InstanceGroupManager matches the config.

  Args:
    manager_cfg:
      proto.config_pb2.InstanceGroupManagerConfig.InstanceGroupManagers.
    instance_group_manager: models.InstanceGroupManager.

  Returns:
    Whether or not the given InstanceGroupManager was modified.
  """
  modified = False

  if instance_group_manager.minimum_size != manager_cfg.minimum_size:
    logging.info(
        'Updating minimum size (%s -> %s): %s',
        instance_group_manager.minimum_size,
        manager_cfg.minimum_size,
        instance_group_manager.key,
    )
    instance_group_manager.minimum_size = manager_cfg.minimum_size
    modified = True

  if instance_group_manager.maximum_size != manager_cfg.maximum_size:
    logging.info(
        'Updating maximum size (%s -> %s): %s',
        instance_group_manager.maximum_size,
        manager_cfg.maximum_size,
        instance_group_manager.key,
    )
    instance_group_manager.maximum_size = manager_cfg.maximum_size
    modified = True

  return modified