8000 🐛 fix e2e by abahmed · Pull Request #533 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ jobs:
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4
uses: github/codeql-action/init@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4
with:
languages: actions
build-mode: none

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4
uses: github/codeql-action/analyze@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4
with:
category: "/language:actions"

Expand All @@ -70,12 +70,12 @@ jobs:
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4
uses: github/codeql-action/init@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4
with:
languages: go
build-mode: autobuild

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4
uses: github/codeql-action/analyze@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4
with:
category: "/language:go"
15 changes: 11 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,17 @@ jobs:
echo "tagging at $RESOLVED"

# The commit being released must already have passed the required CI
# run, the security workflow, and a full nightly-equivalent E2E run
# (run name "E2E full") on main. Read from the Actions API with the
# read-only GITHUB_TOKEN. A dry run reports the gate without failing.
# run and the security workflow on main. Stable and patch releases also
# need a full nightly-equivalent E2E run (run name "E2E full"); an rc is
# a pre-release, so it skips E2E and stable stays the E2E gate. Read
# from the Actions API with the read-only GITHUB_TOKEN. A dry run
# reports the gate without failing.
- name: Require green CI, security and E2E on the target commit
if: ${{ steps.meta.outputs.resume != 'true' }}
env:
SHA: ${{ steps.target.outputs.sha }}
DRY_RUN: ${{ inputs.dry_run }}
COMMAND: ${{ inputs.command }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
Expand All @@ -345,7 +348,11 @@ jobs:
}
check ci.yml ""
check security.yml ""
check e2e.yml "E2E full"
if [ "$COMMAND" = rc ]; then
echo "e2e.yml: not required for an rc release"
else
check e2e.yml "E2E full"
fi
if [ -n "$missing" ]; then
message="no successful run on main for $SHA:$missing. Run the missing workflow on this commit and retry."
if [ "$DRY_RUN" = true ]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
publish_results: true

- name: Upload Scorecard results
uses: github/codeql-action/upload-sarif@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4
uses: github/codeql-action/upload-sarif@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4
with:
sarif_file: scorecard-results.sarif
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Without --platform=$BUILDPLATFORM this stage runs under QEMU for arm64,
# arm/v7 and arm/v6, 10BC8 which is what made a release build take over an hour.
# Go cross-compiles fine and CGO is off, so emulation buys nothing.
FROM --platform=$BUILDPLATFORM golang:1.27-alpine@sha256:cf6fca6641884b8433441b2b0652976f975e1d0fdd26d177eaaf8596087f3125 AS builder
FROM --platform=$BUILDPLATFORM golang:1.27-alpine@sha256:8a5910f31396cd4d89662f56c68b3ae31d374308270a1c3bd96672ee5ed43414 AS builder

ARG RELEASE_VERSION="dev"
ARG GIT_COMMIT="none"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</a>
</p>

<h2 align="center">Stop reading alerts. Start fixing the cause.</h2>
<h2 align="center">See what broke. Understand why. Know what to do next. 👀🧠⚡</h2>

<p align="center">
kwatch is the on-call teammate for your Kubernetes cluster. When something
Expand Down
7 changes: 4 additions & 3 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,9 @@
scenarios` and `Operational validation`; required status checks are now
`Verify`, `Image`, `Chart lifecycle`, `Go dependency scan` and
`Analyze (actions)` (import `.github/rulesets/main-branch.json`). A
release now requires green CI, security and full E2E runs on the tagged
commit, and the image is scanned before it is pushed.
release now requires green CI and security runs on the tagged commit,
plus a full E2E run for stable and patch releases (an rc skips E2E),
and the image is scanned before it is pushed.
- **Readiness follows required sources.** `/readyz` now fails while a
required source (Pods, Nodes) is unavailable, such as after its RBAC
permission is revoked, and recovers with it. A source counts as synced
Expand Down Expand Up @@ -1322,7 +1323,7 @@ An RC should not be promoted until all of these hold:

- [ ] RC has been published for at least **2 weeks** of soak (unless a critical fix is blocking).
- [ ] No open **critical** issues / known regressions against the RC.
- [ ] `CI`, `Security and supply chain` and a full `E2E` run are green on the RC commit (the release workflow enforces this).
- [ ] `CI`, `Security and supply chain` and a full `E2E` run are green on the RC commit (the release workflow enforces E2E when promoting to stable; an rc itself needs only CI and security).
- [ ] `helm lint` + `test_helm.sh` pass for the released chart.
- [ ] Release notes reviewed (generated automatically from merged commit titles).
- [ ] README and `docs/` contain no `🚧 Unreleased` banners (stripped automatically on stable).
Expand Down
7 changes: 4 additions & 3 deletions deploy/chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ apiVersion: v2
name: kwatch
version: "0.10.5"
appVersion: "v0.10.5"
description: monitor all changes in your Kubernetes(K8s) cluster, detects crashes
in your running apps in realtime, and publishes notifications to your channels (Slack,
Discord, etc.) instantly
description: >-
See what broke. Understand why. Know what to do next. 👀🧠⚡
kwatch watches your Kubernetes cluster, finds the one thing that caused a
failure and tells your team in plain words, with the command to fix it.
type: application
home: https://kwatch.dev
icon: https://kwatch.dev/img/kwatch-logo.png
Expand Down
8 changes: 5 additions & 3 deletions docs/production-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,11 @@ Rulesets → New ruleset → Import a ruleset, or with
.github/rulesets/main-branch.json`. Remove the old `Check` required
status check when you apply it.

