solr-operator icon indicating copy to clipboard operation
solr-operator copied to clipboard

zk-setup init container uses "[[" which is not available in /bin/sh which is used to run the command in the init-container

Open kunstkomputer opened this issue 3 months ago • 1 comments

After Installing a Solr-Cloud using a self provided security.json and a Kubernetes Secret supplying the login information for k8s-oper and solr users for the basicAuth the zk-setup init-container completes prematurely. The logline printed before the init container exits is sh: 1: [[: not found The zk-setup init container uses plain /bin/sh instead of /bin/bash as its container Entrypoint.

solr-operator chart version: v0.9.1
WARN  - 2025-09-11 12:10:58.779; org.apache.solr.common.cloud.SolrZkClient; Using default ZkCredentialsInjector. ZkCredentialsInjector is not secure, it creates an empty list of credentials which leads to 'OPEN_ACL_UNSAFE' ACLs to Zookeeper nodes
WARN  - 2025-09-11 12:10:58.985; org.apache.solr.common.cloud.SolrZkClient; Using default ZkACLProvider. DefaultZkACLProvider is not secure, it creates 'OPEN_ACL_UNSAFE' ACLs to Zookeeper nodes
configs
overseer
aliases.json
live_nodes
collections
overseer_elect
security.json
solr.xml
node_roles
sh: 1: [[: not found
stream closed EOF for sophora-stable/solr-solrcloud-0 (setup-zk)
  setup-zk:
    Container ID:  containerd://d3b47a032cdeb9e76833ce1bfaa1cfecdab60cd1c2998d32318640227f574aa1
    Image:         solr:9.2.1
    Image ID:      docker.io/library/solr@sha256:c7d2485fb31e5acdda15c4b22fb9765d233875afd1bca51422dfc6ab7049748d
    Port:          <none>
    Host Port:     <none>
    Command:
      sh
      -c
      solr zk ls ${ZK_CHROOT} -z ${ZK_SERVER} || solr zk mkroot ${ZK_CHROOT} -z ${ZK_SERVER};  solr zk cp zk:/security.json /tmp/current_security.json -z $ZK_HOST >/dev/null 2>&1;  GET_CURRENT_SECURITY_JSON_EXIT_CODE=$?; if [ ${GET_CURRENT_SECURITY_JSON_EXIT_CODE} -eq 0 ]; then if [[ ! -s /tmp/current_security.json ]] || grep -q '^{}$' /tmp/current_security.json ; then  echo $SECURITY_JSON > /tmp/security.json; solr zk cp /tmp/security.json zk:/security.json -z $ZK_HOST >/dev/null 2>&1;  echo 'Blank security.json found. Put new security.json in ZK'; fi; elif [ ${GET_CURRENT_SECURITY_JSON_EXIT_CODE} -eq 1 ]; then  echo $SECURITY_JSON > /tmp/security.json; solr zk cp /tmp/security.json zk:/security.json -z $ZK_HOST >/dev/null 2>&1;  echo 'No security.json found. Put new security.json in ZK'; fi
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 11 Sep 2025 14:10:55 +0200
      Finished:     Thu, 11 Sep 2025 14:11:02 +0200

I think the fix is trivial as while constructing the shell command simply another /bin/sh compatible shell command, like test or [ ] can be used instead of the /bin/bash `[[' version. I am happy to provide a PR if the bug itself is acknowledged.

kunstkomputer avatar Sep 11 '25 16:09 kunstkomputer

The Docker image is based on Ubuntu 22.04.5 LTS and uses Dash as default shell.

$ docker run solr ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 23  2022 /bin/sh -> dash

I propose a fix to the script. See PR #800

DanielRaapDev avatar Sep 12 '25 13:09 DanielRaapDev