
Security News
pnpm 11.5 Adds Support for Recognizing npm Staged Publishes
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.
@kubelib/config
Advanced tools
The last Kubeconfig abstraction in JS you will need
yarn add @kubelib/config
Build a Kubeconfig from scratch
import { buildConfig, addCluster, addUser, addContext } from '@kubelib/config'
// build a config from scratch with modifiers
const config = buildConfig(
addCluster('foo', {
server: 'https://my-kubernetes-cp.example.com'
}),
addUser('bar', {
username: 'admin',
password: 'admin'
}),
addContext('foobar', {
cluster: 'foo',
user: 'bar'
}),
)
Load default kubeconfig and modify it
import {
loadDefaultConfig,
modifyConfig,
addCluster,
addContext,
setDefaultContext
} from '@kubelib/config'
// load ~/.kube/config
const config = await loadDefaultConfig()
// modify config with modifiers
const newConfig = modifyConfig(config)(
addCluster('foo', {
server: 'https://my-kubernetes-cp.example.com'
}),
addContext('newfoo', {
cluster: 'foo',
user: 'existing-user'
}),
setDefaultContext('newfoo')
)
Authenticate a request with a Kubeconfig
The easiest way is to use the kubeFetch abstraction provided
import { loadDefaultConfig, kubeFetch } from '@kubelib/config'
const fetchNamespaces = () =>
kubeFetch('/api/v1/namespaces', {
headers: {
// You can pass your own config like this:
// kube: { config: myOwnKubeconfig },
'Content-Type': 'application/json',
}
})
fetchNamespaces()
.then(response => response.json())
.then(namespaceList => {
// Logs all namespaces in the cluster
console.log(namespaceList.items)
})
import {
loadDefaultConfig,
createAuthenticateOptions,
authenticate,
getCurrentCluster
} from '@kubelib/config'
const fetchNamespaces = () => {
// Load ~/.kube/config
const config = await loadDefaultConfig()
// Create options for authenticating
const authenticateOptions = createAuthenticateOptions({
config,
// Much more can be configured here!
})
// Get the currently selected cluster from the config
const currentCluster = getCurrentCluster(config)
// fetch stuff from the Kubernetes API
const url = `${currentCluster.server}/api/v1/namespaces`
// Create a request to make with the full URL
const request = new Request(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
// Authenticate the request with the Kubeconfig
const authenticatedRequest = authenticate(request, authenticateOptions)
// Send the request
return authenticateOptions.fetch(authenticatedRequest)
}
fetchNamespaces()
.then(response => response.json())
.then(namespaceList => {
// Logs all namespaces in the cluster
console.log(namespaceList.items)
})
Configuration is done by creating an AuthenticateOptions object and passing it to the authenticate function. You can construct it completely manually or partially
by using createAuthenticateOptions as seen below
import { createAuthenticateOptions } from '@kubelib/config'
const options = createAuthenticateOptions({
/**
* The kubeconfig to authenticate with.
*
* By default it will load the default kubeconfig from `~/.kube/config`.
*/
config: Config
/**
* The authenticator to use.
*
* By default this is a stack of authenticators that supports some
* known authentication methods.
*/
authenticator: Authenticator
/**
* The credential cache to use.
*
* By default this is a memory cache.
*/
credentialCache: CredentialCache
/**
* The http loader to use.
*
* By default this is a stack of http loaders that supports some
* known authentication methods.
*/
httpLoader: HttpLoader
/**
* The file loader to use.
*
* By default this is a stack of file loaders that supports some
* known authentication methods.
*/
fileLoader: FileLoader
/**
* The url loaders to use.
*
* By default this is a loader that supports file: urls
* through `fileLoader` and http: and https: urls through `httpLoader`.
*/
urlLoader: UrlLoader
/**
* The command executor to use.
*
* By default this is a node exec executor.
*/
commandExecutor: CommandExecutor
/**
* The config locator to use.
*
* By default it will yield `~/.kube/config`.
*/
configLocator: ConfigLocator
})
FAQs
## Kubernetes Kubeconfig Client
We found that @kubelib/config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.