Giter Club home page Giter Club logo

juju-dashboard-charm's Introduction

Juju Dashboard Charm

This repository contains charms that deploy the dashboard for Juju and JAAS into Machine and Kubernetes environments.

Charm for Juju Dashboard Charm for Juju Dashboard k8s

Building and Testing the Machine Charm

Building the machine charm is fairly straightforward. You need a machine with Juju 3.0+ installed. The rest of the steps, in brief, are:

# From the root directory of this repo

# Build the charm
cd ./machine-charm
charmcraft pack

# Bootstrap a test controller. Make a make a model, and deploy an application, so that the dashboard has things to show.
juju bootstrap localhost localhost-test
juju add-model test
juju switch test
juju deploy ubuntu

# Switch to the controller model and setup the dashboard
juju switch controller
# If apt fails to install packages when deploying the dashboard you may need to run the following:
# sudo iptables -P FORWARD ACCEPT
juju deploy ./juju-dashboard*.charm dashboard
juju relate controller dashboard
juju dashboard

Once you login following the instructions in the output of juju dashboard you should be able to see the controller model, as well as the test model and test application that you deployed.

Update the dashboard to latest version

This script pulls that latest Github release of the dashboard and extracts it to the appropriate folder in machine-charm:

./scripts/update-machine-charm-dashboard.sh

Building and Testing the k8s charm

This guide covers every step necessary to build and test a k8s charm, from updating the facades in js-libjuju, to rebuilding the dashboard source, to building the charm. You can skip some steps if you don't need to update every part of the toolchain.

Install Juju 3.0

Bulid from source, or snap install --channel=3.0/beta juju

Install Docker Engine

Follow the guide on the docker website to install the latest version of the Docker engine.

Bootstrap microk8s

Follow the guide here

In brief:

snap install microk8s --classic

sudo usermod -a -G microk8s $USER
sudo chown -f -R $USER ~/.kube
su - $USER

microk8s status --wait-ready
microk8s.enable hostpath-storage dns

microk8s config | juju add-k8s --client micro
juju bootstrap micro

juju-dashboard

Using the latest release

There is no need to git clone the repository, in the section "Building the Kubernetes Charm" we will set the <image-id> to canonicalwebteam/juju-dashboard:latest

Building from source

Source

  1. Checkout [email protected]:canonical/juju-dashboard.git
  2. Build the container with DOCKER_BUILDKIT=1 docker build -t juju-dashboard .
  3. Take note of the image id. You can get it with docker image inspect juju-dashboard | grep "Id"
  4. Add the docker image that you just build to microk8s' build in docker repo, as it cannot talk to the docker registry on the host machine: docker image save juju-dashboard | microk8s ctr image import -

Building the Kubernetes Charm

You're finally ready to build the charm! Change to the root directory of this repo, and run:

# Build the charm
cd ./k8s-charm
charmcraft pack

# Switch to the controller model and deploy the dashboard
juju switch controller
# image id must include: "sha256:..."
# using latest OCI release
juju deploy --resource dashboard-image=canonicalwebteam/juju-dashboard:latest ./juju-dashboard*.charm dashboard
# alternatively, using a custom OCI image
# juju deploy --resource dashboard-image=<image id> ./juju-dashboard*.charm dashboard
juju relate controller dashboard
juju dashboard

Login to the dashboard, per the instructions from the juju dashboard command.

Tips and Tricks for Testing

Acccess the Dashboard Without a Proxy

Sometimes, it may be useful to access the dashboard directly, rather than through the ssh tunnel. (E.g., you are trying to determine which part of the pipeline has broken, or access a test server remotely.)

This is made difficult in development environments, where the controller will typically be using self signed certs. Modern browsers will simply refuse to connect to the controller API. Here's a workaround:

In Firefox, Accept the Controller's Self Signed Cert

You must tell your browser to trust the controller's cert in order to get a working dashboard. This requires Firefox, or another browser that allows you to override the security warning. Here's how to do so:

  1. From the CLI, execute juju switch controller && juju status
  2. Note the ip address for the controller, and for the dashboard.
  3. Open Firefox, and visit https://:17070
  4. Click to the advanced part of the security prompt, and accept the risk.
  5. Firefox will display a "bad request" page. This is okay. You have successfully accepted the ssl cert!

Visit the dashboard

  1. From the CLI, execute juju dashboard, and make note of the username and password. You don't need to leave the command running, as you are accessing the dashboard directly, rather than using the proxy server.
  2. In Firefox, visit https://.
  3. Login with username and password you obtained in step 1.

Releasing

Machine charm

charmcraft login
cd ./machine-charm
charmcraft pack
charmcraft upload juju-dashboard*.charm
charmcraft release juju-dashboard --channel=... --revision=...

