Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@linode/api-v4': Upcoming Features
---

Add and update `/v4beta/nodebalancers` endpoints for NB-VPC Integration ([#11811](https://github.com/linode/manager/pull/11811))
107 changes: 105 additions & 2 deletions packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nodeBalancerConfigNodeSchema } from '@linode/validation/lib/nodebalancers.schema';
import { API_ROOT } from '../constants';
import { API_ROOT, BETA_API_ROOT } from '../constants';
import Request, { setData, setMethod, setURL } from '../request';
import { ResourcePage as Page } from '../types';
import {
Expand Down Expand Up @@ -31,6 +31,28 @@ export const getNodeBalancerConfigNodes = (
)
);

/**
* getNodeBalancerConfigNodesBeta
*
* Returns a paginated list of nodes for the specified NodeBalancer configuration profile from the beta API.
* Note: Returns the vpc_config_id in case of a VPC backend
*
* @param nodeBalancerId { number } The ID of the NodeBalancer the config belongs to.
* @param configId { number } The configuration profile to retrieve nodes for.
*/
export const getNodeBalancerConfigNodesBeta = (
nodeBalancerId: number,
configId: number
) =>
Request<Page<NodeBalancerConfigNode>>(
setMethod('GET'),
setURL(
`${BETA_API_ROOT}/nodebalancers/${encodeURIComponent(
nodeBalancerId
)}/configs/${encodeURIComponent(configId)}/nodes`
)
);

/**
* getNodeBalancerConfigNode
*
Expand All @@ -55,6 +77,32 @@ export const getNodeBalancerConfigNode = (
)}`
)
);
/**
* getNodeBalancerConfigNodeBeta
*
* Returns details about a specific node for the given NodeBalancer configuration profile from the beta API.
*
* Note: Returns the vpc_config_id in case of a VPC backend
*
* @param nodeBalancerId { number } The ID of the NodeBalancer the config belongs to.
* @param configId { number } The configuration profile to retrieve nodes for.
* @param nodeId { number } The Node to be retrieved.
*/
export const getNodeBalancerConfigNodeBeta = (
nodeBalancerId: number,
configId: number,
nodeId: number
) =>
Request<Page<NodeBalancerConfigNode>>(
setMethod('GET'),
setURL(
`${BETA_API_ROOT}/nodebalancers/${encodeURIComponent(
nodeBalancerId
)}/configs/${encodeURIComponent(configId)}/nodes/${encodeURIComponent(
nodeId
)}`
)
);
/**
* createNodeBalancerConfigNode
*
Expand Down Expand Up @@ -95,7 +143,34 @@ export const createNodeBalancerConfigNode = (
);

/**
* createNodeBalancerConfigNode
* createNodeBalancerConfigNodeBeta
*
* Creates a NodeBalancer Node, a backend that can accept traffic for
* this NodeBalancer Config. Nodes are routed requests on the configured port based on their status.
*
* Note: The BETA version accepts a Node's VPC IP address and subnet-id
*
* @param nodeBalancerId { number } The ID of the NodeBalancer the config belongs to.
* @param configId { number } The configuration profile to add a node to.
* @param data
*/
export const createNodeBalancerConfigNodeBeta = (
nodeBalancerId: number,
configId: number,
data: CreateNodeBalancerConfigNode
) =>
Request<NodeBalancerConfigNode>(
setMethod('POST'),
setURL(
`${BETA_API_ROOT}/nodebalancers/${encodeURIComponent(
nodeBalancerId
)}/configs/${encodeURIComponent(configId)}/nodes`
),
setData(data, nodeBalancerConfigNodeSchema, mergeAddressAndPort)
);

/**
* UpdateNodeBalancerConfigNode
*
* Updates a backend node for the specified NodeBalancer configuration profile.
*
Expand Down Expand Up @@ -135,6 +210,34 @@ export const updateNodeBalancerConfigNode = (
setData(data, nodeBalancerConfigNodeSchema, mergeAddressAndPort)
);

/**
* UpdateNodeBalancerConfigNodeBeta
*
* Updates a backend node for the specified NodeBalancer configuration profile.
*
* Note: The BETA version accepts a Node's VPC IP address and subnet-id
*
* @param nodeBalancerId { number } The ID of the NodeBalancer the config belongs to.
* @param configId { number } The configuration profile to add a node to.
* @param data
*/
export const updateNodeBalancerConfigNodeBeta = (
nodeBalancerId: number,
configId: number,
nodeId: number,
data: UpdateNodeBalancerConfigNode
) =>
Request<NodeBalancerConfigNode>(
setMethod('PUT'),
setURL(
`${BETA_API_ROOT}/nodebalancers/${encodeURIComponent(
nodeBalancerId
)}/configs/${encodeURIComponent(configId)}/nodes/${encodeURIComponent(
nodeId
)}`
),
setData(data, nodeBalancerConfigNodeSchema, mergeAddressAndPort)
);
/**
* deleteNodeBalancerConfigNode
*
Expand Down
30 changes: 29 additions & 1 deletion packages/api-v4/src/nodebalancers/nodebalancer-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createNodeBalancerConfigSchema,
UpdateNodeBalancerConfigSchema,
} from '@linode/validation/lib/nodebalancers.schema';
import { API_ROOT } from '../constants';
import { API_ROOT, BETA_API_ROOT } from '../constants';
import Request, { setData, setMethod, setParams, setURL } from '../request';
import { ResourcePage as Page, Params } from '../types';
import {
Expand Down Expand Up @@ -75,6 +75,34 @@ export const createNodeBalancerConfig = (
)
);

/**
* createNodeBalancerConfigBeta
*
* Creates a NodeBalancer Config, which allows the NodeBalancer to accept traffic on a new port.
* You will need to add NodeBalancer Nodes to the new Config before it can actually serve requests.
*
* Note: The BETA version accepts a Node's VPC IP address and subnet-id
*
* @param nodeBalancerId { number } The NodeBalancer to receive the new config.
*/
export const createNodeBalancerConfigBeta = (
nodeBalancerId: number,
data: CreateNodeBalancerConfig
) =>
Request<NodeBalancerConfig>(
setMethod('POST'),
setURL(
`${BETA_API_ROOT}/nodebalancers/${encodeURIComponent(
nodeBalancerId
)}/configs`
),
setData(
data,
createNodeBalancerConfigSchema,
combineConfigNodeAddressAndPort
)
);

/**
* updateNodeBalancerConfig
*
Expand Down
16 changes: 16 additions & 0 deletions packages/api-v4/src/nodebalancers/nodebalancers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ export const createNodeBalancer = (data: CreateNodeBalancerPayload) =>
)
);

/**
* createNodeBalancerBeta
*
* Add a NodeBalancer to your account using the beta API
*/
export const createNodeBalancerBeta = (data: CreateNodeBalancerPayload) =>
Request<NodeBalancer>(
setMethod('POST'),
setURL(`${BETA_API_ROOT}/nodebalancers`),
setData(
data,
NodeBalancerSchema,
combineNodeBalancerConfigNodeAddressAndPort
)
);

/**
* deleteNodeBalancer
*
Expand Down
8 changes: 8 additions & 0 deletions packages/api-v4/src/nodebalancers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export interface CreateNodeBalancerConfig {
cipher_suite?: 'recommended' | 'legacy' | 'none';
ssl_cert?: string;
ssl_key?: string;
nodes?: CreateNodeBalancerConfigNode[];
}

export type UpdateNodeBalancerConfig = CreateNodeBalancerConfig;
Expand All @@ -193,6 +194,7 @@ export interface CreateNodeBalancerConfigNode {
*/
mode?: NodeBalancerConfigNodeMode;
weight?: number;
subnet_id?: number;
}

export type UpdateNodeBalancerConfigNode = Partial<CreateNodeBalancerConfigNode>;
Expand All @@ -206,6 +208,7 @@ export interface NodeBalancerConfigNode {
nodebalancer_id: number;
status: 'unknown' | 'UP' | 'DOWN';
weight: number;
vpc_config_id?: number | null;
}

export interface NodeBalancerConfigNodeWithPort extends NodeBalancerConfigNode {
Expand All @@ -232,4 +235,9 @@ export interface CreateNodeBalancerPayload {
configs: CreateNodeBalancerConfig[];
firewall_id?: number;
tags?: string[];
vpc?: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field should be named vpcs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this. Added the change in PR #11832

subnet_id: number;
ipv4_range: string;
ipv6_range?: string;
}[];
}