변환 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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user