K8s charm

Update the Docker image

git clone [email protected]:canonical/juju-dashboard.git
cd juju-dashboard
DOCKER_BUILDKIT=1 docker build -t juju-dashboard .

Get the the docker image ID with docker image inspect juju-dashboard | grep "Id"

charmcraft login
charmcraft upload-resource juju-dashboard-k8s dashboard-image --image=[image-id]

Update the charm

charmcraft login
cd ./k8s-charm
charmcraft pack
charmcraft upload juju-dashboard-k8s*.charm
charmcraft release juju-dashboard-k8s --channel=... --revision=[output-from-upload] --resource=dashboard-image:[resource-revision-number]

juju-dashboard-charm's People

Contributors

alesstimec avatar barrettj12 avatar goulinkh avatar hatched avatar huwshimi avatar jpmartinspt avatar lukewh avatar pengale avatar wallyworld avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

juju-dashboard-charm's Issues

Duplicate copies of the same library

We have two versions of the juju_dashboard charm library:
https://github.com/canonical/juju-dashboard-charm/blob/main/k8s-charm/lib/charms/juju_dashboard/v0/juju_dashboard.py
https://github.com/canonical/juju-dashboard-charm/blob/main/machine-charm/lib/charms/juju_dashboard/v0/juju_dashboard.py

Both have the same LIBID, LIBAPI, and LIBPATCH, but there are differences between them. This doesn't seem like a good idea.

In fact, I don't really like the way this repo is structured at all. It's two copies of nearly the same code - and skew will arise over time as we forget to patch both of them. I'm not sure there's a way around this at the moment, though.

ERROR Charm feature requirements cannot be met

root@hazem-pfe:~# juju status
Model Controller Cloud/Region Version SLA Timestamp
controller localhost-localhost localhost/localhost 3.1.5 unsupported 14:09:06Z

App Version Status Scale Charm Channel Rev Exposed Message
controller active 1 juju-controller 3.1/stable 14 no

Unit Workload Agent Machine Public address Ports Message
controller/0* active idle 0 10.217.74.97

Machine State Address Inst id Base AZ Message
0 started 10.217.74.97 juju-4553c3-0 [email protected] Running
root@hazem-pfe:~# juju deploy juju-dashboard-k8s dashboard

Located charm "juju-dashboard-k8s" in charm-hub, revision 8
Deploying "dashboard" from charm-hub charm "juju-dashboard-k8s", revision 8 in channel stable on [email protected]/stable
ERROR Charm feature requirements cannot be met:

  • charm requires feature "k8s-api" but model does not support it

Feature descriptions:

  • "k8s-api": the Kubernetes API lets charms query and manipulate the state of API objects in a Kubernetes cluster

For additional

"controller-relation-changed" hook fails on microk8s

juju bootstrap microk8s c
juju switch controller
juju deploy juju-dashboard
juju relate juju-dashboard controller

Debug logs:

unit-dashboard-0: 17:28:54 WARNING unit.dashboard/0.controller-relation-changed ERROR public address not found
unit-dashboard-0: 17:28:54 ERROR unit.dashboard/0.juju-log controller:0: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-dashboard-0/charm/./src/charm.py", line 127, in <module>
    main(JujuDashboardKubernetesCharm)
  File "/var/lib/juju/agents/unit-dashboard-0/charm/venv/ops/main.py", line 438, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-dashboard-0/charm/venv/ops/main.py", line 150, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-dashboard-0/charm/venv/ops/framework.py", line 355, in emit
    framework._emit(event)  # noqa
  File "/var/lib/juju/agents/unit-dashboard-0/charm/venv/ops/framework.py", line 856, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-dashboard-0/charm/venv/ops/framework.py", line 931, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-dashboard-0/charm/./src/charm.py", line 55, in _on_controller_relation_changed
    requires = JujuDashReq(self, event.relation, event.app)
  File "/var/lib/juju/agents/unit-dashboard-0/charm/lib/charms/juju_dashboard/v0/juju_dashboard.py", line 58, in __init__
    ip = check_output(["unit-get", "public-address"]).decode().strip()
  File "/usr/lib/python3.10/subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['unit-get', 'public-address']' returned non-zero exit status 1.

I suspect the problem was my commit here - this was the correct fix for the machine charm, but I probably shouldn't have changed it for k8s.

Wrong IP address used

Changes made in #16 have been packaged as a beta juju-dashboard charm.

The charm sets the IP address at which the dashboard is reachable into the relation data for the dashboard endpoint. On AWS, the cloud local address is sent. For now, we need to avoid network-get and just use unit-get-public-address until the networking stuff is sorted on the juju side.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.