Resource Restrictions

Updated 1 month ago by Michael Cretzman

To queue the number of resources Harness requests during a deployment, and prevent multiple Workflows requesting the same deployment environment resources at a same time, you can place capacity limits on the resources Harness requests.

For example, a deployment cloud environment (AWS, GCP, Azure, etc) might limit host access to 5 at a time. You can use Resource Restrictions to ensure that the Workflow only requests access to 5 at the same time during deployment.

Another common example is deploying multiple artifacts to a single Kubernetes namespace because the same Workflow is deployed by two people simultaneously. To avoid collision, and queue deployments, you can set a maximum capacity of one request to the namespace at a time.

Resource Restrictions are Account-wide. This ensures that if a Resource Restriction is placed in one Workflow it will restrict any other Workflow in the Account from using the resource until it is safe to use.

In this topic:

Create Resource Restrictions

Resource Restrictions are set up at the Harness Account level, and may be used throughout all Applications.

To create a resource restriction, do the following:

  1. In Harness, click Setup.
  2. In Account, click the vertical ellipsis, and then click Resource Constraints.

The Resource Restrictions dialog appears.

  1. Click Add Constraint.
  2. Fill out the constraint fields:
  • Resource Constraint - Enter a name for your resource constraint. You will use this name to select the Resource Constraint in a Workflow.
  • Capacity - The maximum number of resources that may be consumed simultaneously.
  • Strategy - Choose FIFO if you want the resource requests to be selected in the order they arrived. Choose ASAP if you want Harness to select the first pending resource request that matches the number of available resources.
    As an ASAP example, imagine you have two resource requests: the first needs 2 hosts, and the second request needs 1 host. When 1 host becomes available, the second request is given the host as its request matches the number of available resources first.

The Current Usage value identifies if the resource restriction is applied a Workflow.

Apply Restrictions in Workflows

You can use your Resource Restrictions anywhere they are needed in a Workflow to queue resource requests, such as the Pre-deployment Steps.

To apply a Resource Restriction to a Workflow, do the following:

  1. In a Workflow, click Add Step. The Resource Constraint dialog appears.
  2. Fill out the constraint settings and click SUBMIT. The settings are described below.

Resource Constraint ID

Select the Resource Restriction to use at this stage of the Workflow. Note the capacity of the restriction. This is the maximum number of resources that may be consumed simultaneously.

Required Resource Usage

Enter the number of resources that are required at this step in the Workflow. If the number is more than the Capacity of the Resource Restriction you selected, the Workflow will remain at this step until the required resource usage has been reached. This is how you queue resource usage.

For example, if the Capacity is 4 and the Required Resource Usage is 5, Harness will use 4 resources simultaneously and wait until 1 resource becomes free so that it can use it for the 5th required resource.

Unit

The resource unit is any value that can identify a resource uniquely. You can use Harness built-in variables by entering $ and selecting from the list.

For example, to queue the services deployed to a Kubernetes namespace, you can enter ${infra.kubernetes.namespace} in Unit and set the Resource Restraint Capacity to 1.

To queue the services deployed to a particular Harness Service Infrastructure/Infrastructure Definition that uses the namespace, you would enter ${infra.kubernetes.infraId}-${infra.kubernetes.namespace} in Unit.

The following image shows the Resource Constraint step in the Workflow with Unit set to ${infra.kubernetes.infraId}-${infra.kubernetes.namespace} and the results of the deployed Workflow:

Notify When

Select when to notify users:

  • Blocked - Blocked means that more resources are required than are available and the step is waiting for resources to become free so that it can proceed.
  • Unblocked - Unblocked means that the required number of resources have been satisfied and the Workflow can proceed.

Notification Group

Select one or more User Groups to notify.

Scope

Scope this constraint to this Workflow.

Timeout

Enter how long the Resource Constraint should run before failing the step. If the timeout is reached before the Resource Constraint is able to process all resource requests, it will fail the Workflow and rollback will occur.


How did we do?