Skip to content

Commit 9f629bf

Browse files
committed
feat(k8s): add taints and labels management
1 parent d8ac2b9 commit 9f629bf

21 files changed

+4657
-8
lines changed

cmd/scw/testdata/test-all-usage-k8s-pool-usage.golden

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@ USAGE:
77
scw k8s pool <command>
88

99
AVAILABLE COMMANDS:
10-
add-external-node Add an external node to a Kosmos Pool
11-
create Create a new Pool in a Cluster
12-
delete Delete a Pool in a Cluster
13-
get Get a Pool in a Cluster
14-
list List Pools in a Cluster
15-
update Update a Pool in a Cluster
16-
upgrade Upgrade a Pool in a Cluster
10+
add-external-node Add an external node to a Kosmos Pool
11+
create Create a new Pool in a Cluster
12+
delete Delete a Pool in a Cluster
13+
get Get a Pool in a Cluster
14+
list List Pools in a Cluster
15+
update Update a Pool in a Cluster
16+
upgrade Upgrade a Pool in a Cluster
17+
18+
LABEL COMMANDS:
19+
remove-label Remove a label from a Pool
20+
set-label Add or edit a taint to a Pool
21+
22+
TAINT COMMANDS:
23+
remove-startup-taint Remove a startup taint from a Pool
24+
remove-taint Remove a taint from a Pool
25+
set-startup-taint Add or edit a startup taint to a Pool
26+
set-taint Add or edit a taint to a Pool
1727

1828
WORKFLOW COMMANDS:
19-
wait Wait for a pool to reach a stable state
29+
wait Wait for a pool to reach a stable state
2030

2131
FLAGS:
2232
-h, --help help for pool

