Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hack/verify-file-sizes.sh] Support Mac OS X #124156

Merged

Conversation

bells17
Copy link
Contributor

@bells17 bells17 commented Apr 2, 2024

What type of PR is this?

/kind bug
/sig testing

What this PR does / why we need it:

Enable the hack/verify-file-sizes.sh script to run successfully on Mac OS X.

Which issue(s) this PR fixes:

Fixes #124155

Ref: #121549

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. labels Apr 2, 2024
@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.30 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.30.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Tue Apr 2 14:19:09 UTC 2024.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 2, 2024
@bells17
Copy link
Contributor Author

bells17 commented Apr 2, 2024

/sig testing

@k8s-ci-robot k8s-ci-robot added sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 2, 2024
@bells17
Copy link
Contributor Author

bells17 commented Apr 2, 2024

/cc @pohly

@k8s-ci-robot k8s-ci-robot requested a review from pohly April 2, 2024 19:23
local file="$1"
case "$(uname -s)" in
Darwin)
stat -f %z "$file" | tr -d '\n'
Copy link
Member

Choose a reason for hiding this comment

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

If this line works well on Linux, why not use it directly in Line 61?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carlory Thank you for your review.
Regarding the options for the stat command, I tried it on Linux, and here's what I found:

$ touch samplefile

$ stat -f %z samplefile | tr -d '\n'
stat: cannot read file system information for '%z': No such file or directory
  File: "samplefile"    ID: 0        Namelen: 255     Type: fuseblkBlock size: 1048576    Fundamental block size: 4096Blocks: Total: 59840624   Free: 18538697   Available: 18538697Inodes: Total: 744080125  Free: 741547880

$ stat --printf %z ./samplefile | tr -d '\n'
2024-04-03 03:25:17.374582976 +0000

$ stat --printf %s ./samplefile
0

As shown above, an error occurred with stat -f %z, so I am switching options and such depending on whether the environment is Linux or Mac OS X.

Copy link
Member

Choose a reason for hiding this comment

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

this sort of thing tends to cause problems because even on darwin you may have gnu coreutils installed, check e.g. when we require gnu-sed.

wc -c < "$file" would work portably

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BenTheElder Thank you for your comment.
I have changed the implementation to use wc -c < "$file". Please review it when you have time.

Just to be safe, I've attached the test results below after verifying the operation on both Mac OS X and Linux:

Mac OS X

echo "abc" > samplefile
size=$(wc -c < samplefile)
echo "size: $size"
for i in 3 4
do
  maxsize=$i
  if [ "${size}" -gt "$maxsize" ]; then
    echo "size is greater than maxsize"
  else
    echo "size is less than or equal to maxsize"
  fi
done
size:        4
size is greater than maxsize
size is less than or equal to maxsize

Linux

echo "abc" > samplefile
size=$(wc -c < samplefile)
echo "size: $size"
for i in 3 4
do
  maxsize=$i
  if [ "${size}" -gt "$maxsize" ]; then
    echo "size is greater than maxsize"
  else
    echo "size is less than or equal to maxsize"
  fi
done
size: 4
size is greater than maxsize
size is less than or equal to maxsize

Copy link
Member

Choose a reason for hiding this comment

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

@bells17 bells17 requested a review from carlory April 12, 2024 07:12
@bells17
Copy link
Contributor Author

bells17 commented Apr 12, 2024

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 12, 2024
@bells17
Copy link
Contributor Author

bells17 commented Apr 12, 2024

/priority backlog

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 12, 2024
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 19, 2024
Copy link
Member

@BenTheElder BenTheElder 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

thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 19, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: d1ec4431fac282a9a5dd5fc3269ca41f077e39a4

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bells17, BenTheElder

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 19, 2024
@k8s-ci-robot k8s-ci-robot merged commit bad0f06 into kubernetes:master Apr 19, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Apr 19, 2024
@bells17 bells17 deleted the support-mac-os-verify-file-size branch April 21, 2024 14:12
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note-none Denotes a PR that doesn't merit a release note. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hack/verify-file-sizes.sh does not support Mac OS X
4 participants