Skip to content

Commit b298b5b

Browse files
Merge pull request #775 from kubernetes-client/master
Sync release-0.x branch to HEAD.
2 parents 6131bae + 640a72d commit b298b5b

20 files changed

+408
-106
lines changed

FETCH_MIGRATION.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Fetch migration
2+
3+
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.
4+
5+
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)).
6+
7+
[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.
8+
9+
For more details see the initial discussion ([#754](https://github.com/kubernetes-client/javascript/issues/754)).
10+
11+
## Release cycle
12+
13+
The fetch generator will create breaking changes to this project's API. Consumers will have to make small modifications to their code to upgrade.
14+
15+
We will continue to support the request version of this project for three Kubernetes API versions (~9 months) to give users time to migrate.
16+
17+
Versioning will follow [npm semantic versioning](https://docs.npmjs.com/about-semantic-versioning).
18+
19+
### Old generator (request)
20+
21+
Code will be on the `release-0.x` branch.
22+
23+
- `0.17.x` == old generator, Kubernetes 1.23 API
24+
- `0.18.x` == old generator, Kubernetes 1.24 API
25+
- `0.19.x` == old generator, Kubernetes 1.25 API
26+
27+
Support for old generator stops after 1.25
28+
29+
### New generator (fetch)
30+
31+
Code will be on the `master` branch.
32+
33+
- `1.0.x` == new generator, Kubernetes 1.23 API
34+
- `1.1.x` == new generator, Kubernetes 1.24 API
35+
- `1.2.x` == new generator, Kubernetes 1.25 API
36+
Support for subsequent kubernetes versions continues with the new generator.
37+
38+
## Implementation steps
39+
40+
### Other repositories
41+
42+
- [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>
43+
- [ ] 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>
44+
45+
### Kubernetes-client repository
46+
47+
- [ ] 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)
48+
- [ ] `npm install node-fetch` to install node-fetch
49+
- [ ] Switch generate-client script to use typescript-fetch
50+
- [ ] Import and inject node-fetch in `src/api.ts` with the following
51+
52+
```typescript
53+
import fetch from 'node-fetch';
54+
55+
// inject node-fetch
56+
if (!globalThis.fetch) {
57+
// @ts-ignore
58+
globalThis.fetch = fetch;
59+
globalThis.Headers = Headers;
60+
globalThis.Request = Request;
61+
globalThis.Response = Response;
62+
}
63+
```
64+
65+
- [ ] Generate api with `npm run generate`
66+
- [ ] Match src/gen/api.ts to new generated layout (it changes slightly)
67+
- [ ] Fix errors in /src folder (due to new api)
68+
- [ ] Fix errors in test (due to new api)
69+
- [ ] Test all features
70+
- [ ] Fix examples (due to new api)
71+
- [ ] Update docs
72+
- [ ] Document breaking changes for users
73+
- [ ] Release initial version (1.0.0)

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77

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

12-
For now, the client is implemented for server-side use with node
13-
using the `request` library.
14-
15-
There are future plans to also build a jQuery compatible library but
16-
for now, all of the examples and instructions assume the node client.
12+
The `request` library is currently being swapped to `fetch`. See the [fetch migration docs](./FETCH_MIGRATION.md) for more information and progress.
1713

1814
# Installation
1915

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kubernetes/client-node",
3-
"version": "0.16.1",
3+
"version": "0.16.3",
44
"description": "NodeJS client for kubernetes",
55
"repository": {
66
"type": "git",
@@ -69,9 +69,9 @@
6969
"openid-client": "^4.1.1",
7070
"request": "^2.88.0",
7171
"rfc4648": "^1.3.0",
72-
"shelljs": "^0.8.4",
72+
"shelljs": "^0.8.5",
7373
"stream-buffers": "^3.0.2",
74-
"tar": "^6.0.2",
74+
"tar": "^6.1.11",
7575
"tmp-promise": "^3.0.2",
7676
"tslib": "^1.9.3",
7777
"underscore": "^1.9.1",
@@ -118,5 +118,8 @@
118118
"hooks": {
119119
"pre-push": "npm test && npm run lint"
120120
}
121+
},
122+
"overrides": {
123+
"colors": "1.4.0"
121124
}
122125
}

settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

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

2020
# GitHub username/organization to clone kubernetes repo from.
2121
export USERNAME=kubernetes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4dbc0536a9330c99ca0874d9b9d577fd581a1820517a27f20b4dbf5af0f6fb75
1+
a5685a88a8d1b58674feda167bae22437c9580a1664511293db4508c164603d2

src/gen/model/v1HTTPGetAction.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import { RequestFile } from './models';
14+
import { IntOrString } from '../../types';
1415
import { V1HTTPHeader } from './v1HTTPHeader';
1516

1617
/**
@@ -30,9 +31,9 @@ export class V1HTTPGetAction {
3031
*/
3132
'path'?: string;
3233
/**
33-
* 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.
34+
* 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.
3435
*/
35-
'port': object;
36+
'port': IntOrString;
3637
/**
3738
* Scheme to use for connecting to the host. Defaults to HTTP.
3839
*/
@@ -59,7 +60,7 @@ export class V1HTTPGetAction {
5960
{
6061
"name": "port",
6162
"baseName": "port",
62-
"type": "object"
63+
"type": "IntOrString"
6364
},
6465
{
6566
"name": "scheme",

src/gen/model/v1NetworkPolicyPort.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import { RequestFile } from './models';
14+
import { IntOrString } from '../../types';
1415

1516
/**
1617
* NetworkPolicyPort describes a port to allow traffic on
@@ -21,9 +22,9 @@ export class V1NetworkPolicyPort {
2122
*/
2223
'endPort'?: number;
2324
/**
24-
* 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.
25+
* 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.
2526
*/
26-
'port'?: object;
27+
'port'?: IntOrString;
2728
/**
2829
* The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, this field defaults to TCP.
2930
*/
@@ -40,7 +41,7 @@ export class V1NetworkPolicyPort {
4041
{
4142
"name": "port",
4243
"baseName": "port",
43-
"type": "object"
44+
"type": "IntOrString"
4445
},
4546
{
4647
"name": "protocol",

src/gen/model/v1PodDisruptionBudgetSpec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@
1111
*/
1212

1313
import { RequestFile } from './models';
14+
import { IntOrString } from '../../types';
1415
import { V1LabelSelector } from './v1LabelSelector';
1516

1617
/**
1718
* PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.
1819
*/
1920
export class V1PodDisruptionBudgetSpec {
2021
/**
21-
* 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\".
22+
* 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.
2223
*/
23-
'maxUnavailable'?: object;
24+
'maxUnavailable'?: IntOrString;
2425
/**
25-
* 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%\".
26+
* 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.
2627
*/
27-
'minAvailable'?: object;
28+
'minAvailable'?: IntOrString;
2829
'selector'?: V1LabelSelector;
2930

3031
static discriminator: string | undefined = undefined;
@@ -33,12 +34,12 @@ export class V1PodDisruptionBudgetSpec {
3334
{
3435
"name": "maxUnavailable",
3536
"baseName": "maxUnavailable",
36-
"type": "object"
37+
"type": "IntOrString"
3738
},
3839
{
3940
"name": "minAvailable",
4041
"baseName": "minAvailable",
41-
"type": "object"
42+
"type": "IntOrString"
4243
},
4344
{
4445
"name": "selector",

src/gen/model/v1RollingUpdateDaemonSet.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,33 @@
1111
*/
1212

1313
import { RequestFile } from './models';
14+
import { IntOrString } from '../../types';
1415

1516
/**
1617
* Spec to control the desired behavior of daemon set rolling update.
1718
*/
1819
export class V1RollingUpdateDaemonSet {
1920
/**
20-
* 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.
21+
* 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.
2122
*/
22-
'maxSurge'?: object;
23+
'maxSurge'?: IntOrString;
2324
/**
24-
* 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.
25+
* 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.
2526
*/
26-
'maxUnavailable'?: object;
27+
'maxUnavailable'?: IntOrString;
2728

2829
static discriminator: string | undefined = undefined;
2930

3031
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
3132
{
3233
"name": "maxSurge",
3334
"baseName": "maxSurge",
34-
"type": "object"
35+
"type": "IntOrString"
3536
},
3637
{
3738
"name": "maxUnavailable",
3839
"baseName": "maxUnavailable",
39-
"type": "object"
40+
"type": "IntOrString"
4041
} ];
4142

4243
static getAttributeTypeMap() {

src/gen/model/v1RollingUpdateDeployment.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,33 @@
1111
*/
1212

1313
import { RequestFile } from './models';
14+
import { IntOrString } from '../../types';
1415

1516
/**
1617
* Spec to control the desired behavior of rolling update.
1718
*/
1819
export class V1RollingUpdateDeployment {
1920
/**
20-
* 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.
21+
* 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.
2122
*/
22-
'maxSurge'?: object;
23+
'maxSurge'?: IntOrString;
2324
/**
24-
* 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.
25+
* 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.
2526
*/
26-
'maxUnavailable'?: object;
27+
'maxUnavailable'?: IntOrString;
2728

2829
static discriminator: string | undefined = undefined;
2930

3031
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
3132
{
3233
"name": "maxSurge",
3334
"baseName": "maxSurge",
34-
"type": "object"
35+
"type": "IntOrString"
3536
},
3637
{
3738
"name": "maxUnavailable",
3839
"baseName": "maxUnavailable",
39-
"type": "object"
40+
"type": "IntOrString"
4041
} ];
4142

4243
static getAttributeTypeMap() {

0 commit comments

Comments
 (0)