raijin-server 0.2.25__py3-none-any.whl → 0.2.26__py3-none-any.whl

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.

Potentially problematic release.


This version of raijin-server might be problematic. Click here for more details.

raijin_server/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  """Pacote principal do CLI Raijin Server."""
2
2
 
3
- __version__ = "0.2.25"
3
+ __version__ = "0.2.26"
4
4
 
5
5
  __all__ = ["__version__"]
@@ -147,6 +147,9 @@ metadata:
147
147
  namespace: istio-system
148
148
  spec:
149
149
  profile: {profile}
150
+ meshConfig:
151
+ defaultConfig:
152
+ holdApplicationUntilProxyStarts: true
150
153
  components:
151
154
  pilot:
152
155
  enabled: true
@@ -175,10 +178,6 @@ spec:
175
178
  kubernetes.io/hostname: {node_name}
176
179
  service:
177
180
  type: {service_type}
178
- values:
179
- global:
180
- proxy:
181
- holdApplicationUntilProxyStarts: true
182
181
  """
183
182
 
184
183
  config_path = Path("/tmp/raijin-istio-config.yaml")
@@ -2,10 +2,11 @@
2
2
 
3
3
  import socket
4
4
  import time
5
+ from pathlib import Path
5
6
 
6
7
  import typer
7
8
 
8
- from raijin_server.utils import ExecutionContext, helm_upgrade_install, require_root, run_cmd
9
+ from raijin_server.utils import ExecutionContext, helm_upgrade_install, require_root, run_cmd, write_file
9
10
 
10
11
 
11
12
  def _detect_node_name(ctx: ExecutionContext) -> str:
@@ -20,6 +21,26 @@ def _detect_node_name(ctx: ExecutionContext) -> str:
20
21
  return socket.gethostname()
21
22
 
22
23
 
24
+ def _check_metallb_installed(ctx: ExecutionContext) -> bool:
25
+ """Verifica se MetalLB está instalado no cluster."""
26
+ result = run_cmd(
27
+ ["kubectl", "get", "deployment", "metallb-controller", "-n", "metallb-system"],
28
+ ctx,
29
+ check=False,
30
+ )
31
+ return result.returncode == 0
32
+
33
+
34
+ def _check_cert_manager_installed(ctx: ExecutionContext) -> bool:
35
+ """Verifica se cert-manager está instalado no cluster."""
36
+ result = run_cmd(
37
+ ["kubectl", "get", "deployment", "cert-manager", "-n", "cert-manager"],
38
+ ctx,
39
+ check=False,
40
+ )
41
+ return result.returncode == 0
42
+
43
+
23
44
  def _check_existing_kong(ctx: ExecutionContext) -> bool:
24
45
  """Verifica se existe instalacao do Kong."""
25
46
  result = run_cmd(
@@ -30,6 +51,42 @@ def _check_existing_kong(ctx: ExecutionContext) -> bool:
30
51
  return result.returncode == 0
31
52
 
32
53
 
54
+ def _check_orphan_crds(ctx: ExecutionContext) -> list[str]:
55
+ """Detecta CRDs orfaos do Kong (sem ownership do Helm)."""
56
+ result = run_cmd(
57
+ ["kubectl", "get", "crd", "-o", "name"],
58
+ ctx,
59
+ check=False,
60
+ )
61
+
62
+ if result.returncode != 0:
63
+ return []
64
+
65
+ kong_crds = []
66
+ for line in (result.stdout or "").strip().split("\n"):
67
+ if "konghq.com" in line:
68
+ # Extrai nome do CRD
69
+ crd_name = line.replace("customresourcedefinition.apiextensions.k8s.io/", "")
70
+ kong_crds.append(crd_name)
71
+
72
+ return kong_crds
73
+
74
+
75
+ def _cleanup_orphan_crds(ctx: ExecutionContext, crds: list[str]) -> None:
76
+ """Remove CRDs orfaos do Kong."""
77
+ typer.echo(f"Removendo {len(crds)} CRDs orfaos do Kong...")
78
+
79
+ for crd in crds:
80
+ run_cmd(
81
+ ["kubectl", "delete", "crd", crd, "--ignore-not-found"],
82
+ ctx,
83
+ check=False,
84
+ )
85
+
86
+ time.sleep(3)
87
+ typer.secho(" CRDs orfaos removidos.", fg=typer.colors.GREEN)
88
+
89
+
33
90
  def _uninstall_kong(ctx: ExecutionContext) -> None:
34
91
  """Remove instalacao anterior do Kong."""
35
92
  typer.echo("Removendo instalacao anterior do Kong...")
@@ -100,45 +157,121 @@ def run(ctx: ExecutionContext) -> None:
100
157
  )
101
158
  if cleanup:
102
159
  _uninstall_kong(ctx)
160
+
161
+ # Verificar CRDs orfaos (sem ownership do Helm)
162
+ orphan_crds = _check_orphan_crds(ctx)
163
+ if orphan_crds:
164
+ typer.secho(
165
+ f"\n⚠️ Detectados {len(orphan_crds)} CRDs orfaos do Kong (sem ownership do Helm):",
166
+ fg=typer.colors.YELLOW,
167
+ )
168
+ for crd in orphan_crds[:5]:
169
+ typer.echo(f" - {crd}")
170
+ if len(orphan_crds) > 5:
171
+ typer.echo(f" ... e mais {len(orphan_crds) - 5}")
172
+
173
+ cleanup_crds = typer.confirm(
174
+ "\nRemover CRDs orfaos para permitir instalacao limpa?",
175
+ default=True,
176
+ )
177
+ if cleanup_crds:
178
+ _cleanup_orphan_crds(ctx, orphan_crds)
179
+ else:
180
+ typer.secho(
181
+ "AVISO: A instalacao pode falhar devido aos CRDs orfaos.",
182
+ fg=typer.colors.YELLOW,
183
+ )
184
+
185
+ # Detectar dependencias
186
+ has_metallb = _check_metallb_installed(ctx)
187
+ has_cert_manager = _check_cert_manager_installed(ctx)
188
+
189
+ # Tipo de servico baseado na presenca do MetalLB
190
+ if has_metallb:
191
+ typer.secho("✓ MetalLB detectado. Kong usará LoadBalancer.", fg=typer.colors.GREEN)
192
+ service_type = "LoadBalancer"
193
+ else:
194
+ typer.secho("⚠ MetalLB não detectado. Kong usará NodePort.", fg=typer.colors.YELLOW)
195
+ service_type = "NodePort"
196
+
197
+ if has_cert_manager:
198
+ typer.secho("✓ cert-manager detectado. TLS automático disponível.", fg=typer.colors.GREEN)
199
+ else:
200
+ typer.secho("⚠ cert-manager não detectado. Configure TLS manualmente.", fg=typer.colors.YELLOW)
103
201
 
104
202
  # Configuracoes interativas
105
203
  enable_admin = typer.confirm("Habilitar Admin API (para gerenciamento)?", default=True)
204
+ enable_metrics = typer.confirm("Habilitar métricas Prometheus?", default=True)
106
205
  db_mode = typer.prompt(
107
206
  "Modo de banco de dados (dbless/postgres)",
108
207
  default="dbless",
109
208
  )
110
209
 
111
210
  node_name = _detect_node_name(ctx)
112
-
113
- values = [
114
- # Modo de operacao
115
- f"env.database={db_mode}",
116
- # Ingress Controller
117
- "ingressController.installCRDs=true",
118
- "ingressController.enabled=true",
119
- # Proxy service
120
- "proxy.enabled=true",
121
- "proxy.type=LoadBalancer",
122
- # Tolerations para control-plane
123
- "tolerations[0].key=node-role.kubernetes.io/control-plane",
124
- "tolerations[0].operator=Exists",
125
- "tolerations[0].effect=NoSchedule",
126
- "tolerations[1].key=node-role.kubernetes.io/master",
127
- "tolerations[1].operator=Exists",
128
- "tolerations[1].effect=NoSchedule",
129
- # NodeSelector
130
- f"nodeSelector.kubernetes\\.io/hostname={node_name}",
131
- ]
132
-
133
- # Admin API
134
- if enable_admin:
135
- values.extend([
136
- "admin.enabled=true",
137
- "admin.type=ClusterIP",
138
- "admin.http.enabled=true",
139
- ])
140
- else:
141
- values.append("admin.enabled=false")
211
+
212
+ # Usar arquivo YAML para configurações complexas (mais confiável que --set)
213
+ values_yaml = f"""env:
214
+ database: {db_mode}
215
+
216
+ ingressController:
217
+ installCRDs: true
218
+ enabled: true
219
+
220
+ proxy:
221
+ enabled: true
222
+ type: {service_type}
223
+ http:
224
+ enabled: true
225
+ containerPort: 8000
226
+ servicePort: 80
227
+ tls:
228
+ enabled: true
229
+ containerPort: 8443
230
+ servicePort: 443
231
+
232
+ admin:
233
+ enabled: {str(enable_admin).lower()}
234
+ type: ClusterIP
235
+ http:
236
+ enabled: true
237
+
238
+ tolerations:
239
+ - key: node-role.kubernetes.io/control-plane
240
+ operator: Exists
241
+ effect: NoSchedule
242
+ - key: node-role.kubernetes.io/master
243
+ operator: Exists
244
+ effect: NoSchedule
245
+
246
+ nodeSelector:
247
+ kubernetes.io/hostname: {node_name}
248
+
249
+ resources:
250
+ requests:
251
+ memory: 256Mi
252
+ cpu: 100m
253
+ limits:
254
+ memory: 1Gi
255
+ """
256
+
257
+ # Adicionar métricas se habilitado
258
+ if enable_metrics:
259
+ values_yaml += """
260
+ serviceMonitor:
261
+ enabled: true
262
+ namespace: kong
263
+ labels:
264
+ release: kube-prometheus-stack
265
+
266
+ podAnnotations:
267
+ prometheus.io/scrape: "true"
268
+ prometheus.io/port: "8100"
269
+ """
270
+
271
+ values_path = Path("/tmp/raijin-kong-values.yaml")
272
+ write_file(values_path, values_yaml, ctx)
273
+
274
+ run_cmd(["kubectl", "create", "namespace", "kong"], ctx, check=False)
142
275
 
143
276
  helm_upgrade_install(
144
277
  release="kong",
@@ -147,7 +280,8 @@ def run(ctx: ExecutionContext) -> None:
147
280
  repo="kong",
148
281
  repo_url="https://charts.konghq.com",
149
282
  ctx=ctx,
150
- values=values,
283
+ values=[],
284
+ extra_args=["-f", str(values_path)],
151
285
  )
152
286
 
153
287
  # Aguarda pods ficarem prontos
@@ -155,9 +289,46 @@ def run(ctx: ExecutionContext) -> None:
155
289
  _wait_for_kong_ready(ctx)
156
290
 
157
291
  # Mostra informacoes uteis
158
- typer.secho("\n✓ Kong instalado com sucesso.", fg=typer.colors.GREEN, bold=True)
159
- typer.echo("\nPara verificar o servico:")
160
- typer.echo(" kubectl -n kong get svc kong-kong-proxy")
292
+ typer.secho("\n✓ Kong Gateway instalado com sucesso.", fg=typer.colors.GREEN, bold=True)
293
+
294
+ typer.echo("\n📌 Acesso ao Kong Proxy:")
295
+ if service_type == "LoadBalancer":
296
+ typer.echo(" kubectl -n kong get svc kong-kong-proxy # Aguarde EXTERNAL-IP")
297
+ else:
298
+ typer.echo(" kubectl -n kong get svc kong-kong-proxy # Use NodePort")
299
+
161
300
  if enable_admin:
162
- typer.echo("\nPara acessar Admin API (port-forward):")
301
+ typer.echo("\n📌 Admin API (port-forward):")
163
302
  typer.echo(" kubectl -n kong port-forward svc/kong-kong-admin 8001:8001")
303
+ typer.echo(" curl http://localhost:8001/status")
304
+
305
+ if enable_metrics:
306
+ typer.echo("\n📌 Métricas Prometheus:")
307
+ typer.echo(" ServiceMonitor criado - métricas serão coletadas automaticamente")
308
+
309
+ if has_cert_manager:
310
+ typer.echo("\n📌 TLS com cert-manager (exemplo de Ingress):")
311
+ typer.echo(""" ---
312
+ apiVersion: networking.k8s.io/v1
313
+ kind: Ingress
314
+ metadata:
315
+ name: my-api
316
+ annotations:
317
+ cert-manager.io/cluster-issuer: letsencrypt-prod
318
+ konghq.com/strip-path: "true"
319
+ spec:
320
+ ingressClassName: kong
321
+ tls:
322
+ - hosts: [api.example.com]
323
+ secretName: api-tls
324
+ rules:
325
+ - host: api.example.com
326
+ http:
327
+ paths:
328
+ - path: /
329
+ pathType: Prefix
330
+ backend:
331
+ service:
332
+ name: my-service
333
+ port:
334
+ number: 80""")
@@ -269,7 +269,7 @@ scheduler: {{}}
269
269
  ---
270
270
  apiVersion: kubeproxy.config.k8s.io/v1alpha1
271
271
  kind: KubeProxyConfiguration
272
- mode: ipvs
272
+ mode: iptables
273
273
  ---
274
274
  apiVersion: kubelet.config.k8s.io/v1beta1
275
275
  kind: KubeletConfiguration
@@ -331,3 +331,34 @@ cgroupDriver: systemd
331
331
  "--all",
332
332
  "--timeout=180s",
333
333
  ], ctx, check=False)
334
+
335
+ # Em clusters single-node, perguntar se deve remover taint do control-plane
336
+ # para permitir que workloads rodem no mesmo node
337
+ typer.secho("\n📌 Configuração de Single-Node Cluster", fg=typer.colors.CYAN, bold=True)
338
+ typer.echo("Se este for um cluster single-node (apenas este servidor),")
339
+ typer.echo("é necessário remover o taint do control-plane para permitir workloads.")
340
+
341
+ remove_taint = typer.confirm(
342
+ "Remover taint do control-plane (necessário para single-node)?",
343
+ default=True,
344
+ )
345
+
346
+ if remove_taint:
347
+ typer.echo("Removendo taint node-role.kubernetes.io/control-plane...")
348
+ run_cmd(
349
+ ["kubectl", "taint", "nodes", "--all", "node-role.kubernetes.io/control-plane-", "--overwrite"],
350
+ ctx,
351
+ check=False,
352
+ )
353
+ typer.secho("✓ Taint removido. Workloads podem rodar neste node.", fg=typer.colors.GREEN)
354
+ else:
355
+ typer.secho(
356
+ "⚠ Taint mantido. Workloads precisarão de tolerations ou worker nodes.",
357
+ fg=typer.colors.YELLOW,
358
+ )
359
+
360
+ typer.secho("\n✓ Kubernetes instalado com sucesso!", fg=typer.colors.GREEN, bold=True)
361
+ typer.echo("\nPróximos passos:")
362
+ typer.echo(" raijin-server install metallb # LoadBalancer para bare-metal")
363
+ typer.echo(" raijin-server install traefik # Ingress Controller")
364
+ typer.echo(" raijin-server install cert-manager # Certificados TLS automáticos")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: raijin-server
3
- Version: 0.2.25
3
+ Version: 0.2.26
4
4
  Summary: CLI para automacao de setup e hardening de servidores Ubuntu Server.
5
5
  Home-page: https://example.com/raijin-server
6
6
  Author: Equipe Raijin
@@ -1,4 +1,4 @@
1
- raijin_server/__init__.py,sha256=Fb2dY-WZNdEoZ2C5SWUDZG_DzfMcBF1q-cf_ss9lo7s,95
1
+ raijin_server/__init__.py,sha256=eyoihT94C2L9-FRAopoagny015Laj3hhZ94X-WZ_hvg,95
2
2
  raijin_server/cli.py,sha256=71nn7QN0f3MJkXcHr0STXmxljr-CaPibzOoiItbOT88,28571
3
3
  raijin_server/config.py,sha256=QNiEVvrbW56XgvNn5-h3bkJm46Xc8mjNqPbvixXD8N0,4829
4
4
  raijin_server/healthchecks.py,sha256=lzXdFw6S0hOYbUKbqksh4phb04lXgXdTspP1Dsz4dx8,15401
@@ -15,10 +15,10 @@ raijin_server/modules/full_install.py,sha256=xiKe2GLuZ97c4YdTmhP-kwDVuJJ9Xq3dlgc
15
15
  raijin_server/modules/grafana.py,sha256=DdDLxmTeFnDRvcRLkpg1RuR9o1ZAArk2W-DTLLyfWHg,6009
16
16
  raijin_server/modules/hardening.py,sha256=4hz3ifkMhPlXa2n7gPxN0gitQgzALZ-073vuU3LM4RI,1616
17
17
  raijin_server/modules/harness.py,sha256=uWTxTVJlY_VB6xi4ftMtTSaIb96HA8WJQS-RbyxU45M,5391
18
- raijin_server/modules/istio.py,sha256=LxH_3VKWMq_F8WFumkxgL0dhFmG309XB4TbSUggJEic,7301
18
+ raijin_server/modules/istio.py,sha256=o0K5-Fw4LRs-kbAVgwzYxHzEt_aPFJG8suqOqvg2748,7297
19
19
  raijin_server/modules/kafka.py,sha256=n7ZpLPWv6sKBJhdBiPe7VgeDB24YiCIOWvOQkWwt03Y,5664
20
- raijin_server/modules/kong.py,sha256=cRDzAP9Ne3Qte6sqmxWUS-aJVgiaf4B0uqFvg02Nw5E,5076
21
- raijin_server/modules/kubernetes.py,sha256=waSf2cCVnLicN5o3M47MzMzmHHtvKeFXm1__8ynQzA0,11871
20
+ raijin_server/modules/kong.py,sha256=ehr-Bj_zfvFrYV14YhvKpb-k8KFli6sbaKn6WSIaSvA,9823
21
+ raijin_server/modules/kubernetes.py,sha256=9E6zV0zGQWZW92NVpxwYctpi-4JDmi6YzF3tKRI4HlU,13343
22
22
  raijin_server/modules/loki.py,sha256=aNiUpnOFppZMXoQwYhn7IoPMzwUz4aHi6pbiqj1PRjc,5022
23
23
  raijin_server/modules/metallb.py,sha256=uUuklc_RsQ-W2qDVRMQAxQm9HKGEqso444b1IwBpM6w,8554
24
24
  raijin_server/modules/minio.py,sha256=wxL8U1Zl3XtI-wymIeZonmi561v1zf-bY4TTVPKisLA,6221
@@ -37,9 +37,9 @@ raijin_server/scripts/checklist.sh,sha256=j6E0Kmk1EfjLvKK1VpCqzXJAXI_7Bm67LK4ndy
37
37
  raijin_server/scripts/install.sh,sha256=Y1ickbQ4siQ0NIPs6UgrqUr8WWy7U0LHmaTQbEgavoI,3949
38
38
  raijin_server/scripts/log_size_metric.sh,sha256=Iv4SsX8AuCYRou-klYn32mX41xB6j0xJGLBO6riw4rU,1208
39
39
  raijin_server/scripts/pre-deploy-check.sh,sha256=XqMo7IMIpwUHF17YEmU0-cVmTDMoCGMBFnmS39FidI4,4912
40
- raijin_server-0.2.25.dist-info/licenses/LICENSE,sha256=kJsMCjOiRZE0AQNtxWqBa32z9kMAaF4EUxyHj3hKaJo,1105
41
- raijin_server-0.2.25.dist-info/METADATA,sha256=IZM1t1KEU8iBnJ6bXc2FLoL7XIsJ_01Y5HhZ_Qirt0w,22476
42
- raijin_server-0.2.25.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
43
- raijin_server-0.2.25.dist-info/entry_points.txt,sha256=3ZvxDX4pvcjkIRsXAJ69wIfVmKa78LKo-C3QhqN2KVM,56
44
- raijin_server-0.2.25.dist-info/top_level.txt,sha256=Yz1xneCRtsZOzbPIcTAcrSxd-1p80pohMXYAZ74dpok,14
45
- raijin_server-0.2.25.dist-info/RECORD,,
40
+ raijin_server-0.2.26.dist-info/licenses/LICENSE,sha256=kJsMCjOiRZE0AQNtxWqBa32z9kMAaF4EUxyHj3hKaJo,1105
41
+ raijin_server-0.2.26.dist-info/METADATA,sha256=viulP29E95tjwFrGpTBDrk3kQw3MrtFBB5plAWcL1Xc,22476
42
+ raijin_server-0.2.26.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
43
+ raijin_server-0.2.26.dist-info/entry_points.txt,sha256=3ZvxDX4pvcjkIRsXAJ69wIfVmKa78LKo-C3QhqN2KVM,56
44
+ raijin_server-0.2.26.dist-info/top_level.txt,sha256=Yz1xneCRtsZOzbPIcTAcrSxd-1p80pohMXYAZ74dpok,14
45
+ raijin_server-0.2.26.dist-info/RECORD,,