The `Release` workflow refuses to tag a commit unless `CI`, `Security and
supply chain`, and a full `E2E` run (run name `E2E full`, the nightly run or
an unfiltered dispatch) all succeeded on `main` for that exact commit.
The `Release` workflow refuses to tag a commit unless `CI` and `Security and
supply chain` succeeded on `main` for that exact commit. Stable and patch
releases also need a full `E2E` run (run name `E2E full`, the nightly run or
an unfiltered dispatch) on that commit; an rc pre-release skips E2E, so the
E2E gate applies when the rc is promoted to stable.
`Publish` then builds the release image, scans it with Trivy before anything
is pushed, pushes the multi-platform image, moves `latest` for stable
releases, and signs and attests the digest.
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ require (
github.com/google/uuid v1.6.0
github.com/prometheus/client_golang v1.24.1
github.com/robfig/cron/v3 v3.0.1
github.com/slack-go/slack v0.29.0
github.com/slack-go/slack v0.30.1
github.com/stretchr/testify v1.12.1
go.etcd.io/bbolt v1.5.0
gopkg.in/mail.v2 v2.3.1
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.37.0
k8s.io/apimachinery v0.37.0
k8s.io/client-go v0.37.0
k8s.io/api v0.37.1
k8s.io/apimachinery v0.37.1
k8s.io/client-go v0.37.1
k8s.io/klog/v2 v2.140.0
k8s.io/utils v0.0.0-20260707023825-cf1189d6abe3
sigs.k8s.io/e2e-framework v0.7.0
Expand Down Expand Up @@ -80,7 +80,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/component-base v0.35.3 // indirect
k8s.io/kube-openapi v0.0.0-20260821135717-be32def86098 // indirect
k8s.io/streaming v0.37.0 // indirect
k8s.io/streaming v0.37.1 // indirect
sigs.k8s.io/controller-runtime v0.23.3 // indirect
sigs.k8s.io/json v0.0.0-20260909141634-11ed52e25bc5 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/slack-go/slack v0.29.0 h1:ohhMNgp9DmPKiLhH/pNZV4NxhOXKgNy0SH8FzVHNerI=
github.com/slack-go/slack v0.29.0/go.mod h1:UEe+jmo9WLlwHB04qsOrTDvqM7Aa4rQL3O5wF3n0hx4=
github.com/slack-go/slack v0.30.1 h1:q6FjZssqts6hJ+DRWCnnO2YVUh+E3/UNrC0EIO2xci8=
github.com/slack-go/slack v0.30.1/go.mod h1:radSmEe8GEgE+aK980ZafMR0AQhiZjADptN5k/gOw34=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -193,22 +193,22 @@ gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk=
gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.37.0 h1:Z//Vj9N7RA/yS2sDmxyeo7h+RR4zbUrd2vrd3Z0TbB4=
k8s.io/api v0.37.0/go.mod h1:LKXgcJWMc+f4OLbP5SFR8rulEg07zZhpi/zMULiBImk=
k8s.io/api v0.37.1 h1:l6N77U7tjwB5L056bgrBTJIEdevac/naBZ3iSvDNfpM=
k8s.io/api v0.37.1/go.mod h1:zSlbB1YpJ1YQlFVQy20UYll81UJSJJUMLhkhvg6Z78M=
k8s.io/apiextensions-apiserver v0.35.0 h1:3xHk2rTOdWXXJM+RDQZJvdx0yEOgC0FgQ1PlJatA5T4=
k8s.io/apiextensions-apiserver v0.35.0/go.mod h1:E1Ahk9SADaLQ4qtzYFkwUqusXTcaV2uw3l14aqpL2LU=
k8s.io/apimachinery v0.37.0 h1:Np2AbDtf8x6RDHiD8T9LbKJ9gaegeVNa8yNm5FuGKm0=
k8s.io/apimachinery v0.37.0/go.mod h1:RN3nhprFSCxOi5Selxd7oMTXOe/c+ZbcE7Im+TS2zkE=
k8s.io/client-go v0.37.0 h1:nsN31fy8wBySuZ+QRnKmrjRSQLOG2rvoGN0tKd12zhQ=
k8s.io/client-go v0.37.0/go.mod h1:FcGqw+Ll/gNQiq+nPGY1Oyt9y7SgDh1d3MW3RFDEbn0=
k8s.io/apimachinery v0.37.1 h1:hGCYyvKHCwtwMitj2vU4vYx0Z16N9GyZk9BBnz0wDAE=
k8s.io/apimachinery v0.37.1/go.mod h1:jF84AyUi/IRIXRot5f+lm6MpxoWI+F1XgjaMmwCdTFw=
k8s.io/client-go v0.37.1 h1:QTv/5ha4jAHtW9qxxVBkQVFBRDb4jHfFopQqqMdc+wM=
k8s.io/client-go v0.37.1/go.mod h1:dnAPtTnCNY38Ho04D2KdY1F4IKausa9UbqaAZKl60SY=
k8s.io/component-base v0.35.3 h1:mbKbzoIMy7JDWS/wqZobYW1JDVRn/RKRaoMQHP9c4P0=
k8s.io/component-base v0.35.3/go.mod h1:IZ8LEG30kPN4Et5NeC7vjNv5aU73ku5MS15iZyvyMYk=
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
k8s.io/kube-openapi v0.0.0-20260821135717-be32def86098 h1:z5+pcu1jTyKK5mNTe2/+x+U6Uuv9jRVOJQLaBJJMpeI=
k8s.io/kube-openapi v0.0.0-20260821135717-be32def86098/go.mod h1:0/mqHCVhlumdJ3BhCfnjSZQE037nAhNodh1/hK0T8/I=
k8s.io/streaming v0.37.0 h1:iPBUZLZiKt5bV+lxJurASMOV07VuBhNpiwJt2//AWrM=
k8s.io/streaming v0.37.0/go.mod h1:APlJR26ZWRcVy5bIEj0QRrKUXROtBHPcxl2NT7EAzPU=
k8s.io/streaming v0.37.1 h1:TpzVfQeFuVndn2g9mFqxy1UcUYPwDzqjUmwR/IzJCWc=
k8s.io/streaming v0.37.1/go.mod h1:APlJR26ZWRcVy5bIEj0QRrKUXROtBHPcxl2NT7EAzPU=
k8s.io/utils v0.0.0-20260707023825-cf1189d6abe3 h1:jVkFFVfXdXP74B/zbO3hM3hpSFD0xvhQ5U686DPurkE=
k8s.io/utils v0.0.0-20260707023825-cf1189d6abe3/go.mod h1:M2s5JB1lIYP3jzZdorPLHXIPJzt9vv2muW5a6L9DtNM=
sigs.k8s.io/controller-runtime v0.23.3 h1:VjB/vhoPoA9l1kEKZHBMnQF33tdCLQKJtydy4iqwZ80=
Expand Down
16 changes: 12 additions & 4 deletions internal/detection/detectors/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,19 @@ var startReasons = map[string]bool{
}

// overcomeAtStart reports whether note is a start-up failure of a pod that
// became ready after it: the retry worked, so the event is history, not a
// failure. A failure after the pod became ready still counts.
// ran after it: the retry worked, so the event is history, not a failure.
// A pod that became ready after the note, or whose containers started
// after it, overcame it even if it is not ready now (its node may be
// lost). A failure after that still counts.
func overcomeAtStart(e inventory.Entity, note inventory.Note) bool {
if e.ID.Kind != kube.KindPod || !startReasons[note.Reason] ||
!flag(e, kube.AttrReady) {
if e.ID.Kind != kube.KindPod || !startReasons[note.Reason] {
return false
}
started := timestamp(e, kube.AttrContainersStarted)
if !started.IsZero() && !started.Before(note.At) {
return true
}
if !flag(e, kube.AttrReady) {
return false
}
readySince := timestamp(e, kube.AttrReadySince)
Expand Down
18 changes: 13 additions & 5 deletions internal/detection/detectors/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,28 @@ func TestEventStartFailureOvercomeByReadyPod(t *testing.T) {
name string
ready bool
readySince time.Time
started time.Time
want int
}{
{"ready after the event", true, mount.Add(time.Second), 0},
{"ready before the event", true, mount.Add(-time.Minute), 1},
{"never ready", false, time.Time{}, 1},
{"ready after the event", true, mount.Add(time.Second),
time.Time{}, 0},
{"ready before the event", true, mount.Add(-time.Minute),
time.Time{}, 1},
{"never ready", false, time.Time{}, time.Time{}, 1},
{"not ready now, container started after the event", false,
now.Add(-10 * time.Second), mount.Add(time.Second), 0},
{"not ready now, container started before the event", false,
now.Add(-10 * time.Second), mount.Add(-time.Minute), 1},
} {
t.Run(tc.name, func(t *testing.T) {
model := newTestModel()
id := inventory.CoreID(kube.KindPod, "ns", "tenant-0")
model.Apply(inventory.Observation{
Kind: inventory.Observed, Source: "test", At: mount,
Entity: id, Attributes: map[string]inventory.Value{
kube.AttrReady: inventory.Bool(tc.ready),
kube.AttrReadySince: inventory.Time(tc.readySince),
kube.AttrReady: inventory.Bool(tc.ready),
kube.AttrReadySince: inventory.Time(tc.readySince),
kube.AttrContainersStarted: inventory.Time(tc.started),
},
})
warn(model, id, mount, "FailedMount",
Expand Down
8 changes: 6 additions & 2 deletions internal/inventory/kube/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ const (
AttrImageID = "image.id"
// AttrProbePorts lists the ports the container's probes connect to,
// named ports resolved against the container's own port names.
AttrProbePorts = "probe.ports"
AttrStartedAt = "started.at"
AttrProbePorts = "probe.ports"
AttrStartedAt = "started.at"
// AttrContainersStarted is on a pod: when its newest container
// started. The kubelet only starts containers once their volumes
// and network are ready, and the value survives a lost node.
AttrContainersStarted = "containers.started"
AttrImage = "image"
AttrInit = "init"
AttrSidecar = "sidecar"
Expand Down
30 changes: 30 additions & 0 deletions internal/inventory/kube/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kube
import (
"sort"
"strings"
"time"

corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -120,6 +121,9 @@ func podAttributes(pod *corev1.Pod) map[string]inventory.Value {
if !pod.CreationTimestamp.IsZero() {
attrs[AttrCreated] = inventory.Time(pod.CreationTimestamp.Time)
}
if started := newestContainerStart(pod); !started.IsZero() {
attrs[AttrContainersStarted] = inventory.Time(started)
}
conditions := make([]condition, 0, len(pod.Status.Conditions))
for _, c := range pod.Status.Conditions {
conditions = append(conditions, condition{
Expand All @@ -141,6 +145,32 @@ func podAttributes(pod *corev1.Pod) map[string]inventory.Value {
return attrs
}

// newestContainerStart is when the pod's latest container started, running
// or not; zero when none has.
func newestContainerStart(pod *corev1.Pod) time.Time {
var newest time.Time
for _, s := range pod.Status.ContainerStatuses {
for _, at := range []time.Time{
startOf(s.State), startOf(s.LastTerminationState),
} {
if at.After(newest) {
newest = at
}
}
}
return newest
}

func startOf(state corev1.ContainerState) time.Time {
switch {
case state.Running != nil:
return state.Running.StartedAt.Time
case state.Terminated != nil:
return state.Terminated.StartedAt.Time
}
return time.Time{}
}

// podRef is one Secret or ConfigMap reference and whether the pod starts
// without the object.
type podRef struct {
Expand Down
Loading
Loading
0