# Replicatedctl throws "Array Index Out of Bounds Error"

**URL:** <https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435>\
**Category:** Packaging an application\
**Created:** [July 22, 2020, 12:52am UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435 "2020-07-22T00:52:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MANI\_M](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/mani_m/32/136_2.png) [@MANI\_M](https://community.replicated.com/u/MANI_M)\
**Post date:** [July 22, 2020, 12:52am UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/1 "2020-07-22T00:52:42Z")

</div>

While trying to update to new release via dashboard Even though the previous version was updated successfully Dashboard shows error and stalls subsequent update. When tried to stop and start app `replicatedctl` throws **array index out of bounds** error.

Error Trace:

```
error: error executing jsonpath "{.items[0].metadata.name}": Error executing template: array index out of bounds: index 0, length 0. Printing more information for debugging the template:
template was:
	{.items[0].metadata.name}
object given to jsonpath engine was:
	map[string]interface {}{"apiVersion":"v1", "items":[]interface {}{}, "kind":"List", "metadata":map[string]interface {}{"resourceVersion":"", "selfLink":""}}

error: expected 'exec (POD | TYPE/NAME) COMMAND [ARG1] [ARG2] ... [ARGN]'.
POD or TYPE/NAME and COMMAND are required arguments for the exec command
See 'kubectl exec -h' for help and examples

```

 ![replicated update error](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/c3e2ef8389a569bae09bfc33aa2e78eb6e1cbf64.png)

---

<div class="post-metadata">

**Author:** ![dmitriy](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/dmitriy/32/16_2.png) [@dmitriy](https://community.replicated.com/u/dmitriy)\
**Post date:** [July 22, 2020, 1:07am UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/2 "2020-07-22T01:07:51Z")

</div>

Can you try running `kubectl get pods`

---

<div class="post-metadata">

**Author:** ![MANI\_M](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/mani_m/32/136_2.png) [@MANI\_M](https://community.replicated.com/u/MANI_M)\
**Post date:** [July 22, 2020, 3:27pm UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/3 "2020-07-22T15:27:42Z")

</div>

Yeah everything seems to be working fine.

 ![kubectl data](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/7f9b8ba44d93c91b8193d0f404afb37e2b6f52c8.png)

---

<div class="post-metadata">

**Author:** ![dmitriy](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/dmitriy/32/16_2.png) [@dmitriy](https://community.replicated.com/u/dmitriy)\
**Post date:** [July 22, 2020, 4:23pm UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/4 "2020-07-22T16:23:07Z")

</div>

Mani, there should a a label on the replicated pod `tier: master`. You can see the failing command that looks for it in the `/usr/local/bin/replicatedctl` scrip. Can you check what labels the pod has:

```bash
kubectl get pod replicated-<generated stuff> -o yaml | grep -w -5 labels

```

Can you also run the following command?

```bash
kubectl get pods -l tier=master

```

---

<div class="post-metadata">

**Author:** ![MANI\_M](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/mani_m/32/136_2.png) [@MANI\_M](https://community.replicated.com/u/MANI_M)\
**Post date:** [July 23, 2020, 2:05am UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/5 "2020-07-23T02:05:48Z")

</div>

I think I found the reason for this issue.  
This arises when I change my default namespace in context. This eventually means `/usr/local/bin/replicatedctl` should use `-n default` in the `kubectl` commands. Screenshot attached.  
Should I raise an issue in any GitHub repo?

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/1cebd31727bd0b619ef7333814fdfea9418e17a7.png)

---

<div class="post-metadata">

**Author:** ![MANI\_M](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/mani_m/32/136_2.png) [@MANI\_M](https://community.replicated.com/u/MANI_M)\
**Post date:** [July 23, 2020, 2:16am UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/6 "2020-07-23T02:16:21Z")

</div>

Works fine after updating namespace in `/usr/local/bin/replicatedctl` as follows

```auto
 sh -c "kubectl -n default exec -c replicated $flags \
          $(kubectl get pods -n default -o=jsonpath="{.items[0].metadata.name}" -l tier=master) -- \
          replicatedctl$push $(printf "%s" "$opts")"

```

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/replicated/original/1X/a06c58826da5e6301704844b773a1c0518fb047f.png)

---

<div class="post-metadata">

**Author:** ![ethanm](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/ethanm/32/11_2.png) [@ethanm](https://community.replicated.com/u/ethanm)\
**Post date:** [July 23, 2020, 2:57am UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/8 "2020-07-23T02:57:48Z")

</div>

we will create an internal issue to track this

---

<div class="post-metadata">

**Author:** ![MANI\_M](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/mani_m/32/136_2.png) [@MANI\_M](https://community.replicated.com/u/MANI_M)\
**Post date:** [July 23, 2020, 4:56am UTC](https://community.replicated.com/t/replicatedctl-throws-array-index-out-of-bounds-error/435/9 "2020-07-23T04:56:40Z")

</div>

That would be great. Thanks.
