Skip to content

Commit

Permalink
Merge pull request #28621 from Shilpa-Gokul/4.16-thanos
Browse files Browse the repository at this point in the history
OCPBUGS-29028: Add function back to execute commands via pod
  • Loading branch information
openshift-merge-bot[bot] committed Mar 1, 2024
2 parents 253ff31 + 6e6699a commit e66eced
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/extended/prometheus/prometheus.go
Expand Up @@ -379,7 +379,7 @@ var _ = g.Describe("[sig-instrumentation] Prometheus [apigroup:image.openshift.i
})).NotTo(o.HaveOccurred(), fmt.Sprintf("Did not find tsdb_samples_appended_total, tsdb_head_samples_appended_total, or prometheus_tsdb_head_samples_appended_total"))

g.By("verifying the Thanos querier service requires authentication")
err := helper.ExpectHTTPStatusCode(querySvcURL, "", 401, 403)
err := helper.ExpectURLStatusCodeExecViaPod(ns, execPod.Name, querySvcURL, 401, 403)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("verifying a service account token is able to authenticate")
Expand Down
19 changes: 19 additions & 0 deletions test/extended/util/prometheus/helpers.go
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"

Expand All @@ -27,6 +28,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
watchtools "k8s.io/client-go/tools/watch"
"k8s.io/kubernetes/test/e2e/framework"
e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
)

const (
Expand Down Expand Up @@ -345,6 +347,23 @@ func ExpectHTTPStatusCode(url, bearerToken string, statusCodes ...int) error {
return fmt.Errorf("%s: last response from server was not in %v: %d", url, statusCodes, resp.StatusCode)
}

// ExpectURLStatusCodeExecViaPod attempts connection to url via exec pod and returns an error
// upon failure or if status return code is not equal to any of the statusCodes.
func ExpectURLStatusCodeExecViaPod(ns, execPodName, url string, statusCodes ...int) error {
cmd := fmt.Sprintf("curl -k -s -o /dev/null -w '%%{http_code}' %q", url)
output, err := e2eoutput.RunHostCmd(ns, execPodName, cmd)
if err != nil {
return fmt.Errorf("host command failed: %v\n%s", err, output)
}
for _, statusCode := range statusCodes {
if output == strconv.Itoa(statusCode) {
return nil
}
}

return fmt.Errorf("last response from server was not in %v: %s", statusCodes, output)
}

// ExpectPrometheusEndpoint attempts to connect to the metrics endpoint with
// delayed retries upon failure.
func ExpectPrometheusEndpoint(url string) {
Expand Down

0 comments on commit e66eced

Please sign in to comment.