Skip to content

Commit 0ca720f

Browse files
committed
Handle anonymous http requests in curl HTTP client
1 parent 8f0d96d commit 0ca720f

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

pkg/http/curl/curl.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func (c *Client) executeCurlWithAuth(httpURL, headers, args string) (*http.Respo
120120
return nil, err
121121
}
122122

123+
// Handle anonymous endpoints such as /health/status that will not return a 401 response
124+
if rsp.StatusCode >= 200 && rsp.StatusCode < 300 {
125+
return processResponse(rsp)
126+
}
127+
123128
if rsp.StatusCode != http.StatusUnauthorized {
124129
return rsp, fmt.Errorf("expected 401 DIGEST response before content. Received '%s'", rsp.Status)
125130
}
@@ -172,9 +177,13 @@ func handleContent(reader *bufio.Reader) (*http.Response, error) {
172177
}
173178
}
174179

180+
return processResponse(rsp)
181+
}
182+
183+
func processResponse(rsp *http.Response) (*http.Response, error) {
175184
// Save response body
176185
b := new(bytes.Buffer)
177-
if _, err = io.Copy(b, rsp.Body); err != nil {
186+
if _, err := io.Copy(b, rsp.Body); err != nil {
178187
return nil, err
179188
}
180189
if err := rsp.Body.Close(); err != nil {

pkg/reconcile/pipeline/infinispan/handler/manage/upgrades.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
consts "github.com/infinispan/infinispan-operator/controllers/constants"
1010
ispnApi "github.com/infinispan/infinispan-operator/pkg/infinispan/client/api"
1111
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
12-
kube "github.com/infinispan/infinispan-operator/pkg/kubernetes"
1312
pipeline "github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan"
1413
"github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan/handler/provision"
1514
routev1 "github.com/openshift/api/route/v1"
@@ -131,7 +130,8 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
131130
// Initiate the GracefulShutdown if it's not already in progress
132131
if i.Spec.Replicas == 0 {
133132
logger.Info(".Spec.Replicas==0")
134-
if *statefulSet.Spec.Replicas != 0 {
133+
replicas := *statefulSet.Spec.Replicas
134+
if replicas != 0 {
135135
logger.Info("StatefulSet.Spec.Replicas!=0")
136136
// Only send a GracefulShutdown request to the server if it hasn't succeeded already
137137
if !i.IsConditionTrue(ispnv1.ConditionStopping) {
@@ -153,12 +153,6 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
153153
var podMetaMap = make(map[string]*PodMeta, len(podList.Items))
154154
var shutdownAlreadyInitiated bool
155155
for _, pod := range podList.Items {
156-
// We should only proceed with a GracefulShutdown if all pods are marked as Ready
157-
if !kube.IsPodReady(pod) {
158-
ctx.Requeue(fmt.Errorf("postponing GracefulShutdown as pod '%s' is not ready", pod.Name))
159-
return
160-
}
161-
162156
podMeta := &PodMeta{}
163157
podMetaMap[pod.Name] = podMeta
164158
podMeta.client, err = ctx.InfinispanClientUnknownVersion(pod.Name)
@@ -187,7 +181,7 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
187181
return
188182
}
189183

190-
if info.ClusterSize != i.Spec.Replicas {
184+
if info.ClusterSize != replicas {
191185
err = fmt.Errorf(
192186
"unable to proceed with GracefulShutdown as pod '%s' has '%d' cluster members, expected '%d'. Members: '%s'",
193187
pod.Name,
@@ -353,10 +347,14 @@ func EnableRebalanceAfterScaleUp(i *ispnv1.Infinispan, ctx pipeline.Context) {
353347
return
354348
}
355349

356-
if members, err := ispnClient.Container().Members(); err != nil {
357-
ctx.Requeue(fmt.Errorf("unable to retrieve cluster members on scale up: %w", err))
350+
// TODO why is this failing in TestOperandUpgrade for 14.0.x servers?
351+
/*
352+
2025-05-16T17:11:58.093+0100 ERROR Reconciler error {"controller": "infinispan", "controllerGroup": "infinispan.org", "controllerKind": "Infinispan", "infinispan": {"name":"test-operand-upgrade","namespace":"namespace-for-testing"}, "namespace": "namespace-for-testing", "name": "test-operand-upgrade", "reconcileID": "eda96c7e-fd83-43cc-b903-4a623e4e2785", "error": "unable to retrieve cluster information on scale up: unexpected error getting cache manager info: stderr: , err: the server does not allow this method on the requested resource"}
353+
*/
354+
if info, err := ispnClient.Container().Info(); err != nil {
355+
ctx.Requeue(fmt.Errorf("unable to retrieve cluster information on scale up: %w", err))
358356
return
359-
} else if len(members) != int(i.Spec.Replicas) {
357+
} else if info.ClusterSize != i.Spec.Replicas {
360358
ctx.Log().Info("waiting for cluster to form", "replicas", i.Spec.Replicas)
361359
ctx.RequeueAfter(consts.DefaultWaitClusterPodsNotReady, nil)
362360
return

0 commit comments

Comments
 (0)