Files
my-rook-config/tests/framework/utils/helm_helper.go
T
Joshua Hoblitt 8839f0775d ci: reduce CephUpgradeSuite flakes
The CephUpgradeSuite workflow failed ~31% of PR runs vs the ~19%
broken-PR baseline of the other integration suites. Classifying the
failing step of every failed run from the last ~400 PR runs and the
logs of every failure on non-dependabot branches shows the excess
comes from a handful of too-tight waits, unretried network fetches,
and environment races rather than from the upgrade logic itself:

- The biggest class (21 of 44 genuine test-phase failure runs):
  "giving up waiting for deployment(s) with label
  app=rook-ceph-{rgw,osd},ceph-version!=..." during the
  Squid->Tentacle upgrade. The operator updates daemons sequentially
  (mons, mgr, osds with PG health gates between them, mds, rgw), so
  each later daemon's fixed 275s wait also absorbs the time spent on
  every daemon before it; rgw, last in the sequence, failed most
  often. The mon wait was already extended for slow image pulls in
  98bd03a42; extend the same retry count to all the daemon waits.

- ~7 runs: "snapshot controller is not ready" in the Helm upgrade
  path. WaitForSnapshotController(30) allows only 150s, and the logs
  show the deployment still converging (readyreplicas 1 < replicas 2)
  on the final poll. Raise to 90 retries.

- InstallOrUpgradeHelmRepoChart ran helm with no retry; an observed
  failure fetched the ceph-csi-drivers chart tarball from GitHub
  release assets and got a 504. Retry up to 5 times, as
  InstallLocalHelmChart already does.

- Raise the go test timeouts (2400s->3600s rook, 1800s->2700s helm).
  Failed runs ended in "panic: test timed out" during teardown, which
  aborts cleanup and log collection; the longer daemon waits above
  also need the headroom.

- The "setup cluster resources" composite action (shared by all
  suites) accounted for half of all failed jobs. The one steady class
  there (8 distinct runs across 7 different days): minikube exits with
  K8S_FAIL_CONNECT (code 40) when the requested kubernetes version is
  missing from its bundled version list, because it then validates the
  version with an anonymous GitHub API request (GITHUB_TOKEN is not
  honored on that code path), and anonymous requests from shared
  runner IPs are regularly rate-limited. minikube 1.38.x predates
  v1.35.5, so only the v1.35.5 jobs hit this class. Pass --force to
  minikube start to skip that check: the kubernetes versions used in
  CI are pinned constants already validated by the PRs that bump
  them, and an invalid version would still fail fast at the kubeadm
  download. Also seen twice: dpkg failing on a corrupt cri-dockerd .deb
  because curl ran without --fail and saved an HTTP error page as the
  package; add --fail and retries.

- On runners without the /mnt resource disk, the fallback OSD disk is
  an iSCSI (LIO) device and use_local_disk_for_integration_test
  returned early on those runners, skipping the udev nowatch
  workaround for the device re-probe storms of rook issue 8975. A burn-in
  failure on this PR captured the consequence with full kernel
  forensics: ~100 udev change events on the OSD disk, and ceph-volume
  activate wedged in uninterruptible sleep on the block device lock
  (blkdev_llseek -> rwsem_down_write_slowpath) for 18+ minutes during
  the ceph version upgrade while the cluster's only OSD stayed down.
  Install the nowatch rule before the early return so it applies to
  every runner type, and before the disk is first written rather than
  after.

- One burn-in round failed before the upgrade even began: the
  pre-upgrade PVC create on the Helm path expired WaitUntilPVCIsBound
  (RetryLoop, 275s) while the CSI provisioner pods were still
  starting. Set RETRY_MAX=110 for this workflow to double the
  framework's base wait budget, instead of extending individual waits
  one flake at a time.

- minikube also exits with GUEST_START (code 80) when its internal 6
  minute node-ready wait expires on slow runners (5 runs in the
  dataset, two more observed while burning in this PR, one of them on
  another suite). Pass --wait-timeout=15m to minikube start.

