@catladder/cli 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"catladder": "./bin/catladder"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@catladder/pipeline": "1.
|
|
19
|
+
"@catladder/pipeline": "1.10.0",
|
|
20
20
|
"@kubernetes/client-node": "^0.16.2",
|
|
21
21
|
"child-process-promise": "^2.2.1",
|
|
22
22
|
"command-exists-promise": "^2.0.2",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"eslint": "^8.7.0",
|
|
56
56
|
"typescript": "^4.5.4"
|
|
57
57
|
},
|
|
58
|
-
"version": "1.
|
|
58
|
+
"version": "1.10.0"
|
|
59
59
|
}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getFullKubernetesClusterName,
|
|
3
3
|
isOfDeployType,
|
|
4
|
-
getKubernetesNamespace,
|
|
5
4
|
} from "@catladder/pipeline";
|
|
6
5
|
import Vorpal from "vorpal";
|
|
7
6
|
import { $ } from "zx";
|
|
8
7
|
import { getAllPipelineContexts } from "../../../../config/getProjectConfig";
|
|
9
8
|
import { connectToCluster } from "../../../../utils/cluster";
|
|
10
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
doGitlabRequest,
|
|
11
|
+
getProjectInfo,
|
|
12
|
+
upsertAllVariables,
|
|
13
|
+
} from "../../../../utils/gitlab";
|
|
11
14
|
import ensureNamespace from "./utils/ensureNamespace";
|
|
15
|
+
import open from "open";
|
|
12
16
|
|
|
13
17
|
export default async (vorpal: Vorpal) =>
|
|
14
18
|
vorpal
|
|
@@ -109,69 +113,9 @@ EOF
|
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// in practise, that is often not an issue, but it might happen because the config allows it
|
|
115
|
-
/*
|
|
116
|
-
Object.entries(configuredClusters).forEach(([fullname, config]) =>
|
|
117
|
-
this.log(` - ${config.cluster.name || "unknown"} (${fullname})`)
|
|
118
|
-
);
|
|
119
|
-
this.log("");
|
|
120
|
-
|
|
121
|
-
const missingClusters = Object.fromEntries(
|
|
122
|
-
Object.entries(configuredClusters).filter(
|
|
123
|
-
([c]) => !existingClusters.some((exist) => exist === c)
|
|
124
|
-
)
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
this.log("");
|
|
128
|
-
this.log("These clusters are not configured yet on gitlab:");
|
|
129
|
-
this.log("");
|
|
130
|
-
|
|
131
|
-
Object.entries(missingClusters).forEach(([fullname, config]) =>
|
|
132
|
-
this.log(` - ${config.cluster.name || "unknown"} (${fullname})`)
|
|
116
|
+
const { id: projectId, web_url: projectWebUrl } = await getProjectInfo(
|
|
117
|
+
this
|
|
133
118
|
);
|
|
134
|
-
this.log("");
|
|
135
|
-
|
|
136
|
-
for (const [fullname, config] of Object.entries(missingClusters)) {
|
|
137
|
-
this.log(`${config.name} (${fullname})`);
|
|
138
|
-
this.log("");
|
|
139
|
-
const { shouldContinue } = await this.prompt({
|
|
140
|
-
type: "confirm",
|
|
141
|
-
name: "shouldContinue",
|
|
142
|
-
message: "Should I add the this cluster ? 🤔 ",
|
|
143
|
-
});
|
|
144
|
-
this.log("");
|
|
145
|
-
if (shouldContinue) {
|
|
146
|
-
await connectToCluster(fullname);
|
|
147
|
-
const { stdout: api_url } =
|
|
148
|
-
await $`kubectl cluster-info | grep -E 'Kubernetes master|Kubernetes control plane' | awk '/http/ {print $NF}'`;
|
|
149
|
-
const { stdout: ca_cert } =
|
|
150
|
-
await $`kubectl get secret default-token-69xv4 -o jsonpath="{['data']['ca\.crt']}" | base64 --decode`;
|
|
151
|
-
const { stdout: token } =
|
|
152
|
-
await $`kubectl get secret default-token-69xv4 -o jsonpath="{['data']['token']}" | base64 --decode`;
|
|
153
|
-
const postResult = await doGitlabRequest(
|
|
154
|
-
this,
|
|
155
|
-
`projects/${projectId}/clusters/user`,
|
|
156
|
-
{
|
|
157
|
-
name: fullname,
|
|
158
|
-
managed: false,
|
|
159
|
-
environment_scope: "*",
|
|
160
|
-
platform_kubernetes_attributes: {
|
|
161
|
-
api_url,
|
|
162
|
-
ca_cert,
|
|
163
|
-
token,
|
|
164
|
-
namespace: await getProjectNamespace("prod"),
|
|
165
|
-
},
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
const { message } = postResult;
|
|
169
|
-
if (message) {
|
|
170
|
-
this.log(`Message from gitlab: ${message}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
119
|
const variables = await doGitlabRequest(
|
|
176
120
|
this,
|
|
177
121
|
`projects/${projectId}/variables`
|
|
@@ -244,5 +188,4 @@ EOF
|
|
|
244
188
|
].forEach((tip) => this.log(` - ${tip}`));
|
|
245
189
|
this.log("\n");
|
|
246
190
|
this.log("\n");
|
|
247
|
-
*/
|
|
248
191
|
});
|