Repository: kubernetes/kubernetes (language: go)

Issue:
`kubectl wait --for=jsonpath='{.status.readyReplicas}'=1` fails in 1.31.0-rc.1
### What happened?

https://kubernetes.slack.com/archives/C0EG7JC6T/p1723471158762629

In v1.31.0-rc.1 `kubectl wait --for=jsonpath='{.status.readyReplicas}'=1` commands hang, see relevant thread for details.



### What did you expect to happen?

Second command should work, as it does with kubectl v1.30.3

### How can we reproduce it (as minimally and precisely as possible)?

Reproducer against a 1.30.3 server:

```
(
	curl https://dl.k8s.io/v1.31.0-rc.1/kubernetes-client-linux-amd64.tar.gz -L -o v1.31.0-rc.1.tar.gz
	tar xvzf v1.31.0-rc.1.tar.gz -C v1.31.0-rc.1
)


./v1.31.0-rc.1/kubernetes/client/bin/kubectl create deploy nginx --image nginx --replicas 1
./v1.31.0-rc.1/kubernetes/client/bin/kubectl wait deploy nginx --for=condition=available                # works
./v1.31.0-rc.1/kubernetes/client/bin/kubectl wait deploy nginx --for=jsonpath='{.status.readyReplicas}'=1    # does not work
```

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ ./v1.31.0-rc.1/kubernetes/client/bin/kubectl version
Client Version: v1.31.0-rc.1
Kustomize Version: v5.4.2
Server Version: v1.30.3

```

</details>


### Cloud provider

<details>

</details>


### OS version

<details>

```console
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>

</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>



Discussion / hints:
cc @soltysh @liggitt 

looks like a regression introduced in https://github.com/kubernetes/kubernetes/pull/125868/files#r1713843179

/assign @soltysh 
thanks so much for the very detailed and timely report, great to catch this before the .0 release 🎉 

Fix patch:
diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go b/staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go
index efbe2957e97f9..a247ebb0e9a45 100644
--- a/staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go
+++ b/staging/src/k8s.io/kubectl/pkg/cmd/wait/wait.go
@@ -195,8 +195,8 @@ func conditionFuncFor(condition string, errOut io.Writer) (ConditionFunc, error)
 	case lowercaseCond == "create":
 		return IsCreated, nil
 
-	case strings.HasPrefix(lowercaseCond, "condition="):
-		conditionName := lowercaseCond[len("condition="):]
+	case strings.HasPrefix(condition, "condition="):
+		conditionName := strings.TrimPrefix(condition, "condition=")
 		conditionValue := "true"
 		if equalsIndex := strings.Index(conditionName, "="); equalsIndex != -1 {
 			conditionValue = conditionName[equalsIndex+1:]
@@ -209,8 +209,8 @@ func conditionFuncFor(condition string, errOut io.Writer) (ConditionFunc, error)
 			errOut:          errOut,
 		}.IsConditionMet, nil
 
-	case strings.HasPrefix(lowercaseCond, "jsonpath="):
-		jsonPathInput := strings.TrimPrefix(lowercaseCond, "jsonpath=")
+	case strings.HasPrefix(condition, "jsonpath="):
+		jsonPathInput := strings.TrimPrefix(condition, "jsonpath=")
 		jsonPathExp, jsonPathValue, err := processJSONPathInput(jsonPathInput)
 		if err != nil {
 			return nil, err


Test patch:
diff --git a/test/cmd/wait.sh b/test/cmd/wait.sh
index 4c3dd8a2ad7be..2578d4bd6fdfe 100644
--- a/test/cmd/wait.sh
+++ b/test/cmd/wait.sh
@@ -51,6 +51,12 @@ run_wait_tests() {
     # Post-Condition: Wait failed
     kube::test::if_has_string "${output_message}" 'timed out'
 
+    # wait with mixed case jsonpath
+    output_message=$(kubectl wait --for=jsonpath=.status.unavailableReplicas=1 deploy/test-1 2>&1)
+
+    # Post-Condition: Wait failed
+    kube::test::if_has_string "${output_message}" 'test-1 condition met'
+
     # Delete all deployments async to kubectl wait
     ( sleep 2 && kubectl delete deployment --all ) &