docs/commands/k8s.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ This API allows you to manage Kubernetes Kapsule and Kosmos clusters.
3838
- [Delete a Pool in a Cluster](#delete-a-pool-in-a-cluster)
3939
- [Get a Pool in a Cluster](#get-a-pool-in-a-cluster)
4040
- [List Pools in a Cluster](#list-pools-in-a-cluster)
41+
- [Remove a label from a Pool](#remove-a-label-from-a-pool)
42+
- [Remove a startup taint from a Pool](#remove-a-startup-taint-from-a-pool)
43+
- [Remove a taint from a Pool](#remove-a-taint-from-a-pool)
44+
- [Add or edit a taint to a Pool](#add-or-edit-a-taint-to-a-pool)
45+
- [Add or edit a startup taint to a Pool](#add-or-edit-a-startup-taint-to-a-pool)
46+
- [Add or edit a taint to a Pool](#add-or-edit-a-taint-to-a-pool)
4147
- [Update a Pool in a Cluster](#update-a-pool-in-a-cluster)
4248
- [Upgrade a Pool in a Cluster](#upgrade-a-pool-in-a-cluster)
4349
- [Wait for a pool to reach a stable state](#wait-for-a-pool-to-reach-a-stable-state)
@@ -1160,6 +1166,212 @@ scw k8s pool list cluster-id=11111111-1111-1111-1111-111111111111 order-by=creat
11601166

11611167

11621168

1169+
### Remove a label from a Pool
1170+
1171+
Remove a label from all nodes of the pool (only apply to labels which was set through scaleway api).
1172+
1173+
**Usage:**
1174+
1175+
```
1176+
scw k8s pool remove-label <pool-id ...> [arg=value ...]
1177+
```
1178+
1179+
1180+
**Args:**
1181+
1182+
| Name | | Description |
1183+
|------|---|-------------|
1184+
| pool-id | Required | ID of the pool. |
1185+
| key | Required | Key of the label. |
1186+
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
1187+
1188+
1189+
**Examples:**
1190+
1191+
1192+
Remove a label of a specific pool
1193+
```
1194+
scw k8s pool remove-label 11111111-1111-1111-1111-111111111111 key=foo
1195+
```
1196+
1197+
1198+
1199+
1200+
### Remove a startup taint from a Pool
1201+
1202+
New nodes will not have this taint at startup (does not remove taints from kubernetes side).
1203+
1204+
**Usage:**
1205+
1206+
```
1207+
scw k8s pool remove-startup-taint <pool-id ...> [arg=value ...]
1208+
```
1209+
1210+
1211+
**Args:**
1212+
1213+
| Name | | Description |
1214+
|------|---|-------------|
1215+
| pool-id | Required | ID of the pool. |
1216+
| key | Required | Key of the taint. |
1217+
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
1218+
1219+
1220+
**Examples:**
1221+
1222+
1223+
Remove a startup taint of a specific pool
1224+
```
1225+
scw k8s pool remove-startup-taint 11111111-1111-1111-1111-111111111111 key=foo
1226+
```
1227+
1228+
1229+
1230+
1231+
### Remove a taint from a Pool
1232+
1233+
Remove a taint from all all nodes of the pool (only apply to taints which was set through scaleway api).
1234+
1235+
**Usage:**
1236+
1237+
```
1238+
scw k8s pool remove-taint <pool-id ...> [arg=value ...]
1239+
```
1240+
1241+
1242+
**Args:**
1243+
1244+
| Name | | Description |
1245+
|------|---|-------------|
1246+
| pool-id | Required | ID of the pool. |
1247+
| key | Required | Key of the taint. |
1248+
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
1249+
1250+
1251+
**Examples:**
1252+
1253+
1254+
Remove a taint to a specific pool
1255+
```
1256+
scw k8s pool remove-taint 11111111-1111-1111-1111-111111111111 key=foo
1257+
```
1258+
1259+
1260+
1261+
1262+
### Add or edit a taint to a Pool
1263+
1264+
Apply a label to all nodes of the pool which will be periodically reconciled by scaleway.
1265+
1266+
**Usage:**
1267+
1268+
```
1269+
scw k8s pool set-label <pool-id ...> [arg=value ...]
1270+
```
1271+
1272+
1273+
**Args:**
1274+
1275+
| Name | | Description |
1276+
|------|---|-------------|
1277+
| pool-id | Required | ID of the pool. |
1278+
| key | Required | Key of the label. |
1279+
| value | Required | Value of the label. |
1280+
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
1281+
1282+
1283+
**Examples:**
1284+
1285+
1286+
Apply a label to a specific pool
1287+
```
1288+
scw k8s pool set-label 11111111-1111-1111-1111-111111111111 key=foo value=bar
1289+
```
1290+
1291+
Apply a full label to a specific pool
1292+
```
1293+
scw k8s pool set-label 11111111-1111-1111-1111-111111111111 key=organization.example/gpu value=true
1294+
```
1295+
1296+
1297+
1298+
1299+
### Add or edit a startup taint to a Pool
1300+
1301+
Apply a taint at node creation but does not reconcile after.
1302+
1303+
**Usage:**
1304+
1305+
```
1306+
scw k8s pool set-startup-taint <pool-id ...> [arg=value ...]
1307+
```
1308+
1309+
1310+
**Args:**
1311+
1312+
| Name | | Description |
1313+
|------|---|-------------|
1314+
| pool-id | Required | ID of the pool. |
1315+
| key | Required | Key of the taint. |
1316+
| value | Required | Value of the taint. |
1317+
| effect | Required<br />One of: `NoSchedule`, `PreferNoSchedule`, `NoExecute` | Effect of the taint. |
1318+
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
1319+
1320+
1321+
**Examples:**
1322+
1323+
1324+
Apply a startup taint to a specific pool
1325+
```
1326+
scw k8s pool set-startup-taint 11111111-1111-1111-1111-111111111111 key=foo value=bar effect=NoSchedule
1327+
```
1328+
1329+
Apply a full startup taint to a specific pool
1330+
```
1331+
scw k8s pool set-startup-taint 11111111-1111-1111-1111-111111111111 key=organization.example/gpu value=true effect=NoSchedule
1332+
```
1333+
1334+
1335+
1336+
1337+
### Add or edit a taint to a Pool
1338+
1339+
Apply a taint to all nodes of the pool which will be periodically reconciled by scaleway.
1340+
1341+
**Usage:**
1342+
1343+
```
1344+
scw k8s pool set-taint <pool-id ...> [arg=value ...]
1345+
```
1346+
1347+
1348+
**Args:**
1349+
1350+
| Name | | Description |
1351+
|------|---|-------------|
1352+
| pool-id | Required | ID of the pool. |
1353+
| key | Required | Key of the taint. |
1354+
| value | Required | Value of the taint. |
1355+
| effect | Required<br />One of: `NoSchedule`, `PreferNoSchedule`, `NoExecute` | Effect of the taint. |
1356+
| region | Default: `fr-par` | Region to target. If none is passed will use default region from the config |
1357+
1358+
1359+
**Examples:**
1360+
1361+
1362+
Apply a taint to a specific pool
1363+
```
1364+
scw k8s pool set-taint 11111111-1111-1111-1111-111111111111 key=foo value=bar effect=NoSchedule
1365+
```
1366+
1367+
Apply a full taint to a specific pool
1368+
```
1369+
scw k8s pool set-taint 11111111-1111-1111-1111-111111111111 key=organization.example/gpu value=true effect=NoSchedule
1370+
```
1371+
1372+
1373+
1374+
11631375
### Update a Pool in a Cluster
11641376

11651377
Update the attributes of a specific pool, such as its desired size, autoscaling settings, and tags. To upgrade a pool, you will need to use the dedicated endpoint.

internal/namespaces/k8s/v1/custom.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ func GetCommands() *core.Commands {
3131
k8sNodeWaitCommand(),
3232
k8sPoolWaitCommand(),
3333
k8sPoolAddExternalNodeCommand(),
34+
k8sPoolSetTaintCommand(),
35+
k8sPoolRemoveTaintCommand(),
36+
k8sPoolSetStartupTaintCommand(),
37+
k8sPoolRemoveStartupTaintCommand(),
38+
k8sPoolSetLabelCommand(),
39+
k8sPoolRemoveLabelCommand(),
3440
))
3541

3642
human.RegisterMarshalerFunc(k8s.Version{}, versionMarshalerFunc)
3743
human.RegisterMarshalerFunc(k8s.Cluster{}, clusterMarshalerFunc)
44+
human.RegisterMarshalerFunc(k8s.Pool{}, poolMarshalerFunc)
3845
human.RegisterMarshalerFunc(
3946
k8s.ClusterStatus(""),
4047
human.EnumMarshalFunc(clusterStatusMarshalSpecs),

internal/namespaces/k8s/v1/custom_pool.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,39 @@ const (
4444
poolActionDelete
4545
)
4646

47+
func poolMarshalerFunc(i any, opt *human.MarshalOpt) (string, error) {
48+
type humanPool k8s.Pool
49+
pool := humanPool(i.(k8s.Pool))
50+
51+
// Sections
52+
opt.Sections = []*human.MarshalSection{
53+
{
54+
FieldName: "UpgradePolicy",
55+
Title: "Upgrade Policy",
56+
},
57+
{
58+
FieldName: "Labels",
59+
Title: "Node labels",
60+
},
61+
{
62+
FieldName: "Taints",
63+
Title: "Node taints",
64+
},
65+
66+
{
67+
FieldName: "StartupTaints",
68+
Title: "Node startup taints",
69+
},
70+
}
71+
72+
str, err := human.Marshal(pool, opt)
73+
if err != nil {
74+
return "", err
75+
}
76+
77+
return str, nil
78+
}
79+
4780
func poolCreateBuilder(c *core.Command) *core.Command {
4881
c.WaitFunc = waitForPoolFunc(poolActionCreate)
4982

0 commit comments

Comments
 (0)