Skip to content

Conversation

@wking
Copy link
Member

@wking wking commented Nov 19, 2019

This is everything from #165 except setting InjectReleaseVersion for the installers, because @abhinavdahiya wants some time to look into the ecosystem around that. @sallyom, this also lets us fix the existing bugs described in #165 while avoiding your concerns about warnings when running code that expects to inject release versions into the installer before the installer has the marker to recieve them.

/assign @soltysh

@openshift-ci-robot openshift-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 19, 2019
@wking wking force-pushed the release-extract-cleanup branch from c314c86 to 1604d6d Compare November 19, 2019 00:12
@wking wking changed the title pkg/cli/admin/release/extract_tools: Pass []replacemets to copyAndReplace pkg/cli/admin/release/extract_tools: Pass []replacements to copyAndReplace Nov 19, 2019
wking added a commit to wking/oc that referenced this pull request Nov 23, 2019
…place

We've been injecting the release version into oc since 13215d7 (Bug
1715001: when extracting tools from payload, 'oc version' should
report payload version, 2019-09-10, openshift#88).  This commit refactors the
split helpers from f55426f (Bug 1763728: fix 'oc adm release
extract' version injection, 2019-10-17, openshift#131) with a single helper
that takes a replacement slice.  I've also pushed the unmatched
warning down into the replacement helper itself so we don't have to
return a slice of replacements that did or did not match.  This sets
the stage for injecting release version names into the installer as
well, although I'm not doing that in this commit because Abhinav wants
some time to look into the ecosystem around that [1].

Now that replacements are no longer baked in, I've made the unit test
a bit more readable by dispensing with the fakeInput helpers and just
hard-coding small input/output strings in the test-case definitions.

There's also the "oc is overwriting its own
...RELEASE_VERSION_LOCATION..." constant issue, previously fixed by
ded896d (Bug 1768516: fix extracted-oc adm extract oc, 2019-11-08, openshift#155).
In this commit, I've avoidied that by using ! as the leading character
in the marker constants and replacing it with a null byte when
constructing replacements in extractCommand.  With a single
replacement per marker, we need our marker constant to never match; I
dunno what the previous doubled constant was about (but see the
len(value) point next for why the previous doubled marker worked at
all).

I've also fixed some additional bugs:

* The previous implementation only used len(value) of the marker when
  searching the incoming bytes.  Especially for short strings like
  version replacement, this meant we were only looking for five bytes
  for 4.2.7, which is \x00_REL.  That's not very specific.  It does
  not distinquish between \x00_RELEASE_IMAGE_LOCATION_\x00XX... and
  \x00_RELEASE_VERSION_LOCATION_\x00XX....  It doesn't even
  distinguish between the defaultVersionPadded and
  defaultVersionPrefix constants in pkg/version.  With this commit, we
  search for the full marker, regardless of len(value).

* The previous implementation had:

    nextOffset := end - len(marker)
    ...
    _, wErr := w.Write(buf[:end-nextOffset])
    ...
    copy(buf[:nextOffset], buf[end-nextOffset:end])
    offset = nextOffset

  That was problematic for a few reasons:

  * It didn't write much data.  Substituting for nextOffset, we were
    writing to:

        end - nextOffset
      = end - (end - len(marker))
      = len(marker)

    this makes the buffer size largely meaningless, and means lots of
    inefficient, small reads/writes.  With this commit, we have a
    writeTo variable that is everything except the *last* len(marker).

  * It ignored the amound of data written.  You can *want* to write 1k
    bytes but only actually write 50 bytes with a given Write call.
    That didn't happen often before; because of the previous list
    entry we were only attempting to write a hundred or so bytes at a
    time.  But now that we are trying to write the bulk of the buffer
    size, it happens more often.  With this commit, we keep attempting
    Write until it errors out on us or we finish pushing all the bytes
    we no longer need.

Because 13215d7, f55426f, and ded896d all touched the version
marker, this commit will mean that oc build with this commit and later
will not inject version names into oc built before ded896d.  But
that's ok, because 4.2 binaries have no version markers (just a
RELEASE_IMAGE_LOCATION constant for the installer's marker).  And we
haven't cut 4.3 yet.  So with this commit and no future changes to the
oc marker, we'll be able to inject the version name into all supported
oc which are prepared to receive injected version names.

The Fprintf warning follows package precedent.  Clayton [2]:

> In these commands warnings are printed with fprintf.
>
> Klog is for debugging and servers, not end users.

In action extracting from [3]:

  $ go build -o oc-mine ./cmd/oc
  $ ./oc-mine adm release extract --command=oc quay.io/openshift-release-dev/ocp-release-nightly@sha256:502d184ac8742073cb3007a0ad9abe8672b0a2db37331cfbfb4cb1b564c893fd
  $ ./oc version --client
  Client Version: 4.3.0-0.nightly-2019-11-13-233341

[1]: openshift/installer#2682 (comment)
[2]: openshift#167 (comment)
[3]: https://mirror.openshift.com/pub/openshift-v4/clients/ocp-dev-preview/4.3.0-0.nightly-2019-11-13-233341/release.txt
@wking wking force-pushed the release-extract-cleanup branch from 1604d6d to cbcc1fd Compare November 23, 2019 05:04
…place

We've been injecting the release version into oc since 13215d7 (Bug
1715001: when extracting tools from payload, 'oc version' should
report payload version, 2019-09-10, openshift#88).  This commit refactors the
split helpers from f55426f (Bug 1763728: fix 'oc adm release
extract' version injection, 2019-10-17, openshift#131) with a single helper
that takes a replacement slice.  I've also pushed the unmatched
warning down into the replacement helper itself so we don't have to
return a slice of replacements that did or did not match.  This sets
the stage for injecting release version names into the installer as
well, although I'm not doing that in this commit because Abhinav wants
some time to look into the ecosystem around that [1].

Now that replacements are no longer baked in, I've made the unit test
a bit more readable by dispensing with the fakeInput helpers and just
hard-coding small input/output strings in the test-case definitions.

There's also the "oc is overwriting its own
...RELEASE_VERSION_LOCATION..." constant issue, previously fixed by
ded896d (Bug 1768516: fix extracted-oc adm extract oc, 2019-11-08, openshift#155).
In this commit, I've avoided that by using ! as the leading character
in the marker constants and replacing it with a null byte when
constructing replacements in extractCommand.  With a single
replacement per marker, we need our marker constant to never match; I
dunno what the previous doubled constant was about (but see the
len(value) point next for why the previous doubled marker worked at
all).

I've also fixed some additional bugs:

* The previous implementation only used len(value) of the marker when
  searching the incoming bytes.  Especially for short strings like
  version replacement, this meant we were only looking for five bytes
  for 4.2.7, which is \x00_REL.  That's not very specific.  It does
  not distinguish between \x00_RELEASE_IMAGE_LOCATION_\x00XX... and
  \x00_RELEASE_VERSION_LOCATION_\x00XX....  It doesn't even
  distinguish between the defaultVersionPadded and
  defaultVersionPrefix constants in pkg/version.  With this commit, we
  search for the full marker, regardless of len(value).

* The previous implementation had:

    nextOffset := end - len(marker)
    ...
    _, wErr := w.Write(buf[:end-nextOffset])
    ...
    copy(buf[:nextOffset], buf[end-nextOffset:end])
    offset = nextOffset

  That was problematic for a few reasons:

  * It didn't write much data.  Substituting for nextOffset, we were
    writing to:

        end - nextOffset
      = end - (end - len(marker))
      = len(marker)

    this makes the buffer size largely meaningless, and means lots of
    inefficient, small reads/writes.  With this commit, we have a
    writeTo variable that is everything except the *last* len(marker).

  * It ignored the amount of data written.  You can *want* to write 1k
    bytes but only actually write 50 bytes with a given Write call.
    That didn't happen often before; because of the previous list
    entry we were only attempting to write a hundred or so bytes at a
    time.  But now that we are trying to write the bulk of the buffer
    size, it happens more often.  With this commit, we keep attempting
    Write until it errors out on us or we finish pushing all the bytes
    we no longer need.

Because 13215d7, f55426f, and ded896d all touched the version
marker, this commit will mean that oc build with this commit and later
will not inject version names into oc built before ded896d.  But
that's ok, because 4.2 binaries have no version markers (just a
RELEASE_IMAGE_LOCATION constant for the installer's marker).  And we
haven't cut 4.3 yet.  So with this commit and no future changes to the
oc marker, we'll be able to inject the version name into all supported
oc which are prepared to receive injected version names.

The Fprintf warning follows package precedent.  Clayton [2]:

> In these commands warnings are printed with fprintf.
>
> Klog is for debugging and servers, not end users.

In action extracting from [3]:

  $ go build -o oc-mine ./cmd/oc
  $ ./oc-mine adm release extract --command=oc quay.io/openshift-release-dev/ocp-release-nightly@sha256:502d184ac8742073cb3007a0ad9abe8672b0a2db37331cfbfb4cb1b564c893fd
  $ ./oc version --client
  Client Version: 4.3.0-0.nightly-2019-11-13-233341

[1]: openshift/installer#2682 (comment)
[2]: openshift#167 (comment)
[3]: https://mirror.openshift.com/pub/openshift-v4/clients/ocp-dev-preview/4.3.0-0.nightly-2019-11-13-233341/release.txt
@wking wking force-pushed the release-extract-cleanup branch from cbcc1fd to 2670093 Compare November 23, 2019 05:17
@wking wking changed the title pkg/cli/admin/release/extract_tools: Pass []replacements to copyAndReplace 1775875: pkg/cli/admin/release/extract_tools: Pass []replacements to copyAndReplace Nov 23, 2019
@wking wking changed the title 1775875: pkg/cli/admin/release/extract_tools: Pass []replacements to copyAndReplace Bug 1775875: pkg/cli/admin/release/extract_tools: Pass []replacements to copyAndReplace Nov 23, 2019
@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Nov 23, 2019
@openshift-ci-robot
Copy link

@wking: This pull request references Bugzilla bug 1775875, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Bug 1775875: pkg/cli/admin/release/extract_tools: Pass []replacements to copyAndReplace

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@wking
Copy link
Member Author

wking commented Nov 23, 2019

Now that 4.4 has forked off, I've created a new bug to hang this PR and subsequent backports on.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2019
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: soltysh, wking

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 2, 2019
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

3 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@wking
Copy link
Member Author

wking commented Dec 2, 2019

/cherrypick release-4.3

@openshift-cherrypick-robot

@wking: once the present PR merges, I will cherry-pick it on top of release-4.3 in a new PR and assign it to you.

Details

In response to this:

/cherrypick release-4.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit d3f137b into openshift:master Dec 3, 2019
@openshift-ci-robot
Copy link

@wking: All pull requests linked via external trackers have merged. Bugzilla bug 1775875 has been moved to the MODIFIED state.

Details

In response to this:

Bug 1775875: pkg/cli/admin/release/extract_tools: Pass []replacements to copyAndReplace

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/oc that referenced this pull request Dec 3, 2019
…place

We've been injecting the release version into oc since 13215d7 (Bug
1715001: when extracting tools from payload, 'oc version' should
report payload version, 2019-09-10, openshift#88).  This commit refactors the
split helpers from f55426f (Bug 1763728: fix 'oc adm release
extract' version injection, 2019-10-17, openshift#131) with a single helper
that takes a replacement slice.  I've also pushed the unmatched
warning down into the replacement helper itself so we don't have to
return a slice of replacements that did or did not match.  This sets
the stage for injecting release version names into the installer as
well, although I'm not doing that in this commit because Abhinav wants
some time to look into the ecosystem around that [1].

Now that replacements are no longer baked in, I've made the unit test
a bit more readable by dispensing with the fakeInput helpers and just
hard-coding small input/output strings in the test-case definitions.

There's also the "oc is overwriting its own
...RELEASE_VERSION_LOCATION..." constant issue, previously fixed by
ded896d (Bug 1768516: fix extracted-oc adm extract oc, 2019-11-08, openshift#155).
In this commit, I've avoided that by using ! as the leading character
in the marker constants and replacing it with a null byte when
constructing replacements in extractCommand.  With a single
replacement per marker, we need our marker constant to never match; I
dunno what the previous doubled constant was about (but see the
len(value) point next for why the previous doubled marker worked at
all).

I've also fixed some additional bugs:

* The previous implementation only used len(value) of the marker when
  searching the incoming bytes.  Especially for short strings like
  version replacement, this meant we were only looking for five bytes
  for 4.2.7, which is \x00_REL.  That's not very specific.  It does
  not distinguish between \x00_RELEASE_IMAGE_LOCATION_\x00XX... and
  \x00_RELEASE_VERSION_LOCATION_\x00XX....  It doesn't even
  distinguish between the defaultVersionPadded and
  defaultVersionPrefix constants in pkg/version.  With this commit, we
  search for the full marker, regardless of len(value).

* The previous implementation had:

    nextOffset := end - len(marker)
    ...
    _, wErr := w.Write(buf[:end-nextOffset])
    ...
    copy(buf[:nextOffset], buf[end-nextOffset:end])
    offset = nextOffset

  That was problematic for a few reasons:

  * It didn't write much data.  Substituting for nextOffset, we were
    writing to:

        end - nextOffset
      = end - (end - len(marker))
      = len(marker)

    this makes the buffer size largely meaningless, and means lots of
    inefficient, small reads/writes.  With this commit, we have a
    writeTo variable that is everything except the *last* len(marker).

  * It ignored the amount of data written.  You can *want* to write 1k
    bytes but only actually write 50 bytes with a given Write call.
    That didn't happen often before; because of the previous list
    entry we were only attempting to write a hundred or so bytes at a
    time.  But now that we are trying to write the bulk of the buffer
    size, it happens more often.  With this commit, we keep attempting
    Write until it errors out on us or we finish pushing all the bytes
    we no longer need.

Because 13215d7, f55426f, and ded896d all touched the version
marker, this commit will mean that oc build with this commit and later
will not inject version names into oc built before ded896d.  But
that's ok, because 4.2 binaries have no version markers (just a
RELEASE_IMAGE_LOCATION constant for the installer's marker).  And we
haven't cut 4.3 yet.  So with this commit and no future changes to the
oc marker, we'll be able to inject the version name into all supported
oc which are prepared to receive injected version names.

The Fprintf warning follows package precedent.  Clayton [2]:

> In these commands warnings are printed with fprintf.
>
> Klog is for debugging and servers, not end users.

In action extracting from [3]:

  $ go build -o oc-mine ./cmd/oc
  $ ./oc-mine adm release extract --command=oc quay.io/openshift-release-dev/ocp-release-nightly@sha256:502d184ac8742073cb3007a0ad9abe8672b0a2db37331cfbfb4cb1b564c893fd
  $ ./oc version --client
  Client Version: 4.3.0-0.nightly-2019-11-13-233341

[1]: openshift/installer#2682 (comment)
[2]: openshift#167 (comment)
[3]: https://mirror.openshift.com/pub/openshift-v4/clients/ocp-dev-preview/4.3.0-0.nightly-2019-11-13-233341/release.txt
@openshift-cherrypick-robot

@wking: new pull request created: #198

Details

In response to this:

/cherrypick release-4.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants