변환 yaml 생성 수정
This commit is contained in:
34
migrate.py
34
migrate.py
@@ -6,7 +6,6 @@ from pathlib import Path
|
||||
from collections import defaultdict
|
||||
|
||||
from ruamel.yaml import YAML
|
||||
from ruamel.yaml.comments import CommentedMap
|
||||
|
||||
|
||||
# -----------------------------
|
||||
@@ -38,11 +37,9 @@ def load_mapping(path):
|
||||
|
||||
# -----------------------------
|
||||
# annotation 렌더링
|
||||
# (모든 value를 문자열로 강제)
|
||||
# -----------------------------
|
||||
def render_annotations_block(unsupported, partial, converted):
|
||||
"""
|
||||
annotations 하위에 그대로 삽입될 문자열을 생성
|
||||
"""
|
||||
lines = []
|
||||
|
||||
if unsupported:
|
||||
@@ -55,15 +52,29 @@ def render_annotations_block(unsupported, partial, converted):
|
||||
if partial:
|
||||
for p in partial:
|
||||
lines.append(f" # PARTIAL SUPPORT: {p['note']}")
|
||||
lines.append(f" {p['haproxy']}: {p['value']}")
|
||||
lines.append(f" {p['haproxy']}: \"{str(p['value'])}\"")
|
||||
lines.append("")
|
||||
|
||||
for c in converted:
|
||||
lines.append(f" {c['haproxy']}: {c['value']}")
|
||||
lines.append(f" {c['haproxy']}: \"{str(c['value'])}\"")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# 불필요한 metadata 제거
|
||||
# -----------------------------
|
||||
def cleanup_metadata(meta):
|
||||
for k in [
|
||||
"creationTimestamp",
|
||||
"generation",
|
||||
"resourceVersion",
|
||||
"uid",
|
||||
"managedFields",
|
||||
]:
|
||||
meta.pop(k, None)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# ingress 변환 로직
|
||||
# -----------------------------
|
||||
@@ -81,6 +92,8 @@ def migrate_ingress(data, mapping, ingress_class=None):
|
||||
meta = item.setdefault("metadata", {})
|
||||
spec = item.setdefault("spec", {})
|
||||
|
||||
cleanup_metadata(meta)
|
||||
|
||||
name = meta.get("name")
|
||||
namespace = meta.get("namespace", "default")
|
||||
ingress_id = f"{namespace}/{name}"
|
||||
@@ -127,7 +140,7 @@ def migrate_ingress(data, mapping, ingress_class=None):
|
||||
{"nginx": k, "value": v, "note": note}
|
||||
)
|
||||
|
||||
meta["annotations"] = CommentedMap()
|
||||
meta.pop("annotations", None)
|
||||
item["_rendered_annotations"] = render_annotations_block(
|
||||
unsupported, partial, converted
|
||||
)
|
||||
@@ -136,7 +149,7 @@ def migrate_ingress(data, mapping, ingress_class=None):
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# 리포트 생성 (Markdown)
|
||||
# 리포트 생성
|
||||
# -----------------------------
|
||||
def write_report(report, path):
|
||||
with open(path, "w") as f:
|
||||
@@ -232,9 +245,7 @@ def main():
|
||||
parser.add_argument("--split", action="store_true")
|
||||
parser.add_argument("--out", default="output")
|
||||
parser.add_argument("--ingress-class")
|
||||
parser.add_argument(
|
||||
"--report", default="migration-report.md"
|
||||
)
|
||||
parser.add_argument("--report", default="migration-report.md")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -266,4 +277,3 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
16
report.md
16
report.md
@@ -1,16 +0,0 @@
|
||||
# Ingress Migration Report
|
||||
|
||||
## Summary
|
||||
- Converted : 2
|
||||
- Partial : 1
|
||||
- Unsupported: 1
|
||||
|
||||
---
|
||||
|
||||
## test/nginx-ingress
|
||||
|
||||
- PARTIAL nginx.ingress.kubernetes.io/app-root → haproxy.org/path-rewrite
|
||||
- note: Chage Value
|
||||
- UNSUPPORTED proxy-buffering
|
||||
- note: HAProxy does not support arbitrary NGINX snippets
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{},"creationTimestamp":"2025-12-29T07:28:19Z","generation":1,"name":"haproxy-ingress","namespace":"test","resourceVersion":"3565525","uid":"1c305e90-734c-4421-83a5-b3e3414796c3"},"spec":{"ingressClassName":"haproxy","rules":[{"host":"app.10.60.100.92.nip.io","http":{"paths":[{"backend":{"service":{"name":"test-app","port":{"number":8080}}},"path":"/","pathType":"Prefix"}]}}]},"status":{"loadBalancer":{}}}
|
||||
|
||||
annotations: {}
|
||||
creationTimestamp: "2025-12-29T07:28:19Z"
|
||||
generation: 1
|
||||
name: haproxy-ingress
|
||||
namespace: test
|
||||
resourceVersion: "4241506"
|
||||
uid: 1c305e90-734c-4421-83a5-b3e3414796c3
|
||||
spec:
|
||||
ingressClassName: haproxy
|
||||
rules:
|
||||
- host: app.10.60.100.92.nip.io
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
service:
|
||||
name: test-app
|
||||
port:
|
||||
number: 8080
|
||||
path: /
|
||||
pathType: Prefix
|
||||
status:
|
||||
loadBalancer: {}
|
||||
@@ -1,36 +0,0 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
# HAProxy does not support arbitrary NGINX snippets
|
||||
#proxy-buffering: on
|
||||
|
||||
# PARTIAL SUPPORT: Chage Value
|
||||
haproxy.org/path-rewrite: /kor
|
||||
|
||||
haproxy.org/proxy-connect-timeout: 100
|
||||
haproxy.org/ssl-redirect: true
|
||||
annotations: {}
|
||||
creationTimestamp: "2025-12-30T23:22:37Z"
|
||||
generation: 1
|
||||
name: nginx-ingress
|
||||
namespace: test
|
||||
resourceVersion: "4549046"
|
||||
uid: 9948d763-7e01-4a34-9b2b-a733fd9acff5
|
||||
spec:
|
||||
ingressClassName: haproxy
|
||||
rules:
|
||||
- host: app.10.60.100.91.nip.io
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
service:
|
||||
name: test-app
|
||||
port:
|
||||
number: 8080
|
||||
path: /
|
||||
pathType: Prefix
|
||||
status:
|
||||
loadBalancer:
|
||||
ingress:
|
||||
- ip: 10.60.100.91
|
||||
Reference in New Issue
Block a user