Uploaded image for project: 'OpenShift Bugs'
  1. OpenShift Bugs
  2. OCPBUGS-16735

oc adm inspect does not truncate files when overwriting

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done-Errata
    • Undefined
    • 4.14.0
    • 4.14.0
    • oc
    • None
    • Moderate
    • No
    • Rejected
    • False
    • Hide

      None

      Show
      None

    Description

      Description of problem:

      oc adm inspect generated files sometime have the leading "---" and some time do not. This depends on the order of objects collected. This by itself is not an issue.
      
      However this becomes an issue when combined with multiple invocations of oc adm inspect and collecting data to the same directory like must-gather does.
      
      If an object is collected multiple times then the second time oc might overwrite the original file improperly and leave 4 bytes of the original content behind.
      
      This is happening when not writing the "---\n" in the second invocation as this makes the content 4B shorter and the original tailing 4B are left in the file intact.
      
      This garbage confuses YAML parsers.

      Version-Release number of selected component (if applicable):

      4.14 nighly as of Jul 25 and before

      How reproducible:

      Always

      Steps to Reproduce:

      Run oc adm inspect twice with different order of objects:
      
      [msivak@x openshift-must-gather]$ oc adm inspect performanceprofile,machineconfigs,nodes --dest-dir=inspect.dual --all-namespaces
      [msivak@x openshift-must-gather]$ oc adm inspect nodes --dest-dir=inspect.dual --all-namespaces
      
      
      And then check the alphabetically first node yaml file - it will have garbage at the end of the file.

      Actual results:

      Garbage at the end of the file.

      Expected results:

      No garbage.

      Additional info:

      I believe this is caused by the lack of Truncate mode here https://github.com/openshift/oc/blob/master/pkg/cli/admin/inspect/writer.go#L54
      
      
      Collecting data multiple times cannot be easily avoided when multiple collect scripts are combined with relatedObjects requested by operators.

      Attachments

        Issue Links

          Activity

            People

              jchaloup@redhat.com Jan Chaloupka
              msivak@redhat.com Martin Sivak
              ying zhou ying zhou
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: