@catladder/cli 1.98.0 → 1.98.2

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
@@ -24,7 +24,7 @@
24
24
  "node": ">=12.0.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@catladder/pipeline": "1.98.0",
27
+ "@catladder/pipeline": "1.98.2",
28
28
  "@kubernetes/client-node": "^0.16.2",
29
29
  "@tsconfig/node14": "^1.0.1",
30
30
  "@types/common-tags": "^1.8.0",
@@ -57,5 +57,5 @@
57
57
  "typescript": "^4.5.4",
58
58
  "vorpal": "^1.12.0"
59
59
  },
60
- "version": "1.98.0"
60
+ "version": "1.98.2"
61
61
  }
@@ -85,16 +85,26 @@ roleRef:
85
85
  EOF
86
86
  `);
87
87
 
88
- // get token name
89
- const tokenName = await exec(
90
- `kubectl get serviceaccount --namespace ${namespace} ${serviceAccountName} -o jsonpath='{.secrets[0].name}'`
91
- ).then((c) => c.stdout.trim());
88
+ const secretName = `${serviceAccountName}-secret`;
89
+ // create token for the service account
90
+ await exec(`
91
+ kubectl apply -f - <<EOF
92
+ apiVersion: v1
93
+ kind: Secret
94
+ metadata:
95
+ name: ${secretName}
96
+ namespace: ${namespace}
97
+ annotations:
98
+ kubernetes.io/service-account.name: ${serviceAccountName}
99
+ type: kubernetes.io/service-account-token
100
+ EOF
101
+ `);
92
102
 
93
103
  const KUBE_CA_PEM = await exec(
94
- `kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['ca\\.crt']}"`
104
+ `kubectl get secret ${secretName} --namespace ${namespace} -o jsonpath="{['data']['ca\\.crt']}"`
95
105
  ).then((c) => c.stdout.trim());
96
106
  const KUBE_TOKEN = await exec(
97
- `kubectl get secret ${tokenName} --namespace ${namespace} -o jsonpath="{['data']['token']}" | base64 --decode`
107
+ `kubectl get secret ${secretName} --namespace ${namespace} -o jsonpath="{['data']['token']}" | base64 --decode`
98
108
  ).then((c) => c.stdout.trim());
99
109
 
100
110
  const vars = {
@@ -103,6 +113,17 @@ EOF
103
113
  KUBE_URL,
104
114
  };
105
115
 
116
+ const missing = Object.entries(vars).filter((e) => !e[1]);
117
+ if (missing.length > 0) {
118
+ throw new Error(
119
+ "could not setup credentials. Missing vars: " +
120
+ missing.map((m) => m[0]).join(", ") +
121
+ ". Check whether your local kubectl is still working for '" +
122
+ fullName +
123
+ "'"
124
+ );
125
+ }
126
+
106
127
  instance.log("service accounts created / updated!");
107
128
 
108
129
  instance.log("");