gmeghnag / omc

OpenShift Must-Gather Client
Apache License 2.0
153 stars 63 forks source link

OMC does not ignore the '.swp' files #180

Open vlours opened 2 months ago

vlours commented 2 months ago

Just noticed that if someone is opening one of the yaml files using vim or vi, this will create a .swp file and omc will try to open it:

[vlours@supportshell-1 ~]$ oc get machineset -n openshift-machine-api
Error when trying to unmarshal file: /home/bne/vlours/03920836/0010-3920836.tar.gz/3920836/quay-io-openshift-release-dev-ocp-v4-0-art-dev-sha256-1d0190b2e1110469c9ea981f24f758dccacf621c5d46ab01ba1edaf5755b2ec1/namespaces/openshift-machine-api/machine.openshift.io/machinesets/.int-np-lmjcl-worker-0.yaml.swp
[vlours@supportshell-1 ~]$ ls -la /home/bne/vlours/03920836/0010-3920836.tar.gz/3920836/quay-io-openshift-release-dev-ocp-v4-0-art-dev-sha256-1d0190b2e1110469c9ea981f24f758dccacf621c5d46ab01ba1edaf5755b2ec1/namespaces/openshift-machine-api/machine.openshift.io/machinesets/
total 20
drwxrwxrwx+ 2 yank    yank       91 Sep  5 05:59 .
drwxrwxrwx+ 5 yank    yank       84 Sep  5 02:14 ..
-rw-rw-rw-+ 1 yank    yank     3609 Sep  5 02:05 int-np-lmjcl-worker-0.yaml
-rw-r--r--+ 1 egeorge egeorge 16384 Sep  5 05:59 .int-np-lmjcl-worker-0.yaml.swp       <<<<< 

In addition If you create a empty file in a folder the command will simply crash:

[vlours@supportshell-1 ~]$ oc get mcp
NAME     CONFIG                                             UPDATED   UPDATING   DEGRADED   MACHINECOUNT   READYMACHINECOUNT   UPDATEDMACHINECOUNT   DEGRADEDMACHINECOUNT   AGE
master   rendered-master-cd754fa9873eb664b22c894f530fdecb   True      False      False      3              3                   3                     0                      58d
worker   rendered-worker-18f2b48afb85af4e68a3b0b0afd0d208   True      False      False      6              6                   6                     0                      58d
[vlours@supportshell-1 ~]$ touch 03920836/0010-3920836.tar.gz/3920836/quay-io-openshift-release-dev-ocp-v4-0-art-dev-sha256-1d0190b2e1110469c9ea981f24f758dccacf621c5d46ab01ba1edaf5755b2ec1/cluster-scoped-resources/machineconfiguration.openshift.io/machineconfigpools/infra.yaml
[vlours@supportshell-1 ~]$ oc get mcp
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x198 pc=0x2ccd9fa]

goroutine 1 [running]:
github.com/gmeghnag/omc/pkg/tablegenerator.GenerateCustomResourceTable({0x0})
    /builddir/build/BUILD/omc-3.7.2/pkg/tablegenerator/tablegenerator.go:169 +0xb5a
github.com/gmeghnag/omc/cmd/get.handleObject({0x0})
    /builddir/build/BUILD/omc-3.7.2/cmd/get/get.go:443 +0x118e
github.com/gmeghnag/omc/cmd/get.getClusterScopedResources({0xc004023530, 0x12}, {0xc004412b40, 0x21}, 0xc00155f3b0)
    /builddir/build/BUILD/omc-3.7.2/cmd/get/get.go:362 +0x5c5
github.com/gmeghnag/omc/cmd/get.init.func1(0xc00019f200?, {0xc000a944c0?, 0x4?, 0x386f378?})
    /builddir/build/BUILD/omc-3.7.2/cmd/get/get.go:109 +0x4db
github.com/spf13/cobra.(*Command).execute(0x5687840, {0xc000a94480, 0x1, 0x1})
    /builddir/build/BUILD/omc-3.7.2/vendor/github.com/spf13/cobra/command.go:944 +0x867
github.com/spf13/cobra.(*Command).ExecuteC(0x5684d20)
    /builddir/build/BUILD/omc-3.7.2/vendor/github.com/spf13/cobra/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
    /builddir/build/BUILD/omc-3.7.2/vendor/github.com/spf13/cobra/command.go:992
main.main()
    /builddir/build/BUILD/omc-3.7.2/main.go:24 +0x1a

So it will be great to ignore empty (size = 0) and swp binary files (.*.swp)

Thanks