From bbfdf93b4104f7bb178c54d5068e1609371c82e8 Mon Sep 17 00:00:00 2001 From: hrao Date: Mon, 10 Mar 2025 17:19:53 +0530 Subject: [PATCH 1/3] upcoming: [M3-9422] - Update API endpoints and types for /v4/nodebalancers --- .../nodebalancer-config-nodes.ts | 115 +++++++++++++++++- .../src/nodebalancers/nodebalancer-configs.ts | 34 +++++- .../api-v4/src/nodebalancers/nodebalancers.ts | 20 +++ packages/api-v4/src/nodebalancers/types.ts | 8 ++ 4 files changed, 175 insertions(+), 2 deletions(-) diff --git a/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts b/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts index 20b9d7df86a..b0bb1ad3c07 100644 --- a/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts +++ b/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts @@ -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 { @@ -31,6 +31,34 @@ export const getNodeBalancerConfigNodes = ( ) ); +/** + * getNodeBalancerConfigNodesBeta + * + * Returns a paginated list of nodes for the specified NodeBalancer configuration profile. + * These are the backends that will be sent traffic for this port. + * Requires the NB-VPC feature flag to be enabled + * + * Note: Returns the vpc_config_id incase of a VPC backend + * + * duplicated function of getNodeBalancerConfigNodes + * necessary to call BETA_API_ROOT in a separate function based on the feature flag + * + * @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>( + setMethod('GET'), + setURL( + `${BETA_API_ROOT}/nodebalancers/${encodeURIComponent( + nodeBalancerId + )}/configs/${encodeURIComponent(configId)}/nodes` + ) + ); + /** * getNodeBalancerConfigNode * @@ -55,6 +83,36 @@ export const getNodeBalancerConfigNode = ( )}` ) ); + +/** + * getNodeBalancerConfigNodeBeta + * + * Returns details about a specific node for the given NodeBalancer configuration profile. + * + * Note: Returns the vpc_config_id incase of a VPC backend + * + * duplicated function of getNodeBalancerConfigNode + * necessary to call BETA_API_ROOT in a separate function based on the feature flag + * + * @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>( + setMethod('GET'), + setURL( + `${BETA_API_ROOT}/nodebalancers/${encodeURIComponent( + nodeBalancerId + )}/configs/${encodeURIComponent(configId)}/nodes/${encodeURIComponent( + nodeId + )}` + ) + ); /** * createNodeBalancerConfigNode * @@ -97,6 +155,33 @@ export const createNodeBalancerConfigNode = ( /** * createNodeBalancerConfigNode * + * 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. + * Requires the NB-VPC feature flag to be enabled + * + * Note: The BETA version accepts a Node's VPC IP address and subnet-id + * + * duplicated function of createNodeBalancer + * necessary to call BETA_API_ROOT in a separate function based on the feature flag + */ +export const createNodeBalancerConfigNodeBeta = ( + nodeBalancerId: number, + configId: number, + data: CreateNodeBalancerConfigNode +) => + Request( + 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. * * Note: The Linode API does not accept separate port and IP address parameters. This method will join @@ -135,6 +220,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( + setMethod('PUT'), + setURL( + `${BETA_API_ROOT}/nodebalancers/${encodeURIComponent( + nodeBalancerId + )}/configs/${encodeURIComponent(configId)}/nodes/${encodeURIComponent( + nodeId + )}` + ), + setData(data, nodeBalancerConfigNodeSchema, mergeAddressAndPort) + ); /** * deleteNodeBalancerConfigNode * diff --git a/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts b/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts index ac81afa6c28..5c1611e4e8f 100644 --- a/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts +++ b/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts @@ -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 { @@ -75,6 +75,38 @@ export const createNodeBalancerConfig = ( ) ); +/** + * createNodeBalancerConfig + * + * 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. + * Requires the NB-VPC feature flag to be enabled + * + * Note: The BETA version accepts a Node's VPC IP address and subnet-id + * + * duplicated function of createNodeBalancer + * necessary to call BETA_API_ROOT in a separate function based on the feature flag + * + * @param nodeBalancerId { number } The NodeBalancer to receive the new config. + */ +export const createNodeBalancerConfigBeta = ( + nodeBalancerId: number, + data: CreateNodeBalancerConfig +) => + Request( + setMethod('POST'), + setURL( + `${BETA_API_ROOT}/nodebalancers/${encodeURIComponent( + nodeBalancerId + )}/configs` + ), + setData( + data, + createNodeBalancerConfigSchema, + combineConfigNodeAddressAndPort + ) + ); + /** * updateNodeBalancerConfig * diff --git a/packages/api-v4/src/nodebalancers/nodebalancers.ts b/packages/api-v4/src/nodebalancers/nodebalancers.ts index 35f378bdea4..dcef43ce7a8 100644 --- a/packages/api-v4/src/nodebalancers/nodebalancers.ts +++ b/packages/api-v4/src/nodebalancers/nodebalancers.ts @@ -95,6 +95,26 @@ export const createNodeBalancer = (data: CreateNodeBalancerPayload) => ) ); +/** + * createNodeBalancer + * + * Create a NodeBalancer within a VPC with the BETA version + * Requires the NB-VPC feature flag to be enabled + * + * duplicated function of createNodeBalancer + * necessary to call BETA_API_ROOT in a separate function based on the feature flag + */ +export const createNodeBalancerBeta = (data: CreateNodeBalancerPayload) => + Request( + setMethod('POST'), + setURL(`${BETA_API_ROOT}/nodebalancers`), + setData( + data, + NodeBalancerSchema, + combineNodeBalancerConfigNodeAddressAndPort + ) + ); + /** * deleteNodeBalancer * diff --git a/packages/api-v4/src/nodebalancers/types.ts b/packages/api-v4/src/nodebalancers/types.ts index f969daa2c4c..2e782011d09 100644 --- a/packages/api-v4/src/nodebalancers/types.ts +++ b/packages/api-v4/src/nodebalancers/types.ts @@ -181,6 +181,7 @@ export interface CreateNodeBalancerConfig { cipher_suite?: 'recommended' | 'legacy' | 'none'; ssl_cert?: string; ssl_key?: string; + nodes?: CreateNodeBalancerConfigNode[]; } export type UpdateNodeBalancerConfig = CreateNodeBalancerConfig; @@ -193,6 +194,7 @@ export interface CreateNodeBalancerConfigNode { */ mode?: NodeBalancerConfigNodeMode; weight?: number; + subnet_id?: number; } export type UpdateNodeBalancerConfigNode = Partial; @@ -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 { @@ -232,4 +235,9 @@ export interface CreateNodeBalancerPayload { configs: CreateNodeBalancerConfig[]; firewall_id?: number; tags?: string[]; + vpc?: { + subnet_id: number; + ipv4_range: string; + ipv6_range?: string; + }[]; } From 904e74128ec11702dfbae7df1b82579d18c698f6 Mon Sep 17 00:00:00 2001 From: hrao Date: Mon, 10 Mar 2025 17:28:54 +0530 Subject: [PATCH 2/3] Add changeset --- .../.changeset/pr-11811-upcoming-features-1741607872773.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md diff --git a/packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md b/packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md new file mode 100644 index 00000000000..1810edffe0c --- /dev/null +++ b/packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md @@ -0,0 +1,5 @@ +--- +'@linode/api-v4': Upcoming Features +--- + +Add `/v4beta/nodebalancers` endpoints for NB-VPC Integration ([#11811](https://github.com/linode/manager/pull/11811)) From 782687fbeeae15d16d02a4d372367fd2a4df98c7 Mon Sep 17 00:00:00 2001 From: hrao Date: Wed, 12 Mar 2025 12:47:45 +0530 Subject: [PATCH 3/3] made comments more precise --- ...r-11811-upcoming-features-1741607872773.md | 2 +- .../nodebalancer-config-nodes.ts | 26 ++++++------------- .../src/nodebalancers/nodebalancer-configs.ts | 6 +---- .../api-v4/src/nodebalancers/nodebalancers.ts | 8 ++---- 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md b/packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md index 1810edffe0c..605ab8fe6f9 100644 --- a/packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md +++ b/packages/api-v4/.changeset/pr-11811-upcoming-features-1741607872773.md @@ -2,4 +2,4 @@ '@linode/api-v4': Upcoming Features --- -Add `/v4beta/nodebalancers` endpoints for NB-VPC Integration ([#11811](https://github.com/linode/manager/pull/11811)) +Add and update `/v4beta/nodebalancers` endpoints for NB-VPC Integration ([#11811](https://github.com/linode/manager/pull/11811)) diff --git a/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts b/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts index b0bb1ad3c07..ccff24807b7 100644 --- a/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts +++ b/packages/api-v4/src/nodebalancers/nodebalancer-config-nodes.ts @@ -34,14 +34,8 @@ export const getNodeBalancerConfigNodes = ( /** * getNodeBalancerConfigNodesBeta * - * Returns a paginated list of nodes for the specified NodeBalancer configuration profile. - * These are the backends that will be sent traffic for this port. - * Requires the NB-VPC feature flag to be enabled - * - * Note: Returns the vpc_config_id incase of a VPC backend - * - * duplicated function of getNodeBalancerConfigNodes - * necessary to call BETA_API_ROOT in a separate function based on the feature flag + * 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. @@ -83,16 +77,12 @@ export const getNodeBalancerConfigNode = ( )}` ) ); - /** * getNodeBalancerConfigNodeBeta * - * Returns details about a specific node for the given NodeBalancer configuration profile. + * Returns details about a specific node for the given NodeBalancer configuration profile from the beta API. * - * Note: Returns the vpc_config_id incase of a VPC backend - * - * duplicated function of getNodeBalancerConfigNode - * necessary to call BETA_API_ROOT in a separate function based on the feature flag + * 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. @@ -153,16 +143,16 @@ 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. - * Requires the NB-VPC feature flag to be enabled * * Note: The BETA version accepts a Node's VPC IP address and subnet-id * - * duplicated function of createNodeBalancer - * necessary to call BETA_API_ROOT in a separate function based on the feature flag + * @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, diff --git a/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts b/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts index 5c1611e4e8f..a690d580c41 100644 --- a/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts +++ b/packages/api-v4/src/nodebalancers/nodebalancer-configs.ts @@ -76,17 +76,13 @@ export const createNodeBalancerConfig = ( ); /** - * 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. - * Requires the NB-VPC feature flag to be enabled * * Note: The BETA version accepts a Node's VPC IP address and subnet-id * - * duplicated function of createNodeBalancer - * necessary to call BETA_API_ROOT in a separate function based on the feature flag - * * @param nodeBalancerId { number } The NodeBalancer to receive the new config. */ export const createNodeBalancerConfigBeta = ( diff --git a/packages/api-v4/src/nodebalancers/nodebalancers.ts b/packages/api-v4/src/nodebalancers/nodebalancers.ts index dcef43ce7a8..f9469565dd8 100644 --- a/packages/api-v4/src/nodebalancers/nodebalancers.ts +++ b/packages/api-v4/src/nodebalancers/nodebalancers.ts @@ -96,13 +96,9 @@ export const createNodeBalancer = (data: CreateNodeBalancerPayload) => ); /** - * createNodeBalancer - * - * Create a NodeBalancer within a VPC with the BETA version - * Requires the NB-VPC feature flag to be enabled + * createNodeBalancerBeta * - * duplicated function of createNodeBalancer - * necessary to call BETA_API_ROOT in a separate function based on the feature flag + * Add a NodeBalancer to your account using the beta API */ export const createNodeBalancerBeta = (data: CreateNodeBalancerPayload) => Request(