Error attaching oci resource to juju charm using containerd


Hello everyone,

I am trying to attach an oci-type resource to a kubernetes charm, and I’m getting this error:

$ juju attach ui-k8s ui-image=lightui --debug
16:04:53 INFO  juju.cmd supercommand.go:57 running juju [2.5.4 gc go1.10.4]
16:04:53 DEBUG juju.cmd supercommand.go:58   args: []string{"/snap/juju/7206/bin/juju", "attach", "ui-k8s", "ui-image=lightui", "--debug"}
16:04:53 INFO  juju.juju api.go:67 connecting to API addresses: []
16:04:53 DEBUG juju.api apiclient.go:888 successfully dialed "wss://"
16:04:53 INFO  juju.api apiclient.go:608 connection established to "wss://"
16:04:54 DEBUG httpbakery client.go:243 client do PUT {
16:05:01 DEBUG httpbakery client.go:245 } -> error <nil>
16:05:01 DEBUG juju.api monitor.go:35 RPC connection died
ERROR failed to upload resource "ui-image": invalid character 'b' looking for beginning of value
16:05:01 DEBUG cmd supercommand.go:496 error stack: 
invalid character 'b' looking for beginning of value
/build/juju/parts/juju/go/src/ failed to upload resource "ui-image"

In order to reproduce this error, I’ve created this script. If it’s executed in a clear VM with ubuntu 18.04LTS it should happen exactly the same error.

# Setup environment
sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
sudo apt install -y snapd
sudo snap install lxd
sudo snap install juju --classic --stable
sudo snap install microk8s --classic --stable
cat <<EOF | lxd init --preseed
config: {}
- config:
    ipv4.address: auto
    ipv6.address: none
  description: ""
  managed: false
  name: lxdbr0
  type: ""
- config:
    size: 30GB
  description: ""
  name: default
  driver: zfs
- config: {}
  description: ""
      name: eth0
      nictype: bridged
      parent: lxdbr0
      type: nic
      path: /
      pool: default
      type: disk
  name: default
cluster: null

lxd waitready

sudo snap alias microk8s.kubectl kubectl
eval $(microk8s.inspect | grep "sudo" | sed -n -e 's/^.*: //p')
microk8s.status --wait-ready
microk8s.enable dashboard storage dns

juju bootstrap lxd juju-controller
microk8s.config | juju add-k8s k8s
juju add-model model-name k8s

# Download charm
git clone 
sudo snap install charm --classic
cd canonical-osm
# Build ui-k8s charm
cd charms/layers/
mkdir ../builds
charm build ui-k8s -o ../

# Deploy charm using bundle
cat << EOF > bundle.yaml
bundle: kubernetes
    charm: '../builds/ui-k8s'
    scale: 1
    series: kubernetes
      ui-image: '../resources/ui-image.yaml'
mkdir ../resources
echo "registrypath: opensourcemano/light-ui:releasefive-daily" > ../resources/ui-image.yaml

juju deploy bundle.yaml

# ctr pull
microk8s.ctr image pull
# ctr export 
microk8s.ctr images export lightui
# juju attach
juju attach ui-k8s ui-image=lightui --debug


I was able to reproduce this. Thank you @davigar15.

@wallyworld by googling the error it seems that when the client tried to PUT the image it received a non-json response. Are there any logs we can take a look at to find out what went wrong?


juju attach is used to attach a storage instance to a unit.

The command you want to use is charm attach.

You can snap install charm. From charm help attach:

The attach command can also be used to attach docker resources
to Kubernetes charms. When a charm has a docker image resource,
it can be attached by naming the image in the local docker instance:

    charm attach ~user/mykubernetes-charm myresource=ubuntu

The image will be uploaded to the Docker registry associated with the
charm store. It's also possible to attach an image from an external
registry directly without uploading it to the charmstore's registry
by using the prefix "external::"; for example:

    charm attach ~user/mykubernetes-charm myresource=external::ubuntu