Skip to content

Commit

Permalink
Add COS module
Browse files Browse the repository at this point in the history
  • Loading branch information
dosaboy committed Dec 12, 2024
1 parent 8bd2196 commit 7da3821
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 0 deletions.
1 change: 1 addition & 0 deletions cos/common
46 changes: 46 additions & 0 deletions cos/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash -x
COS_MODEL=cos
SCRIPT_DIR=$(realpath $(dirname $0))

juju_run_cmd="juju run"
if (( $(juju --version | awk -F. {'print $1'}) > 2 )); then
juju_run_cmd="juju exec"
fi

which kubectl || sudo snap install kubectl --classic
mkdir -p ~/.kube

if $(juju list-models| egrep -q "^${COS_MODEL}\*"); then
echo "WARNING: currently in '$COS_MODEL' context - switch to microk8s model to re-run microk8s config"
else
mk8s_unit=$(juju status| sed -nr 's,(^microk8s/[[:digit:]]+)\*.*,\1,p')
$juju_run_cmd --unit $mk8s_unit microk8s.config > ~/.kube/config
$juju_run_cmd --unit $mk8s_unit -- 'IPADDR=$( ip r get 2.2.2.2| sed -rn "s/.+src ([0-9\.]+) .+/\1/p"); microk8s enable metallb:$IPADDR-$IPADDR'
fi

kubectl get pods -A

if ! $(juju list-clouds| egrep -q "^microk8s-cos"); then
KUBECONFIG=~/.kube/config juju add-k8s microk8s-cos --cluster-name=microk8s-cluster --client --controller stg-reproducer-hopem-project --storage=ceph-xfs
fi
if ! $(juju list-models| egrep -q "^${COS_MODEL}"); then
juju add-model $COS_MODEL microk8s-cos
juju deploy cos-lite --overlay ${SCRIPT_DIR}/overlays/cos/cos-lite-offers.yaml --trust
else
echo "INFO: model '$COS_MODEL' already exists - skipping deploy"
juju switch $COS_MODEL
fi

juju wait-for application grafana

echo "INFO: COS should now be reachable at the following endpoints:"
juju run traefik/0 show-proxied-endpoints --format=yaml| yq '."traefik/0".results."proxied-endpoints"' | jq

GRAFANA_PASSWORD=$(juju run grafana/leader get-admin-password --model cos 2>/dev/null| sed -rn 's/admin-password:\s+(.+)/\1/p')
GRAFANA_USER=$(juju config grafana admin_user)
echo "Grafana login info: ${GRAFANA_USER}/$GRAFANA_PASSWORD"

echo "INFO: run the following to consume COS from your microk8s model:"
for offer in cos.loki cos.grafana cos.prometheus cos.altermanager; do
echo "juju consume $offer"
done
25 changes: 25 additions & 0 deletions cos/cos.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
series: __SERIES__
machines:
'0':
constraints: __MACHINE1_CONSTRAINTS__
series: __SERIES__
'1':
constraints: __MACHINE2_CONSTRAINTS__
series: __SERIES__
'2':
constraints: __MACHINE3_CONSTRAINTS__
series: __SERIES__
applications:
microk8s:
charm: __CHARM_STORE____CHARM_CS_NS____CHARM_CH_PREFIX__microk8s
num_units: 3
expose: true
options:
containerd_http_proxy: __CONTAINERD_PROXY__
containerd_https_proxy: __CONTAINERD_PROXY__
containerd_no_proxy: __CONTAINERD_NO_PROXY__
num_units: 3
to:
- 0
- 1
- 2
1 change: 1 addition & 0 deletions cos/generate-bundle.sh
14 changes: 14 additions & 0 deletions cos/module_defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file must contain defaults for all variables used in bundles/overlays.
# They are used to render to final product in the event they are not provided
# elsewhere. It is inserted into the global context at the start of the
# pipeline.
#
# You can check that none are missing by running lint/check_var_defaults.sh
#

