Skip to content

Commit

Permalink
Merge pull request #775 from kubernetes-client/master
Browse files Browse the repository at this point in the history
Sync release-0.x branch to HEAD.
  • Loading branch information
brendandburns committed Feb 9, 2022
2 parents 6131bae + 640a72d commit b298b5b
Show file tree
Hide file tree
Showing 20 changed files with 408 additions and 106 deletions.
73 changes: 73 additions & 0 deletions FETCH_MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Fetch migration

Request is fully deprecated requiring us to switch libraries (see [#414](https://github.com/kubernetes-client/javascript/issues/414) for more information). There were a few [different options](https://github.com/kubernetes-client/javascript/issues/414#issuecomment-978031677) for how this swap should be implemented but moving to a new open-api generator option was chosen since this project will acquire the advantages of an up-to-date open-api generator version.

Fetch was selected as the new HTTP request library for this project due to its widespread adoption across the JavaScript ecosystem. Additonally, potential future updates to this project could allow this client to be available with browser JavaScript since fetch is native to the browser ([#165](https://github.com/kubernetes-client/javascript/issues/165)).

[Node-fetch](https://www.npmjs.com/package/node-fetch) is our specific fetch package since it is the largest Node.js compatable implementation. Fetch is not implemented by default in Node.

For more details see the initial discussion ([#754](https://github.com/kubernetes-client/javascript/issues/754)).

## Release cycle

The fetch generator will create breaking changes to this project's API. Consumers will have to make small modifications to their code to upgrade.

We will continue to support the request version of this project for three Kubernetes API versions (~9 months) to give users time to migrate.

Versioning will follow [npm semantic versioning](https://docs.npmjs.com/about-semantic-versioning).

### Old generator (request)

Code will be on the `release-0.x` branch.

- `0.17.x` == old generator, Kubernetes 1.23 API
- `0.18.x` == old generator, Kubernetes 1.24 API
- `0.19.x` == old generator, Kubernetes 1.25 API

Support for old generator stops after 1.25

### New generator (fetch)

Code will be on the `master` branch.

- `1.0.x` == new generator, Kubernetes 1.23 API
- `1.1.x` == new generator, Kubernetes 1.24 API
- `1.2.x` == new generator, Kubernetes 1.25 API
Support for subsequent kubernetes versions continues with the new generator.

## Implementation steps

### Other repositories

- [x] Update [kubernetes-client/gen](https://github.com/kubernetes-client/gen)'s typescript-fetch files to let us pass in the `typescriptThreePlus` config option <sup>[1](https://github.com/OpenAPITools/openapi-generator/issues/9973) [2](https://github.com/OpenAPITools/openapi-generator/issues/3869#issuecomment-584152932)</sub>
- [ ] Update [openapi-generator](https://github.com/OpenAPITools/openapi-generator)'s typescript-fetch flavor to mark parameters as optional if all parameters are optional <sup>[3](https://github.com/OpenAPITools/openapi-generator/issues/6440)</sup>

### Kubernetes-client repository

- [ ] Increment `OPENAPI_GENERATOR_COMMIT` to be [version 5.3.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v5.3.0) (with the optional parameters addition)
- [ ] `npm install node-fetch` to install node-fetch
- [ ] Switch generate-client script to use typescript-fetch
- [ ] Import and inject node-fetch in `src/api.ts` with the following

```typescript
import fetch from 'node-fetch';

// inject node-fetch
if (!globalThis.fetch) {
// @ts-ignore
globalThis.fetch = fetch;
globalThis.Headers = Headers;
globalThis.Request = Request;
globalThis.Response = Response;
}
```

- [ ] Generate api with `npm run generate`
- [ ] Match src/gen/api.ts to new generated layout (it changes slightly)
- [ ] Fix errors in /src folder (due to new api)
- [ ] Fix errors in test (due to new api)
- [ ] Test all features
- [ ] Fix examples (due to new api)
- [ ] Update docs
- [ ] Document breaking changes for users
- [ ] Release initial version (1.0.0)
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

The Javascript clients for Kubernetes is implemented in
[typescript](https://typescriptlang.org), but can be called from either
Javascript or Typescript.
Javascript or Typescript. The client is implemented for server-side use with Node.

For now, the client is implemented for server-side use with node
using the `request` library.

There are future plans to also build a jQuery compatible library but
for now, all of the examples and instructions assume the node client.
The `request` library is currently being swapped to `fetch`. See the [fetch migration docs](./FETCH_MIGRATION.md) for more information and progress.

# Installation

Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kubernetes/client-node",
"version": "0.16.1",
"version": "0.16.3",
"description": "NodeJS client for kubernetes",
"repository": {
"type": "git",
Expand Down Expand Up @@ -69,9 +69,9 @@
"openid-client": "^4.1.1",
"request": "^2.88.0",
"rfc4648": "^1.3.0",
"shelljs": "^0.8.4",
"shelljs": "^0.8.5",
"stream-buffers": "^3.0.2",
"tar": "^6.0.2",
"tar": "^6.1.11",
"tmp-promise": "^3.0.2",
"tslib": "^1.9.3",
"underscore": "^1.9.1",
Expand Down Expand Up @@ -118,5 +118,8 @@
"hooks": {
"pre-push": "npm test && npm run lint"
}
},
"overrides": {
"colors": "1.4.0"
}
}
2 changes: 1 addition & 1 deletion settings
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

# kubernetes-client/gen commit to use for code generation.
export GEN_COMMIT=a3aef4d
export GEN_COMMIT=82c3ff5

# GitHub username/organization to clone kubernetes repo from.
export USERNAME=kubernetes
Expand Down
2 changes: 1 addition & 1 deletion src/gen/.openapi-generator/swagger.json-default.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4dbc0536a9330c99ca0874d9b9d577fd581a1820517a27f20b4dbf5af0f6fb75
a5685a88a8d1b58674feda167bae22437c9580a1664511293db4508c164603d2
7 changes: 4 additions & 3 deletions src/gen/model/v1HTTPGetAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import { RequestFile } from './models';
import { IntOrString } from '../../types';
import { V1HTTPHeader } from './v1HTTPHeader';

/**
Expand All @@ -30,9 +31,9 @@ export class V1HTTPGetAction {
*/
'path'?: string;
/**
* Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'port': object;
'port': IntOrString;
/**
* Scheme to use for connecting to the host. Defaults to HTTP.
*/
Expand All @@ -59,7 +60,7 @@ export class V1HTTPGetAction {
{
"name": "port",
"baseName": "port",
"type": "object"
"type": "IntOrString"
},
{
"name": "scheme",
Expand Down
7 changes: 4 additions & 3 deletions src/gen/model/v1NetworkPolicyPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import { RequestFile } from './models';
import { IntOrString } from '../../types';

/**
* NetworkPolicyPort describes a port to allow traffic on
Expand All @@ -21,9 +22,9 @@ export class V1NetworkPolicyPort {
*/
'endPort'?: number;
/**
* The port on the given protocol. This can either be a numerical or named port on a pod. If this field is not provided, this matches all port names and numbers. If present, only traffic on the specified protocol AND port will be matched.
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'port'?: object;
'port'?: IntOrString;
/**
* The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, this field defaults to TCP.
*/
Expand All @@ -40,7 +41,7 @@ export class V1NetworkPolicyPort {
{
"name": "port",
"baseName": "port",
"type": "object"
"type": "IntOrString"
},
{
"name": "protocol",
Expand Down
13 changes: 7 additions & 6 deletions src/gen/model/v1PodDisruptionBudgetSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
*/

import { RequestFile } from './models';
import { IntOrString } from '../../types';
import { V1LabelSelector } from './v1LabelSelector';

/**
* PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.
*/
export class V1PodDisruptionBudgetSpec {
/**
* An eviction is allowed if at most \"maxUnavailable\" pods selected by \"selector\" are unavailable after the eviction, i.e. even in absence of the evicted pod. For example, one can prevent all voluntary evictions by specifying 0. This is a mutually exclusive setting with \"minAvailable\".
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'maxUnavailable'?: object;
'maxUnavailable'?: IntOrString;
/**
* An eviction is allowed if at least \"minAvailable\" pods selected by \"selector\" will still be available after the eviction, i.e. even in the absence of the evicted pod. So for example you can prevent all voluntary evictions by specifying \"100%\".
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'minAvailable'?: object;
'minAvailable'?: IntOrString;
'selector'?: V1LabelSelector;

static discriminator: string | undefined = undefined;
Expand All @@ -33,12 +34,12 @@ export class V1PodDisruptionBudgetSpec {
{
"name": "maxUnavailable",
"baseName": "maxUnavailable",
"type": "object"
"type": "IntOrString"
},
{
"name": "minAvailable",
"baseName": "minAvailable",
"type": "object"
"type": "IntOrString"
},
{
"name": "selector",
Expand Down
13 changes: 7 additions & 6 deletions src/gen/model/v1RollingUpdateDaemonSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,33 @@
*/

import { RequestFile } from './models';
import { IntOrString } from '../../types';

/**
* Spec to control the desired behavior of daemon set rolling update.
*/
export class V1RollingUpdateDaemonSet {
/**
* The maximum number of nodes with an existing available DaemonSet pod that can have an updated DaemonSet pod during during an update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up to a minimum of 1. Default value is 0. Example: when this is set to 30%, at most 30% of the total number of nodes that should be running the daemon pod (i.e. status.desiredNumberScheduled) can have their a new pod created before the old pod is marked as deleted. The update starts by launching new pods on 30% of nodes. Once an updated pod is available (Ready for at least minReadySeconds) the old DaemonSet pod on that node is marked deleted. If the old pod becomes unavailable for any reason (Ready transitions to false, is evicted, or is drained) an updated pod is immediatedly created on that node without considering surge limits. Allowing surge implies the possibility that the resources consumed by the daemonset on any given node can double if the readiness check fails, and so resource intensive daemonsets should take into account that they may cause evictions during disruption. This is beta field and enabled/disabled by DaemonSetUpdateSurge feature gate.
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'maxSurge'?: object;
'maxSurge'?: IntOrString;
/**
* The maximum number of DaemonSet pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of total number of DaemonSet pods at the start of the update (ex: 10%). Absolute number is calculated from percentage by rounding up. This cannot be 0 if MaxSurge is 0 Default value is 1. Example: when this is set to 30%, at most 30% of the total number of nodes that should be running the daemon pod (i.e. status.desiredNumberScheduled) can have their pods stopped for an update at any given time. The update starts by stopping at most 30% of those DaemonSet pods and then brings up new DaemonSet pods in their place. Once the new pods are available, it then proceeds onto other DaemonSet pods, thus ensuring that at least 70% of original number of DaemonSet pods are available at all times during the update.
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'maxUnavailable'?: object;
'maxUnavailable'?: IntOrString;

static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "maxSurge",
"baseName": "maxSurge",
"type": "object"
"type": "IntOrString"
},
{
"name": "maxUnavailable",
"baseName": "maxUnavailable",
"type": "object"
"type": "IntOrString"
} ];

static getAttributeTypeMap() {
Expand Down
13 changes: 7 additions & 6 deletions src/gen/model/v1RollingUpdateDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,33 @@
*/

import { RequestFile } from './models';
import { IntOrString } from '../../types';

/**
* Spec to control the desired behavior of rolling update.
*/
export class V1RollingUpdateDeployment {
/**
* The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to 25%. Example: when this is set to 30%, the new ReplicaSet can be scaled up immediately when the rolling update starts, such that the total number of old and new pods do not exceed 130% of desired pods. Once old pods have been killed, new ReplicaSet can be scaled up further, ensuring that total number of pods running at any time during the update is at most 130% of desired pods.
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'maxSurge'?: object;
'maxSurge'?: IntOrString;
/**
* The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to 25%. Example: when this is set to 30%, the old ReplicaSet can be scaled down to 70% of desired pods immediately when the rolling update starts. Once new pods are ready, old ReplicaSet can be scaled down further, followed by scaling up the new ReplicaSet, ensuring that the total number of pods available at all times during the update is at least 70% of desired pods.
* IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number.
*/
'maxUnavailable'?: object;
'maxUnavailable'?: IntOrString;

static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "maxSurge",
"baseName": "maxSurge",
"type": "object"
"type": "IntOrString"
},
{
"name": "maxUnavailable",
"baseName": "maxUnavailable",
"type": "object"
"type": "IntOrString"
} ];

static getAttributeTypeMap() {
Expand Down
Loading

0 comments on commit b298b5b

Please sign in to comment.