Registry / aws / openshift-rest-client

openshift-rest-client

JSON →
library10.0.0jsnpmunverified

openshift-rest-client is a Node.js library designed to interact with the OpenShift REST API. It provides a client that translates OpenShift API Path Item Objects (like `/apis/project.openshift.io/v1/projects`) into idiomatic JavaScript object chains, allowing developers to interact with resources using methods such as `.get()`, `.post()`, `.delete()`, `.patch()`, and `.put()`. The library is currently stable at version 10.0.0 and follows a release cadence tied to Node.js LTS versions, introducing breaking changes primarily for dropping support for End-of-Life Node.js runtimes. A key differentiator is its integration with the kubernetes-client module for configuration, enabling flexible authentication and cluster context management, similar to the Fabric8 Maven Plugin but tailored for Node.js environments. It simplifies API interaction by providing aliases for common API groups and supports query parameters and path templating, making it a robust tool for programmatic OpenShift management from Node.js applications.

npm install openshift-rest-client
INSTALL
IMPORT
SIG · OPENSHIFT-REST-CLI
O
openshift-rest-client
awsjavascriptv10.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenshiftClient
✓ import { OpenshiftClient } from 'openshift-rest-client';
✗ const OpenshiftClient = require('openshift-rest-client');
The primary client factory. While the README shows CommonJS `require('pkg').OpenshiftClient`, modern Node.js environments (v10+) support named ESM imports for CJS modules. Avoid `require('pkg')` if you intend to get the factory directly.
config
✓ import { config } from 'openshift-rest-client';
✗ const configModule = require('openshift-rest-client'); const specificConfig = configModule.config;
A utility export for advanced configuration options, leveraging `kubernetes-client`'s config module. Direct named import is preferred in ESM.
OpenShiftClient
✓ import type { OpenShiftClient } from 'openshift-rest-client';
Type definition for the instantiated OpenShift client object, useful for TypeScript projects.

This example demonstrates how to initialize the OpenShift client, connect to an API endpoint (projects), and fetch resources. It includes basic error handling and uses environment variables for flexible configuration.

import { OpenshiftClient } from 'openshift-rest-client'; import type { OpenShiftClient } from 'openshift-rest-client'; // Configure the client using environment variables for safety, or a specific kubeconfig path. // process.env.KUBECONFIG can point to a specific file, or OpenshiftClient() will try default paths. const kubeConfigPath = process.env.KUBECONFIG || undefined; async function runClientExample() { let client: OpenShiftClient; try { if (kubeConfigPath) { console.log(`Attempting to connect using kubeconfig: ${kubeConfigPath}`); client = await OpenshiftClient({ config: kubeConfigPath }); } else { console.log('Attempting to connect using default kubeconfig or in-cluster configuration.'); client = await OpenshiftClient(); } console.log('Successfully connected to OpenShift API.'); // Fetch all projects accessible by the authenticated user console.log('Fetching all projects...'); const projectList = await client.apis['project.openshift.io'].v1.projects.get(); console.log(`Found ${projectList.body.items.length} projects.`); // Log details of the first project found, if any if (projectList.body.items.length > 0) { const firstProjectName = projectList.body.items[0].metadata?.name; console.log(`First project name: ${firstProjectName}`); } // Example: List all build configs in the 'default' namespace console.log('Fetching build configs in default namespace...'); const buildConfigs = await client.apis['build.openshift.io'].v1.namespaces('default').buildconfigs.get(); console.log(`Found ${buildConfigs.body.items.length} build configs in 'default' namespace.`); } catch (error: any) { console.error('An error occurred:', error.message); if (error.response?.body) { console.error('API Error Response:', JSON.stringify(error.response.body, null, 2)); } } } runClientExample();
Debug
Known issues
breakingVersion 10.0.0 removed support for Node.js 18. Ensure your environment uses Node.js 20, 22, or 24.
fix
Upgrade your Node.js runtime to version 20 or higher. Refer to the package's `engines` field for exact supported versions.
affects: >=10.0.0
breakingVersion 9.0.0 removed support for Node.js 16. Projects must be on Node.js 18 or newer.
fix
Upgrade your Node.js runtime to version 18 or higher.
affects: >=9.0.0 <10.0.0
breakingVersion 8.0.0 removed support for Node.js 14. Projects must be on Node.js 16 or newer.
fix
Upgrade your Node.js runtime to version 16 or higher.
affects: >=8.0.0 <9.0.0
breakingVersion 7.1.0 replaced the underlying `request` library with `undici` for HTTP operations. This may affect custom HTTP agents, proxy configurations, or specific `request` options no longer supported or handled differently by `undici`.
fix
Review any custom HTTP client configurations or options previously passed to `request`. Adapt them to `undici`'s API or the `kubernetes-client`'s options for underlying HTTP client configuration.
affects: >=7.1.0
gotchaThe `strictSSL` option was deprecated and replaced with `rejectUnauthorized` in v8.0.3. Using `strictSSL` might lead to unexpected behavior or be ignored.
fix
Replace `strictSSL: false` with `rejectUnauthorized: false` in your client configuration when dealing with self-signed certificates or untrusted CAs.
affects: >=8.0.3
Errors
Common errors & fixes
TypeError: client.apis['project.openshift.io'].v1.projects.get is not a function
Incorrect API path traversal or a typo in the API group, version, or resource name. The client builds the API structure dynamically based on the OpenShift API schema.
fix
Double-check the OpenShift API documentation for the exact path and method. Ensure the API version (e.g., `v1`) and resource names (e.g., `projects`) are correct and in the correct order.
Error: read ECONNRESET
This often indicates a network connection issue, an incorrect cluster URL, or a problem with TLS/SSL verification (e.g., self-signed certificate without `rejectUnauthorized: false`).
fix
Verify your OpenShift cluster URL and network connectivity. If using self-signed certificates, ensure `rejectUnauthorized: false` is set in your client configuration. Also check for proxy issues.
Error: The client only supports Node.js versions 20, 22, 24
The application is running on an unsupported Node.js version, as indicated by the package's `engines` field and recent breaking changes.
fix
Upgrade your Node.js runtime to one of the supported versions (20, 22, or 24) using a Node.js version manager like `nvm` or `volta`.
Upgrade
Version history
10.0.0latest on npm
Audit
Dependencies
kubernetes-clientrequiredUsed by default to load OpenShift/Kubernetes cluster configuration (e.g., from `~/.kube/config`).
Agent activity
14 hits · last 30 days
node
14
Resources
openshift-rest-client — npm install openshift-rest-client · libregistry