MOD_PARAMS[__MICROK8S_CHANNEL__]="latest/edge"
MOD_PARAMS[__CONTAINERD_PROXY__]=''
MOD_PARAMS[__CONTAINERD_NO_PROXY__]='127.0.0.1,localhost,::1,10.149.0.0/16,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16'
MOD_PARAMS[__MACHINE1_CONSTRAINTS__]='mem=16G'
MOD_PARAMS[__MACHINE2_CONSTRAINTS__]='mem=16G'
MOD_PARAMS[__MACHINE3_CONSTRAINTS__]='mem=16G'
1 change: 1 addition & 0 deletions cos/overlays
21 changes: 21 additions & 0 deletions cos/pipeline/00setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Globals
export MOD_NAME=cos
export MOD_BASE_TEMPLATE=cos.yaml.template
export MOD_SSL_STATE_DIR=${MOD_NAME}
[ -n "${MASTER_OPTS[BUNDLE_NAME]}" ] && \
MOD_SSL_STATE_DIR="${MOD_SSL_STATE_DIR}-${MASTER_OPTS[BUNDLE_NAME]}"

# opts that 02configure does not recognise that get passed to the generator
export -a MOD_PASSTHROUGH_OPTS=()

# Collection of messages to display at the end
export -A MOD_MSGS=()
# Use order 0 to ensure this is first displayed
MOD_MSGS[0_common.0]="run ./configure to initialise your deployment"

# Array list of overlays to use with this deployment.
export -a MOD_OVERLAYS=()

export -A MOD_PARAMS=()
2 changes: 2 additions & 0 deletions cos/pipeline/01import-config-defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Current module imports
. $MOD_DIR/module_defaults
49 changes: 49 additions & 0 deletions cos/pipeline/02configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# Global variables are first defined in 00setup and module
# dependencies are defined in 01import-config-defaults
#
# All overlay/bundle variables (MOD_PARAMS) defaults must go into
# the <module>/module_defaults file.

target=$series
[ -z "$pocket" ] || target=${target}-$pocket
target=${target}:${MOD_PARAMS[__MICROK8S_CHANNEL__]}
MOD_PASSTHROUGH_OPTS+=( --release-name $target )

# Automatically use proxy if in prodstack only
if $(timeout 1s getent hosts squid.internal &> /dev/null) && [ -z "${MOD_PARAMS[__CONTAINERD_PROXY__]}" ]; then
MOD_MSGS[1_proxy.0]='PROXY: squid.internal exists, setting containerd proxy to http://squid.internal:3128'
MOD_PARAMS[__CONTAINERD_PROXY__]=http://squid.internal:3128
fi

if ! has_opt --charmed-ceph-lxd && ! has_opt --microceph; then
MOD_OVERLAYS+=( "cos/charmed-ceph.yaml" )
fi

# Skip processing input if it includes exclusive passthrough options
! has_excl_passthrough_opt && \
while (($# > 0))
do
case "$1" in
--containerd-proxy) #__OPT__type:<str> (default="" unless the hostname squid.internal resolves, then it's http://squid.internal:3128)
MOD_PARAMS[__CONTAINERD_PROXY__]=$2
shift
;;
--containerd-no-proxy) #__OPT__type:<str> (default=127.0.0.1,localhost,::1,10.149.0.0/16,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16)
MOD_PARAMS[__CONTAINERD_NO_PROXY__]=$2
shift
;;
--microceph)
MOD_OVERLAYS+=( "cos/microceph.yaml" )
;;
--charmed-ceph-lxd)
MOD_OVERLAYS+=( "cos/charmed-ceph-lxd.yaml" )
;;
*)
echo "ERROR: invalid input '$1'"
_usage
exit 1
;;
esac
shift
done
5 changes: 5 additions & 0 deletions cos/pipeline/03build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
. $MOD_DIR/common/generate_bundle_base

print_msgs

5 changes: 5 additions & 0 deletions cos/resources/README_resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
If you want to configure charm resources [1] in a bundle, put a directory in
this path with the name of the bundle/overlay they correspond to. Any files
within will then be copied into the generated bundles' path.

