Skip to content

Commit efbe845

Browse files
authored
feat: suggest to deploy manifests when ip changed (#1092)
* feat: suggest to deploy manifests when ip changed * fix circular * feat: improve provider.yaml (#1094) * feat: improvements for provider yaml * Apply automatic changes * some fixes * fix and use latest * Apply automatic changes * fix * fix * remove deprecation warning from tests as well --------- Co-authored-by: shamsartem <[email protected]> --------- Co-authored-by: shamsartem <[email protected]>
1 parent e6955df commit efbe845

File tree

22 files changed

+881
-862
lines changed

22 files changed

+881
-862
lines changed

packages/cli/package/bin/dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S node --no-warnings --import tsx
1+
#!/usr/bin/env -S node --no-warnings --no-deprecation --import tsx
22

33
/**
44
* Fluence CLI

packages/cli/package/bin/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S node --no-warnings
1+
#!/usr/bin/env -S node --no-warnings --no-deprecation
22

33
/**
44
* Fluence CLI

packages/cli/package/docs/configs/provider.md

Lines changed: 57 additions & 133 deletions
Large diffs are not rendered by default.

packages/cli/package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"whatwg-url": "^14.0.0"
5757
},
5858
"dependencies": {
59-
"@fluencelabs/deal-ts-clients": "0.23.2-add-dc-to-subgraph-afdd94a-7473-1.0",
59+
"@fluencelabs/deal-ts-clients": "0.23.2-feat-marketplace-v2-resources-eb89b78-7511-1.0",
6060
"@kubernetes/client-node": "github:fluencelabs/kubernetes-client-javascript#e72ee00a52fec4eb4a8327632895d888ee504f4d",
6161
"@libp2p/crypto": "4.0.1",
6262
"@libp2p/peer-id-factory": "4.0.5",

packages/cli/package/src/commands/provider/deploy.ts

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import { readFile } from "node:fs/promises";
19-
import { isAbsolute, resolve } from "node:path";
20-
21-
import type k8s from "@kubernetes/client-node";
22-
2318
import { BaseCommand } from "../../baseCommand.js";
24-
import { commandObj } from "../../lib/commandObj.js";
2519
import { CHAIN_FLAGS, PEER_AND_OFFER_NAMES_FLAGS } from "../../lib/const.js";
2620
import { initCli } from "../../lib/lifeCycle.js";
27-
import { projectRootDir } from "../../lib/paths.js";
28-
import { resolveComputePeersByNames } from "../../lib/resolveComputePeersByNames.js";
21+
import { deployManifests } from "../../lib/manifestsDeploy.js";
2922

3023
export default class Deploy extends BaseCommand<typeof Deploy> {
3124
static override description = "Deploy manifests";
@@ -36,89 +29,6 @@ export default class Deploy extends BaseCommand<typeof Deploy> {
3629
};
3730
async run(): Promise<void> {
3831
const { flags } = await initCli(this, await this.parse(Deploy));
39-
const computePeers = await resolveComputePeersByNames(flags);
40-
41-
for (const { kubeconfigPath, name, manifestPath } of computePeers) {
42-
await kubectlApply(kubeconfigPath, manifestPath, name);
43-
}
44-
}
45-
}
46-
47-
/**
48-
* This function comes from https://github.com/kubernetes-client/javascript
49-
* Replicate the functionality of `kubectl apply`. That is, create the resources defined in the `specFile` if they do
50-
* not exist, patch them if they do exist.
51-
*
52-
* @param specPath File system path to a YAML Kubernetes spec.
53-
* @return Array of resources created
54-
*/
55-
async function kubectlApply(
56-
kubeconfigPath: string,
57-
specPath: string,
58-
peerName: string,
59-
): Promise<k8s.KubernetesObject[]> {
60-
const kubeconfigAbsolutePath = isAbsolute(kubeconfigPath)
61-
? kubeconfigPath
62-
: resolve(projectRootDir, kubeconfigPath);
63-
64-
commandObj.log(
65-
`Applying manifest for computePeer ${peerName}\nKubeconfig: ${kubeconfigAbsolutePath}\nManifest: ${specPath}`,
66-
);
67-
68-
const k8s = await import("@kubernetes/client-node");
69-
const kc = new k8s.KubeConfig(kubeconfigAbsolutePath);
70-
kc.loadFromFile(kubeconfigAbsolutePath);
71-
72-
/* eslint-disable */
73-
const client = k8s.KubernetesObjectApi.makeApiClient(kc);
74-
75-
const specString = await readFile(specPath, "utf8");
76-
const specs: k8s.KubernetesObject[] = k8s.loadAllYaml(specString);
77-
78-
const validSpecs = specs.filter((s) => {
79-
return s && s.kind && s.metadata;
80-
});
81-
82-
const created: k8s.KubernetesObject[] = [];
83-
84-
for (const spec of validSpecs) {
85-
// this is to convince the old version of TypeScript that metadata exists even though we already filtered specs
86-
// without metadata out
87-
spec.metadata = spec.metadata || {};
88-
spec.metadata.annotations = spec.metadata.annotations || {};
89-
90-
delete spec.metadata.annotations[
91-
"kubectl.kubernetes.io/last-applied-configuration"
92-
];
93-
94-
spec.metadata.annotations[
95-
"kubectl.kubernetes.io/last-applied-configuration"
96-
] = JSON.stringify(spec);
97-
98-
try {
99-
// try to get the resource, if it does not exist an error will be thrown and we will end up in the catch
100-
// block.
101-
// @ts-expect-error
102-
await client.read(spec);
103-
// we got the resource, so it exists, so patch it
104-
//
105-
// Note that this could fail if the spec refers to a custom resource. For custom resources you may need
106-
// to specify a different patch merge strategy in the content-type header.
107-
//
108-
// See: https://github.com/kubernetes/kubernetes/issues/97423
109-
const response = await client.patch(spec);
110-
created.push(response.body);
111-
} catch (err) {
112-
// if the resource doesnt exist then create it
113-
if (err instanceof k8s.HttpError && err.statusCode === 404) {
114-
const response = await client.create(spec);
115-
created.push(response.body);
116-
} else {
117-
throw err;
118-
}
119-
}
32+
await deployManifests({ flags });
12033
}
121-
122-
return created;
123-
/* eslint-enable */
12434
}

packages/cli/package/src/commands/provider/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class Info extends BaseCommand<typeof Info> {
4747

4848
async run(): Promise<void> {
4949
const { flags } = await initCli(this, await this.parse(Info));
50-
const computePeers = await resolveComputePeersByNames(flags);
50+
const computePeers = await resolveComputePeersByNames({ flags });
5151

5252
const infoToPrint = {
5353
...(await formatProvidersInfo(

packages/cli/package/src/lib/chain/commitment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ async function getCommitmentsIds(
243243
);
244244
}
245245

246-
return getComputePeersWithCCIds(await resolveComputePeersByNames(flags));
246+
return getComputePeersWithCCIds(await resolveComputePeersByNames({ flags }));
247247
}
248248

249249
export async function createCommitments(flags: PeerAndOfferNameFlags) {
250-
const computePeers = await resolveComputePeersByNames(flags);
250+
const computePeers = await resolveComputePeersByNames({ flags });
251251
const { contracts } = await getContracts();
252252
const precision = await contracts.diamond.precision();
253253
const { ZeroAddress } = await import("ethers");

packages/cli/package/src/lib/chain/distributeToNox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { fltFormatWithSymbol, fltParse } from "./currencies.js";
3838
export async function distributeToPeer(
3939
flags: { amount?: string | undefined } & PeerAndOfferNameFlags,
4040
) {
41-
const computePeers = await resolveComputePeersByNames(flags);
41+
const computePeers = await resolveComputePeersByNames({ flags });
4242

4343
const amount =
4444
flags.amount ??
@@ -71,7 +71,7 @@ export async function withdrawFromPeer(
7171
amount?: string | undefined;
7272
} & PeerAndOfferNameFlags,
7373
) {
74-
const computePeers = await resolveComputePeersByNames(flags);
74+
const computePeers = await resolveComputePeersByNames({ flags });
7575

7676
const amount =
7777
flags.amount ??

0 commit comments

Comments
 (0)