WoozyMasta / kube-dump

Backup a Kubernetes cluster as a yaml manifest
https://kube-dump.woozymasta.ru
GNU General Public License v3.0
318 stars 64 forks source link

Correct dump of cluster resources to be single item per file #22

Closed davidalger closed 2 years ago

davidalger commented 3 years ago

Currently when I run kube-dump cls it is creating a file for each resource, but these files would be a list of every resource of that kind due to the kubectl get cmd lacking the resource name when it fetches the manifest. In the case of ClusterRole resources, each file was ending up at nearly 5k lines long since every one of them contained all For example, cluster/default_Namespace.yaml would be written like this:

apiVersion: v1
items:
  - apiVersion: v1
    kind: Namespace
    metadata:
      name: default
    spec:
      finalizers:
        - kubernetes
    status:
      phase: Active
  - apiVersion: v1
    kind: Namespace
    metadata:
      name: kube-public
    spec:
      finalizers:
        - kubernetes
    status:
      phase: Active
  - apiVersion: v1
    kind: Namespace
    metadata:
      name: kube-system
    spec:
      finalizers:
        - kubernetes
    status:
      phase: Active

// etc

What this PR accomplishes is correctly writing a single item per file, so this file is instead written as it should be (with similar single-item files for kube-public and kube-system etc):

apiVersion: v1
kind: Namespace
metadata:
  name: default
spec:
  finalizers:
    - kubernetes
status:
  phase: Active
WoozyMasta commented 3 years ago

Okay, I need a some time to check this, if everything is ok, I will release a new tag.