[1] https://docs.jujucharms.com/using-resources-developer-guide
42 changes: 42 additions & 0 deletions overlays/cos/charmed-ceph-lxd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
machines:
'0':
constraints: __MACHINE1_CONSTRAINTS__
series: __SERIES__
'1':
constraints: __MACHINE2_CONSTRAINTS__
series: __SERIES__
'2':
constraints: __MACHINE3_CONSTRAINTS__
series: __SERIES__
applications:
ceph-mon:
charm: ceph-mon
channel: quincy/stable
num_units: 3
to:
- 0
- 1
- 2
ceph-osd:
charm: ceph-osd
channel: quincy/stable
num_units: 3
to:
- 0
- 1
- 2
options:
osd-devices: '' # must be empty string when using juju storage
config-flags: '{"osd": {"osd memory target": 1073741824}}' # matching 2G constraint
storage:
osd-devices: cinder,10G,1
ceph-csi:
charm: ceph-csi
channel: 1.28/stable
options:
provisioner-replicas: 1
namespace: kube-system
relations:
- [ ceph-osd:mon, ceph-mon:osd ]
- [ ceph-csi:ceph-client, ceph-mon:client ]
- [ ceph-csi:kubernetes-info, microk8s ]
43 changes: 43 additions & 0 deletions overlays/cos/charmed-ceph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
machines:
'0':
constraints: __MACHINE1_CONSTRAINTS__
series: __SERIES__
'1':
constraints: __MACHINE2_CONSTRAINTS__
series: __SERIES__
'2':
constraints: __MACHINE3_CONSTRAINTS__
series: __SERIES__
applications:
ceph-mon:
charm: ceph-mon
channel: quincy/stable
num_units: 3
to:
- 0
- 1
- 2
ceph-osd:
charm: ceph-osd
channel: quincy/stable
num_units: 3
to:
- 0
- 1
- 2
options:
osd-devices: '' # must be empty string when using juju storage
config-flags: '{"osd": {"osd memory target": 1073741824}}' # matching 2G constraint
storage:
osd-devices: cinder,10G,1
ceph-csi:
charm: ceph-csi
# See https://github.com/charmed-kubernetes/ceph-csi-operator/issues/22
channel: 1.31/stable
options:
provisioner-replicas: 1
namespace: kube-system
relations:
- [ ceph-osd:mon, ceph-mon:osd ]
- [ ceph-csi:ceph-client, ceph-mon:client ]
- [ ceph-csi:kubernetes-info, microk8s ]
21 changes: 21 additions & 0 deletions overlays/cos/cos-lite-offers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
applications:
alertmanager:
offers:
alertmanager:
endpoints:
- karma-dashboard
grafana:
offers:
grafana:
endpoints:
- grafana-dashboard
loki:
offers:
loki:
endpoints:
- logging
prometheus:
offers:
prometheus:
endpoints:
- receive-remote-write
42 changes: 42 additions & 0 deletions overlays/cos/microceph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
machines:
'0':
constraints: __MACHINE1_CONSTRAINTS__
series: __SERIES__
'1':
constraints: __MACHINE2_CONSTRAINTS__
series: __SERIES__
'2':
constraints: __MACHINE3_CONSTRAINTS__
series: __SERIES__
applications:
ceph-mon:
charm: ceph-mon
channel: quincy/stable
num_units: 3
to:
- 0
- 1
- 2
ceph-osd:
charm: ceph-osd
channel: quincy/stable
num_units: 3
to:
- 0
- 1
- 2
options:
osd-devices: '' # must be empty string when using juju storage
config-flags: '{"osd": {"osd memory target": 1073741824}}' # matching 2G constraint
storage:
osd-devices: cinder,10G,1
ceph-csi:
charm: ceph-csi
channel: 1.28/stable
options:
provisioner-replicas: 1
namespace: kube-system
relations:
- [ ceph-osd:mon, ceph-mon:osd ]
- [ ceph-csi:ceph-client, ceph-mon:client ]
- [ ceph-csi:kubernetes-info, microk8s ]

0 comments on commit 7da3821

Please sign in to comment.