### Configure Pod Startup Probe in Kubernetes (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/BatchV1Api.md This example demonstrates how to define a startup probe for a Kubernetes pod. It includes configurations for exec, gRPC, HTTP GET, and TCP socket probes, along with timing parameters like initial delay, period, and timeout. This helps ensure your application starts correctly before it receives traffic. ```javascript { startupProbe: { exec: { command: [ "command_example", ], }, failureThreshold: 1, grpc: { port: 1, service: "service_example", }, httpGet: { host: "host_example", httpHeaders: [ { name: "name_example", value: "value_example", }, ], path: "path_example", port: "port_example", scheme: "scheme_example", }, initialDelaySeconds: 1, periodSeconds: 1, successThreshold: 1, tcpSocket: { host: "host_example", port: "port_example", }, terminationGracePeriodSeconds: 1, timeoutSeconds: 1, }, } ``` -------------------------------- ### Configure Container Lifecycle Hooks (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/BatchV1Api.md This example shows how to define lifecycle hooks for a container, specifically the `postStart` hook using an HTTP GET request. This allows you to execute commands or make HTTP calls when a container starts. Dependencies include Kubernetes API object definitions. ```javascript { lifecycle: { postStart: { exec: { command: [ "command_example", ], }, httpGet: { host: "host_example", httpHeaders: [ { name: "name_example", value: "value_example", }, ], }, }, }, } ``` -------------------------------- ### List and Watch Resources with Initial Events (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/DiscoveryV1Api.md Demonstrates how to list Kubernetes resources and initiate a watch stream. It includes options for sending initial events, setting timeouts, and specifying resource version matching. The `sendInitialEvents` option requires `resourceVersionMatch` to be set. ```javascript const k8s = require('@kubernetes/client-node'); const config = new k8s.KubeConfig(); config.loadFromDefault(); const apiInstance = config.makeApiClient(k8s.CoreV1Api); const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced // to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment // when request started being processed. // - `resourceVersionMatch` set to any other value or unset // Invalid error is returned. Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listNamespacedEndpointSlice(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### List Device Class with Watch and Initial Events Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/ResourceV1beta1Api.md This example demonstrates how to list device classes using the `listDeviceClass` method. It includes options for watching for changes (`watch: true`), sending initial synthetic events to represent the current state (`sendInitialEvents: true`), and setting a timeout for the request (`timeoutSeconds: 1`). The `sendInitialEvents` option requires `resourceVersionMatch` to be set. ```APIDOC ## POST /api/v1/deviceclasses ### Description Lists device classes with options to watch for changes and send initial events. This endpoint is useful for monitoring the state of device classes in the Kubernetes cluster. ### Method GET ### Endpoint /api/v1/deviceclasses ### Query Parameters - **sendInitialEvents** (boolean) - Optional - If true, the watch stream will begin with synthetic events representing the current state of objects. Requires `resourceVersionMatch` to be set. - **timeoutSeconds** (integer) - Optional - Limits the duration of the list/watch call. - **watch** (boolean) - Optional - If true, watches for changes to the described resources and returns them as a stream of notifications. - **resourceVersionMatch** (string) - Required if `sendInitialEvents` is true - Specifies how to match the resource version. Supported values include 'NotOlderThan'. ### Request Example ```javascript const request = { sendInitialEvents: true, timeoutSeconds: 1, watch: true, resourceVersionMatch: 'NotOlderThan' }; const data = await apiInstance.listDeviceClass(request); console.log('API called successfully. Returned data:', data); ``` ### Response #### Success Response (200) - **items** (array) - A list of device class objects. - **metadata** (object) - Metadata about the list, including resource version. #### Response Example ```json { "kind": "List", "apiVersion": "v1", "metadata": { "selfLink": "/api/v1/deviceclasses", "resourceVersion": "12345" }, "items": [ { "apiVersion": "device.example.com/v1alpha1", "kind": "DeviceClass", "metadata": { "name": "example-device-class", "creationTimestamp": "2023-10-27T10:00:00Z" }, "spec": { "provider": "aws", "region": "us-east-1" } } ] } ``` ``` -------------------------------- ### Install Project Dependencies with NPM Source: https://github.com/kubernetes-client/javascript/blob/main/CONTRIBUTING.md Installs all project dependencies listed in the package.json file using NPM. This is a prerequisite for starting development. ```bash npm install ``` -------------------------------- ### List Pods with Initial Events and Watch Enabled (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/CertificatesV1beta1Api.md Demonstrates how to list pods in a namespace while enabling initial events and watching for changes. This configuration requires `resourceVersionMatch` to be set and ensures data consistency by synchronizing to a specific resource version. ```javascript const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced to a `resourceVersion` at least as fresh as the one provided by the ListOptions. If `resourceVersion` is unset, this is interpreted as "consistent read" and the bookmark event is send when the state is synced at least to the moment when request started being processed. // - `resourceVersionMatch` set to any other value or unset Invalid error is returned. Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listNamespacedPodCertificateRequest(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### GET /apis/apiextensions.k8s.io/v1/customresourcedefinitions Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/SchedulingV1alpha1Api.md Retrieves a list of all Custom Resource Definitions (CRDs) available in the cluster. This endpoint is useful for discovering custom resources that have been installed. ```APIDOC ## GET /apis/apiextensions.k8s.io/v1/customresourcedefinitions ### Description Retrieves a list of all Custom Resource Definitions (CRDs) available in the cluster. This endpoint is useful for discovering custom resources that have been installed. ### Method GET ### Endpoint /apis/apiextensions.k8s.io/v1/customresourcedefinitions ### Parameters #### Query Parameters - **pretty** (string) - Optional - If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). - **continue** (string) - Optional - The continue option should be set when retrieving a list that is not complete. For example, if the API call returned 10 items from a list of 100, and the value of the continue field is "abc", then a subsequent GET request should include continue="abc" in the query to retrieve the next batch of objects. - **fieldSelector** (string) - Optional - A selector to restrict the list of returned objects by their fields. Supported syntax - string "key", where key is a JSON path in the object. Currently only key that supports equality restriction is that of type string. - **labelSelector** (string) - Optional - A selector to restrict the list of returned objects by their labels. Supported syntax - LabelSelectorRequirement string (e.g. name%3D=foo-bar). Multiple label requirements are concatenated with commas. - **limit** (integer) - Optional - limit is a maximum number of responses to return for a list call. If more items in the collection signify that there's more results to be retrieved, the server will set the continue field on the list metadata to the value of the continue field on the returned list objects. - **resourceVersion** (string) - Optional - resourceVersion sets a version number for to that the result should be over. If the requested resourceVersion is in the past, any returned objects will be identical to those returned as of that version. Otherwise, if resourceVersion is not specified, the returned objects will be up to date as of the instance being accessed on the controller and may be updated before the client reads them. - **timeoutSeconds** (integer) - Optional - Timeout for the list request in seconds. The server might return partial results if the timeout is reached before all objects are returned. ### Response #### Success Response (200) - **kind** (string) - Kind of the resource, typically "CustomResourceDefinitionList". - **apiVersion** (string) - API version of the resource, typically "apiextensions.k8s.io/v1". - **metadata** (object) - Standard list metadata. - **items** (array) - An array of CustomResourceDefinition objects. - **item** (object) - A CustomResourceDefinition object. - **metadata** (object) - Standard object's metadata. - **spec** (object) - Spec for the CustomResourceDefinition. - **status** (object) - Status for the CustomResourceDefinition. #### Response Example ```json { "kind": "CustomResourceDefinitionList", "apiVersion": "apiextensions.k8s.io/v1", "metadata": { "selfLink": "/apis/apiextensions.k8s.io/v1/customresourcedefinitions", "resourceVersion": "12345" }, "items": [ { "metadata": { "name": "crontabs.stable.example.com" }, "spec": { "group": "stable.example.com", "versions": [ { "name": "v1", "served": true, "storage": true, "schema": { "openAPIV3Schema": { "type": "object", "properties": { "spec": { "type": "object", "properties": { "cronSpec": { "type": "string" }, "image": { "type": "string" }, "replicas": { "type": "integer" } } } } } } } ], "names": { "plural": "crontabs", "singular": "crontab", "kind": "CronTab", "shortNames": [ "ct" ] }, "scope": "Namespaced" } } ] } ``` ``` -------------------------------- ### List Resources with Watch and Initial Events (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/StorageV1beta1Api.md Demonstrates how to list Kubernetes resources and initiate a watch stream. It includes configuration for sending initial events and matching resource versions, ensuring data consistency. The `sendInitialEvents` option requires `resourceVersionMatch` to be set. ```javascript const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment when request started being processed. // - `resourceVersionMatch` set to any other value or unset Invalid error is returned. // Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listVolumeAttributesClass(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### List Resources with Watch and Initial Events (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/AdmissionregistrationV1beta1Api.md Demonstrates how to list resources from the Kubernetes API and simultaneously watch for changes. It includes advanced options like `sendInitialEvents` and `resourceVersionMatch` for controlling the watch stream's behavior, and `timeoutSeconds` for setting a call duration limit. This example requires `resourceVersionMatch` to be set when `sendInitialEvents` is enabled. ```javascript const k8s = require('@kubernetes/client-node'); const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment when request started being processed. // - `resourceVersionMatch` set to any other value or unset Invalid error is returned. // Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const config = new k8s.KubeConfig(); config.loadFromDefault(); const k8sApi = config.makeApiClient(k8s.CoreV1Api); async function listAndWatchResources() { try { const res = await k8sApi.listMutatingAdmissionPolicy(request); console.log('API called successfully. Returned data:', res.body); } catch (err) { console.error('Error calling API:', err); } } listAndWatchResources(); ``` -------------------------------- ### Configure Flocker Volume in Kubernetes JavaScript Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/StorageV1Api.md This example shows how to configure a Flocker volume for a Kubernetes PersistentVolume. It includes dataset name and UUID. Requires Flocker to be installed and configured. ```javascript { flocker: { datasetName: "datasetName_example", datasetUUID: "datasetUUID_example" } } ``` -------------------------------- ### List Resources with Initial Events (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/AdmissionregistrationV1Api.md Demonstrates how to list Kubernetes resources using the client library, enabling the `sendInitialEvents` option. This option, when used with `watch=true`, provides synthetic events for the current state before streaming live changes. It requires `resourceVersionMatch` to be set. ```javascript const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment when request started being processed. // - `resourceVersionMatch` set to any other value or unset // Invalid error is returned. // Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listValidatingAdmissionPolicy(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### Get API Resources using TypeScript Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/NetworkingV1Api.md Retrieves a list of available API resources from the Kubernetes cluster. This function does not require any parameters. It returns a V1APIResourceList object. Ensure you have the Kubernetes client library installed and configured. ```typescript import { createConfiguration, NetworkingV1Api } from ''; const configuration = createConfiguration(); const apiInstance = new NetworkingV1Api(configuration); const request = {}; const data = await apiInstance.getAPIResources(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### Read APIService - TypeScript Example Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/ApiregistrationV1Api.md Demonstrates how to read a specific APIService using the Kubernetes client for JavaScript. It shows the import statements, configuration setup, API instance creation, and how to call the readAPIService method with optional parameters like 'name' and 'pretty'. ```typescript import { createConfiguration, ApiregistrationV1Api } from ''; import type { ApiregistrationV1ApiReadAPIServiceRequest } from ''; const configuration = createConfiguration(); const apiInstance = new ApiregistrationV1Api(configuration); const request: ApiregistrationV1ApiReadAPIServiceRequest = { // name of the APIService name: "name_example", // If \'true\', then the output is pretty printed. Defaults to \'false\' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). (optional) pretty: "pretty_example", }; const data = await apiInstance.readAPIService(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### List Devices with Initial Events and Watch in JavaScript Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/ResourceV1Api.md Demonstrates how to list devices while enabling initial events and watching for changes. This configuration requires `resourceVersionMatch` to be set. The `sendInitialEvents` option ensures that the watch stream starts with synthetic events representing the current state of objects. ```javascript const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment when request started being processed. // - `resourceVersionMatch` set to any other value or unset Invalid error is returned. // Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listDeviceClass(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### Get API Group Information (TypeScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/EventsApi.md Retrieves information about the Kubernetes API group for events. This method requires no parameters and returns a V1APIGroup object upon successful execution. Ensure the Kubernetes client library is installed and configured. ```typescript import { createConfiguration, EventsApi } from ''; const configuration = createConfiguration(); const apiInstance = new EventsApi(configuration); const request = {}; const data = await apiInstance.getAPIGroup(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### List Resources with Watch and Initial Events (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/DiscoveryV1Api.md This example demonstrates how to list Kubernetes resources across all namespaces using the JavaScript client. It configures the request to enable watching for changes, send initial events to reflect the current state, and specifies a timeout. The `sendInitialEvents` option requires `resourceVersionMatch` to be set. ```javascript const k8s = require('@kubernetes/client-node'); const config = new k8s.KubeConfig(); config.loadFromDefault(); const apiInstance = new k8s.CoreV1Api(config); const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced // to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment // when request started being processed. // - `resourceVersionMatch` set to any other value or unset // Invalid error is returned. Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listEndpointSliceForAllNamespaces(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### List Resources with Watch and Initial Events (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/CoordinationV1alpha2Api.md Demonstrates how to list Kubernetes resources across all namespaces and initiate a watch stream. It configures options such as `sendInitialEvents`, `timeoutSeconds`, and `watch`. The `sendInitialEvents` option requires `resourceVersionMatch` to be set. ```javascript const k8s = require('@kubernetes/client-node'); const config = new k8s.KubeConfig(); config.loadFromDefault(); const apiInstance = config.makeApiClient(k8s.CoreV1Api); const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced // to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment // when request started being processed. // - `resourceVersionMatch` set to any other value or unset // Invalid error is returned. Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listLeaseCandidateForAllNamespaces(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### Configure Container Image and Lifecycle (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/BatchV1Api.md Specifies the container image, pull policy, and lifecycle hooks like postStart and preStop. Lifecycle hooks can execute commands, perform HTTP GET requests, or initiate a sleep before the container starts or stops. ```javascript { image: "image_example", imagePullPolicy: "imagePullPolicy_example", lifecycle: { postStart: { exec: { command: [ "command_example", ], }, httpGet: { host: "host_example", httpHeaders: [ { name: "name_example", value: "value_example", }, ], path: "path_example", port: "port_example", scheme: "scheme_example", }, sleep: { seconds: 1, }, tcpSocket: { host: "host_example", port: "port_example", }, }, preStop: { exec: { command: [ "command_example", ], }, httpGet: { host: "host_example", httpHeaders: [ { name: "name_example", value: "value_example", }, ], path: "path_example", port: "port_example", scheme: "scheme_example", }, sleep: { seconds: 1, }, tcpSocket: { host: "host_example", port: "port_example", }, }, stopSignal: "stopSignal_example", }, } ``` -------------------------------- ### List Resources with Watch and Initial Events (JavaScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/ResourceV1Api.md Demonstrates how to list Kubernetes resources and initiate a watch stream. It includes the `sendInitialEvents` option, which provides synthetic events for the current state of objects, followed by a bookmark. This option requires `resourceVersionMatch` to be set. ```javascript const request = { // `sendInitialEvents=true` may be set together with `watch=true`. In that case, the watch stream will begin with synthetic events to produce the current state of objects in the collection. Once all such events have been sent, a synthetic "Bookmark" event will be sent. The bookmark will report the ResourceVersion (RV) corresponding to the set of objects, and be marked with `"k8s.io/initial-events-end": "true"` annotation. Afterwards, the watch stream will proceed as usual, sending watch events corresponding to changes (subsequent to the RV) to objects watched. When `sendInitialEvents` option is set, we require `resourceVersionMatch` option to also be set. The semantic of the watch request is as following: // - `resourceVersionMatch` = NotOlderThan is interpreted as "data at least as new as the provided `resourceVersion`" // and the bookmark event is send when the state is synced to a `resourceVersion` at least as fresh as the one provided by the ListOptions. // If `resourceVersion` is unset, this is interpreted as "consistent read" and the // bookmark event is send when the state is synced at least to the moment when request started being processed. // - `resourceVersionMatch` set to any other value or unset Invalid error is returned. // Defaults to true if `resourceVersion=""` or `resourceVersion="0"` (for backward compatibility reasons) and to false otherwise. (optional) sendInitialEvents: true, // Timeout for the list/watch call. This limits the duration of the call, regardless of any activity or inactivity. (optional) timeoutSeconds: 1, // Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion. (optional) watch: true, }; const data = await apiInstance.listNamespacedResourceClaimTemplate(request); console.log('API called successfully. Returned data:', data); ``` -------------------------------- ### List Endpoint Slices (TypeScript) Source: https://github.com/kubernetes-client/javascript/blob/main/src/gen/docs/DiscoveryV1Api.md This snippet shows how to instantiate the DiscoveryV1Api and call the listEndpointSliceForAllNamespaces method. It includes examples of common query parameters like allowWatchBookmarks, continue, fieldSelector, labelSelector, limit, pretty, resourceVersion, and resourceVersionMatch for filtering and pagination. Ensure the Kubernetes client library is installed and configured. ```typescript import { createConfiguration, DiscoveryV1Api } from '@kubernetes/client-node'; import type { DiscoveryV1ApiListEndpointSliceForAllNamespacesRequest } from '@kubernetes/client-node'; const configuration = createConfiguration(); const apiInstance = new DiscoveryV1Api(configuration); const request: DiscoveryV1ApiListEndpointSliceForAllNamespacesRequest = { allowWatchBookmarks: true, _continue: "continue_example", fieldSelector: "fieldSelector_example", labelSelector: "labelSelector_example", limit: 1, pretty: "pretty_example", resourceVersion: "resourceVersion_example", resourceVersionMatch: "resourceVersionMatch_example" }; apiInstance.listEndpointSliceForAllNamespaces(request) .then(response => { console.log('Successfully listed endpoint slices:', response.body); }) .catch(error => { console.error('Error listing endpoint slices:', error); }); ```