Skip to content

Commit 300e606

Browse files
committed
cmd/k8s-operator/generate: skip tests if no network or Helm is down
Updates helm/helm#31434 Change-Id: I5eb20e97ff543f883d5646c9324f50f54180851d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> (cherry picked from commit d5a40c0)
1 parent 1a6c315 commit 300e606

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

cmd/k8s-operator/generate/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func generate(baseDir string) error {
144144
if _, err := file.Write([]byte(helmConditionalEnd)); err != nil {
145145
return fmt.Errorf("error writing helm if-statement end: %w", err)
146146
}
147-
return nil
147+
return file.Close()
148148
}
149149
for _, crd := range []struct {
150150
crdPath, templatePath string

cmd/k8s-operator/generate/main_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,50 @@ package main
77

88
import (
99
"bytes"
10+
"context"
11+
"net"
1012
"os"
1113
"os/exec"
1214
"path/filepath"
1315
"strings"
1416
"testing"
17+
"time"
18+
19+
"tailscale.com/tstest/nettest"
20+
"tailscale.com/util/cibuild"
1521
)
1622

1723
func Test_generate(t *testing.T) {
24+
nettest.SkipIfNoNetwork(t)
25+
26+
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
27+
defer cancel()
28+
if _, err := net.DefaultResolver.LookupIPAddr(ctx, "get.helm.sh"); err != nil {
29+
// https://github.com/helm/helm/issues/31434
30+
t.Skipf("get.helm.sh seems down or unreachable; skipping test")
31+
}
32+
1833
base, err := os.Getwd()
1934
base = filepath.Join(base, "../../../")
2035
if err != nil {
2136
t.Fatalf("error getting current working directory: %v", err)
2237
}
2338
defer cleanup(base)
39+
40+
helmCLIPath := filepath.Join(base, "tool/helm")
41+
if out, err := exec.Command(helmCLIPath, "version").CombinedOutput(); err != nil && cibuild.On() {
42+
// It's not just DNS. Azure is generating bogus certs within GitHub Actions at least for
43+
// helm. So try to run it and see if we can even fetch it.
44+
//
45+
// https://github.com/helm/helm/issues/31434
46+
t.Skipf("error fetching helm; skipping test in CI: %v, %s", err, out)
47+
}
48+
2449
if err := generate(base); err != nil {
2550
t.Fatalf("CRD template generation: %v", err)
2651
}
2752

2853
tempDir := t.TempDir()
29-
helmCLIPath := filepath.Join(base, "tool/helm")
3054
helmChartTemplatesPath := filepath.Join(base, "cmd/k8s-operator/deploy/chart")
3155
helmPackageCmd := exec.Command(helmCLIPath, "package", helmChartTemplatesPath, "--destination", tempDir, "--version", "0.0.1")
3256
helmPackageCmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)