Error attaching oci resource to juju charm using containerd


#1

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: [10.47.6.37:17070]
16:04:53 DEBUG juju.api apiclient.go:888 successfully dialed "wss://10.47.6.37:17070/model/8354809b-ba02-49f6-823f-a91d28e82022/api"
16:04:53 INFO  juju.api apiclient.go:608 connection established to "wss://10.47.6.37:17070/model/8354809b-ba02-49f6-823f-a91d28e82022/api"
16:04:54 DEBUG httpbakery client.go:243 client do PUT https://10.47.6.37:17070/model/8354809b-ba02-49f6-823f-a91d28e82022/applications/ui-k8s/resources/ui-image {
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/github.com/juju/juju/resource/api/client/client.go:121: 
/build/juju/parts/juju/go/src/github.com/juju/juju/cmd/juju/resource/upload.go:134: 
/build/juju/parts/juju/go/src/github.com/juju/juju/cmd/juju/resource/upload.go:120: 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: {}
networks:
- config:
    ipv4.address: auto
    ipv6.address: none
  description: ""
  managed: false
  name: lxdbr0
  type: ""
storage_pools:
- config:
    size: 30GB
  description: ""
  name: default
  driver: zfs
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      nictype: bridged
      parent: lxdbr0
      type: nic
    root:
      path: /
      pool: default
      type: disk
  name: default
cluster: null
EOF

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 https://git.launchpad.net/canonical-osm 
sudo snap install charm --classic
cd canonical-osm
# Build ui-k8s charm
cd charms/layers/
export CHARM_LAYERS_DIR=.
export CHARM_INTERFACES_DIR=.
mkdir ../builds
charm build ui-k8s -o ../

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

juju deploy bundle.yaml

# ctr pull
microk8s.ctr image pull docker.io/opensourcemano/light-ui:releasefive-daily
# ctr export 
microk8s.ctr images export lightui docker.io/opensourcemano/light-ui:releasefive-daily
# juju attach
juju attach ui-k8s ui-image=lightui --debug

#2

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?


#3

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