def check_redis_quota()

in nuvolaris/quota_checker.py [0:0]


def check_redis_quota(redis_client: RedisClient, redis_wsku):
    """
    Check REDIS/VALKEY quota
    """
    logging.info("***** Checking Redis Cache limit ****")

    if len(redis_wsku) == 0:
        logging.info("no nuvolaris wsku resource with enforced REDIS quota limit found!")
        return

    for wsku in redis_wsku:        
        spec = wsku['spec']
        metadata = wsku['metadata']
        wsku_name = metadata['name']
        prefix = f"{spec['redis']['prefix']}"
        namespace = spec['namespace']
        quota_applied = "false"
        redis_quota = int(spec['redis']['quota'])*1014*1024

        if(not prefix.endswith(":")):
            prefix = f"{prefix}:"

        # Check if the quota annotations has been already applied
        if "annotations" in metadata and REDIS_DB_QUOTA_ANNOTATION in metadata["annotations"]:
            quota_applied = metadata["annotations"][REDIS_DB_QUOTA_ANNOTATION]

        logging.info(f"REDIS prefix {prefix} enforced quota is set to {redis_quota} bytes")        
        current_redis_db_quota = redis_client.calculate_prefix_allocated_size(prefix)
            
        if current_redis_db_quota >= redis_quota:
                if quota_applied in ["false"]:
                    block_redis_prefix_quota(redis_client,
                                wsku_name ,
                                namespace, 
                                prefix,
                                REDIS_DB_QUOTA_ANNOTATION)
                    continue
                else:
                    logging.info(f"***** REDIS prefix {prefix} size {current_redis_db_quota} is exceeding quota limit {redis_quota}, but revoke has been already executed ****")
                    continue 
            
        if current_redis_db_quota < redis_quota and quota_applied in ["true"]:
                reset_redis_prefix_quota(redis_client,
                                wsku_name ,
                              namespace, 
                              prefix,
                              REDIS_DB_QUOTA_ANNOTATION)
                continue

        logging.info(f"***** REDIS prefix {prefix} size {current_redis_db_quota} is not exceeding quota limit {redis_quota} ****")