Skip to content

Commit 602f35f

Browse files
Merge pull request #1332 from hongkailiu/guard-more
OTA-1546: Skip an accept-risk case on network-restricted environment
2 parents ffe4646 + 257eca1 commit 602f35f

83 files changed

Lines changed: 13905 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ require (
6262
github.com/google/cel-go v0.26.0 // indirect
6363
github.com/google/gnostic-models v0.7.0 // indirect
6464
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
65+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
6566
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6667
github.com/jpillora/backoff v1.0.0 // indirect
6768
github.com/json-iterator/go v1.1.12 // indirect
69+
github.com/moby/spdystream v0.5.0 // indirect
6870
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6971
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
7072
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
7173
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
74+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
7275
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7376
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.86.0 // indirect
7477
github.com/prometheus/procfs v0.15.1 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
22
cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
33
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
44
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
5+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
6+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
57
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
68
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
79
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
@@ -66,6 +68,8 @@ github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgY
6668
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
6769
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6870
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
71+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
72+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
6973
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
7074
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
7175
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
@@ -82,6 +86,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
8286
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
8387
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
8488
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
89+
github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
90+
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
8591
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
8692
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
8793
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -92,6 +98,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
9298
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
9399
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
94100
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
101+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
102+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
95103
github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw=
96104
github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
97105
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250220212757-b9c4d98a0c45 h1:hXpbYtP3iTh8oy/RKwKkcMziwchY3fIk95ciczf7cOA=

test/cvo/accept_risks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
6666
})
6767

6868
g.It("should work with accept risks", g.Label("Serial"), func() {
69+
// This test case relies on a public service util.FauxinnatiAPIURL
70+
o.Expect(util.SkipIfNetworkRestricted(ctx, c, util.FauxinnatiAPIURL)).To(o.BeNil())
71+
6972
cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{})
7073
o.Expect(err).NotTo(o.HaveOccurred())
7174

test/util/util.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package util
22

33
import (
4+
"bytes"
45
"context"
6+
"fmt"
7+
"strings"
58
"time"
69

710
g "github.com/onsi/ginkgo/v2"
@@ -10,13 +13,18 @@ import (
1013
corev1 "k8s.io/api/core/v1"
1114
apierrors "k8s.io/apimachinery/pkg/api/errors"
1215
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
"k8s.io/apimachinery/pkg/labels"
1317
"k8s.io/apimachinery/pkg/util/wait"
1418
"k8s.io/client-go/kubernetes"
19+
"k8s.io/client-go/kubernetes/scheme"
1520
"k8s.io/client-go/rest"
1621
"k8s.io/client-go/tools/clientcmd"
22+
"k8s.io/client-go/tools/remotecommand"
1723

1824
configv1 "github.com/openshift/api/config/v1"
1925
clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned"
26+
27+
"github.com/openshift/cluster-version-operator/pkg/external"
2028
)
2129

2230
// IsHypershift checks if running on a HyperShift hosted cluster
@@ -135,3 +143,72 @@ const (
135143
// fauxinnati mocks Cincinnati Update Graph Server for OpenShift
136144
FauxinnatiAPIURL = "https://fauxinnati-fauxinnati.apps.ota-stage.q2z4.p1.openshiftapps.com/api/upgrades_info/graph"
137145
)
146+
147+
func accessible(ctx context.Context, restConfig *rest.Config, urls ...string) (bool, error) {
148+
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
149+
defer cancel()
150+
kubeClient, err := GetKubeClient(restConfig)
151+
if err != nil {
152+
return false, err
153+
}
154+
155+
pods, err := kubeClient.CoreV1().Pods(external.DefaultCVONamespace).
156+
List(ctx, metav1.ListOptions{LabelSelector: labels.FormatLabels(map[string]string{"k8s-app": "cluster-version-operator"})})
157+
if err != nil || len(pods.Items) == 0 {
158+
return false, fmt.Errorf("could not find CVO pod: %w", err)
159+
}
160+
podName := pods.Items[0].Name
161+
command := []string{"curl", "-sI", "--max-time", "10"}
162+
command = append(command, urls...)
163+
164+
req := kubeClient.CoreV1().RESTClient().Post().
165+
Resource("pods").
166+
Name(podName).
167+
Namespace(external.DefaultCVONamespace).
168+
SubResource("exec").
169+
VersionedParams(&corev1.PodExecOptions{
170+
Command: command,
171+
Stdout: true,
172+
Stderr: true,
173+
}, scheme.ParameterCodec)
174+
exec, err := remotecommand.NewSPDYExecutor(restConfig, "POST", req.URL())
175+
176+
if err != nil {
177+
return false, err
178+
}
179+
stdoutBuf := &bytes.Buffer{}
180+
stderrBuf := &bytes.Buffer{}
181+
182+
err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
183+
Stdout: stdoutBuf,
184+
Stderr: stderrBuf,
185+
})
186+
if err != nil {
187+
if strings.Contains(err.Error(), "command terminated with exit code") {
188+
return false, nil
189+
}
190+
return false, err
191+
}
192+
return true, nil
193+
}
194+
195+
// NetworkRestricted returns true if there is a given URL
196+
// that is not accessible. Otherwise, false.
197+
func NetworkRestricted(ctx context.Context, restConfig *rest.Config, urls ...string) (bool, error) {
198+
ok, err := accessible(ctx, restConfig, urls...)
199+
if err != nil {
200+
return false, err
201+
}
202+
return !ok, nil
203+
}
204+
205+
func SkipIfNetworkRestricted(ctx context.Context, restConfig *rest.Config, urls ...string) error {
206+
ok, err := NetworkRestricted(ctx, restConfig, urls...)
207+
if err != nil {
208+
return err
209+
}
210+
if ok {
211+
g.Skip("This test is skipped because the network is restricted")
212+
}
213+
return nil
214+
}

vendor/github.com/gorilla/websocket/.gitignore

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gorilla/websocket/AUTHORS

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gorilla/websocket/LICENSE

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gorilla/websocket/README.md

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)