scooby87 8540e746f8 fix(seaweedfs): parse naming-audit timestamps portably across GNU and BSD date (#4282)
Fixes #4273

`hack/seaweedfs-naming-audit.sh` read PV and `first_deployed` timestamps
with `date -u -d`, a spelling only GNU `date` accepts. On a host with
BSD `date` (macOS, or any host without GNU coreutils on `PATH`) the call
failed, its stderr was discarded by the `2>/dev/null` on the same line,
and `|| return 0` turned that host-tool failure into the audit's "no
epoch available" signal. Every tenant then read as MIXED with "direction
cannot be established", as though the cluster carried no evidence rather
than the host carrying no readable clock — and since the audit gates a
destructive runbook step, that indistinguishability is the problem.

A new `parse_epoch` helper tries the GNU spelling (`date -d`) and then
the BSD one (`date -j -f`), each with its own stderr muted, and uses
whichever the host speaks. Both call sites (`first_deployed` and
`pv_epoch`) route through it, so the audit now works on GNU and BSD
hosts alike with no behaviour change for a valid timestamp on a GNU
host.

Crucially it keeps the two outcomes the issue asks to be separated
distinct. A timestamp that is *present but readable by neither form* is
no longer folded into the silent absent-evidence branch: `parse_epoch`
fails loudly via `audit_fatal`, names the value, and aborts — the same
fail-closed contract the rest of the script already follows. The
legitimate absent-evidence cases the comment at the `pv_epoch` block
reasons about — an unbound claim, a NotFound PVC/PV — stay on their
benign path and still degrade to the conservative "classify by hand"
note.

## Tests

The suite is bats via `hack/cozytest.sh`. New coverage, each RED before
the fix and GREEN after (mutation-verified: reverting the fix turns them
RED again):

- `parse_epoch` reads an RFC3339 timestamp to the epoch the issue
quotes, on GNU or BSD date. The test runs under a deliberately non-UTC
`TZ` (`XXX5`), not UTC: both call sites pass `-u`, which makes GNU and
BSD alike parse the zoneless 19-char value as UTC, so the absolute epoch
is TZ-independent — measured on a BSD host, `1789470000` with `-u`
versus `1789488000` without. Dropping `-u` would move the value, so
running under a non-UTC `TZ` pins that flag as a regression guard. The
classifier's own relative comparison is timezone-immune regardless.
- `parse_epoch` fails loudly, on stderr, on a value neither form can
read — and writes nothing to stdout.
- The MIXED path classifies as OVERLAP under a BSD-only `date`,
byte-identical to the golden the GNU path produces, instead of
"direction cannot be established". A `date` shim on `PATH` reproduces
the bug deterministically on a GNU CI runner, where it is otherwise
invisible.
- The `first_deployed` call site (the second one the issue names) parses
under a BSD-only `date` instead of aborting the whole audit.
- A PV whose `creationTimestamp` is present but unparseable is fatal,
not the absent-evidence branch — proving the two are not collapsed at
the real call site.

`dash -n` confirms the script stays POSIX-clean for the CI shell.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
  - Improved timestamp handling across GNU and BSD environments.
- Audits now report an explicit failure when a provided deployment or
volume timestamp cannot be parsed, instead of treating it as missing
evidence.
  - Preserved the existing behavior for genuinely absent timestamps.

- **Tests**
- Added coverage for GNU and BSD timestamp parsing, invalid values,
deployment timestamps, and invalid volume timestamps.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-18 20:28:43 +03:00
2025-10-08 09:43:34 +05:00
2024-02-08 12:04:32 +01:00

Cozystack Cozystack

GitHub Release Apache-2.0 License Commit activity OpenSSF Best Practices OpenSSF Scorecard CLOMonitor Support

Cozystack

Cozystack is a free and open-source platform and framework for building clouds.

Cozystack is a CNCF Sandbox project that was originally built and sponsored by Ænix.

With Cozystack, you can transform a bunch of servers into an intelligent system with a simple REST API for spawning Kubernetes clusters, Database-as-a-Service, virtual machines, load balancers, HTTP caching services, and other services with ease.

Use Cozystack to build your own cloud or provide a cost-effective development environment.

Cozystack user interface

Use-Cases

Documentation

The documentation is located on the cozystack.io website.

Read the Getting Started section for a quick start.

If you encounter any difficulties, start with the troubleshooting guide and work your way through the process that we've outlined.

Versioning

Versioning adheres to the Semantic Versioning principles.
A full list of the available releases is available in the GitHub repository's Release section.

Contributions

Contributions are highly appreciated and very welcomed!

In case of bugs, please check if the issue has already been opened by checking the GitHub Issues section. If it isn't, you can open a new one. A detailed report will help us replicate it, assess it, and work on a fix.

You are welcome to take on the fix yourself. Commits are used to generate the changelog, and their author will be referenced in it.

If you have a concrete feature request, open an issue. For a cross-cutting or architectural change, open a design proposal in the community repo. For questions or early ideas, use GitHub Discussions. See CONTRIBUTING.md for the full routing.

Community

You are welcome to join us in #cozystack, on either CNCF Slack (get an invite) or Kubernetes Slack (get an invite), in our Telegram group, and at our community meetings. Add them to your Google Calendar or iCal for convenience.

Project documents

Document What it covers
Governance How decisions are made and who makes them
Contributor Ladder How to grow from contributor to maintainer
Maintainers Who maintains the project
Code of Conduct What we expect of each other
Security Policy Reporting a vulnerability, and which releases get fixes
Adopters Who runs Cozystack in production
Roadmap Where the project is going

License

Cozystack is licensed under Apache 2.0.
The code is provided as-is with no warranties.

Commercial Support

A list of companies providing commercial support for this project can be found on official site.

Languages
Go 47.2%
Shell 37.6%
TypeScript 7%
Go Template 5.4%
Makefile 1.4%
Other 1.2%