Not addressed (small or episodic classes): OSDs never coming up on
initial deploy (3 runs, possibly the same udev/iSCSI wedge), the
filesystem not becoming active (2 runs), and several day-clustered
minikube incidents (exit codes 65/67/90).

Signed-off-by: Joshua Hoblitt <josh@hoblitt.com>
(cherry picked from commit cff8b7f311)
2026-06-16 21:14:15 +00:00

241 lines
7.4 KiB
Go

/*
Copyright 2016 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
"time"
"gopkg.in/yaml.v2"
"github.com/pkg/errors"
"github.com/rook/rook/pkg/util/exec"
)
// HelmHelper is wrapper for running helm commands
type HelmHelper struct {
executor *exec.CommandExecutor
HelmPath string
}
// NewHelmHelper creates a instance of HelmHelper
func NewHelmHelper(helmPath string) *HelmHelper {
executor := &exec.CommandExecutor{}
return &HelmHelper{executor: executor, HelmPath: helmPath}
}
// Execute is wrapper for executing helm commands
func (h *HelmHelper) Execute(args ...string) (string, error) {
result, err := h.executor.ExecuteCommandWithOutput(h.HelmPath, args...)
if err != nil {
logger.Errorf("Errors Encountered while executing helm command %v: %v", result, err)
return result, fmt.Errorf("failed to run helm command on args %v : %v , err -> %v", args, result, err)
}
return result, nil
}
func createValuesFile(path string, values map[string]interface{}) error {
f, err := os.Create(path)
if err != nil {
return fmt.Errorf("could not create values file: %v", err)
}
defer func() {
closeErr := f.Close()
if err == nil {
err = closeErr
}
}()
output, err := yaml.Marshal(values)
if err != nil {
return fmt.Errorf("could not serialize values file: %v", err)
}
logger.Debugf("Writing values file %v: \n%v", path, string(output))
if _, err := f.Write(output); err != nil {
return fmt.Errorf("could not write values file: %v", err)
}
if err := f.Sync(); err != nil {
return fmt.Errorf("could not flush values file")
}
return nil
}
// InstallLocalHelmChart installs a give helm chart
func (h *HelmHelper) InstallLocalHelmChart(upgrade bool, namespace, chart string, values map[string]interface{}) error {
rootDir, err := FindRookRoot()
if err != nil {
return errors.Wrap(err, "failed to find rook root")
}
var cmdArgs []string
chartDir := path.Join(rootDir, fmt.Sprintf("deploy/charts/%s/", chart))
if upgrade {
cmdArgs = []string{"upgrade"}
} else {
cmdArgs = []string{"install", "--create-namespace"}
}
cmdArgs = append(cmdArgs, chart, chartDir)
if namespace != "" {
cmdArgs = append(cmdArgs, "--namespace", namespace)
}
var lastErr error
maxRetries := 5
for i := 0; i < maxRetries; i++ {
err = h.installChart(cmdArgs, values)
if err != nil {
lastErr = fmt.Errorf("failed to install local helm chart %s with in namespace: %v, err=%v", chart, namespace, err)
logger.Error(lastErr)
time.Sleep(time.Second)
continue
}
logger.Infof("helm chart %q installed successfully after %d attempt(s)", chart, i+1)
return nil
}
logger.Errorf("failed to install helm chart %s after %d attempts", chart, maxRetries)
return lastErr
}
func (h *HelmHelper) InstallVersionedChart(namespace, chart, version string, values map[string]interface{}) error {
logger.Infof("adding rook-release helm repo")
cmdArgs := []string{"repo", "add", "rook-release", "https://charts.rook.io/release"}
_, err := h.Execute(cmdArgs...)
if err != nil {
// Continue on error in case the repo already was added
logger.Warningf("failed to add repo rook-release, err=%v", err)
}
logger.Infof("installing helm chart %s with version %s", chart, version)
cmdArgs = []string{"install", "--create-namespace", chart, "rook-release/" + chart, "--version=" + version}
if namespace != "" {
cmdArgs = append(cmdArgs, "--namespace", namespace)
}
err = h.installChart(cmdArgs, values)
if err != nil {
return fmt.Errorf("failed to install helm chart %s with version %s in namespace: %v, err=%v", chart, version, namespace, err)
}
return nil
}
func (h *HelmHelper) InstallOrUpgradeHelmRepoChart(namespace, release, repoURL, repoName, chartName, version string, values map[string]interface{}) error {
if _, err := h.Execute("repo", "add", repoName, repoURL, "--force-update"); err != nil {
return fmt.Errorf("failed to add helm repo %q: %w", repoName, err)
}
if _, err := h.Execute("repo", "update"); err != nil {
logger.Warningf("helm repo update failed: %v", err)
}
cmdArgs := []string{
"upgrade", "--install", "--force", "--create-namespace",
release, repoName + "/" + chartName,
"--version", version,
"--namespace", namespace,
}
// retry: helm fetches the chart tarball from the repo's download URL (e.g. GitHub release
// assets), and transient fetch errors (504s) have failed CI runs
var lastErr error
maxRetries := 5
for i := 0; i < maxRetries; i++ {
err := h.installChart(cmdArgs, values)
if err != nil {
lastErr = fmt.Errorf("helm upgrade --install %q in namespace %q: %w", release, namespace, err)
logger.Error(lastErr)
time.Sleep(10 * time.Second)
continue
}
logger.Infof("helm chart %q installed successfully after %d attempt(s)", release, i+1)
return nil
}
logger.Errorf("failed to install helm chart %s after %d attempts", release, maxRetries)
return lastErr
}
func (h *HelmHelper) UninstallHelmReleaseIfExists(namespace, release string) error {
out, err := h.Execute("uninstall", release, "--namespace", namespace)
if err == nil {
return nil
}
msg := strings.ToLower(out + err.Error())
if strings.Contains(msg, "not found") {
return nil
}
return fmt.Errorf("helm uninstall %q in namespace %q: %w; output=%s", release, namespace, err, out)
}
func (h *HelmHelper) installChart(cmdArgs []string, values map[string]interface{}) error {
if values != nil {
testValuesPath := "values-test.yaml"
if err := createValuesFile(testValuesPath, values); err != nil {
return fmt.Errorf("error creating values file: %v", err)
}
defer func() {
_ = os.Remove(testValuesPath)
}()
cmdArgs = append(cmdArgs, "-f", testValuesPath)
}
result, err := h.Execute(cmdArgs...)
if err != nil {
logger.Errorf("failed to install chart. result=%s, err=%v", result, err)
return err
}
return nil
}
// DeleteLocalRookHelmChart uninstalls a give helm deploy
func (h *HelmHelper) DeleteLocalRookHelmChart(namespace, deployName string) error {
cmdArgs := []string{"delete", "-n", namespace, deployName}
_, err := h.Execute(cmdArgs...)
if err != nil {
logger.Errorf("could not delete helm chart with name %v : %v", deployName, err)
return fmt.Errorf("failed to delete helm chart with name %v : %v", deployName, err)
}
return nil
}
func FindRookRoot() (string, error) {
const folderToFind = "tests"
workingDirectory, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("failed to find current working directory. %v", err)
}
parentPath := workingDirectory
userHome, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("failed to find user home directory. %v", err)
}
for parentPath != userHome {
fmt.Printf("parent path = %s\n", parentPath)
_, err := os.Stat(path.Join(parentPath, folderToFind))
if os.IsNotExist(err) {
parentPath = filepath.Dir(parentPath)
continue
}
return parentPath, nil
}
return "", fmt.Errorf("rook root not found above directory %s", workingDirectory)
}