Skip to content

Commit

Permalink
microk8s/kubernetes: Configure containerd proxy
Browse files Browse the repository at this point in the history
Configure the containerd proxy server, as it's not possible to pull from
most image repositories without it in se-cloud.

Defaults to the required settings for the se-cloud environment. Can be
overridden with --containerd-proxy and --containerd-no-proxy.

For those using stsstack-bundles outside of the se-cloud environment,
use --containerd-use-proxy false to skip it. This is required as passing
a blank ("") argument to --containerd-proxy is not parsed correctly.
  • Loading branch information
lathiat committed Aug 15, 2024
1 parent 3357a98 commit e2dee17
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
3 changes: 2 additions & 1 deletion common/render.d/all
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ render_mod_params ()
if ((${#MOD_PARAMS[@]})); then
for p in ${!MOD_PARAMS[@]}; do
echo -n "-e 's,$p,${MOD_PARAMS[$p]},g' " >> $config_renderer
# Escape any comma characters in the value, otherwise it breaks
echo -n "-e 's,$p,${MOD_PARAMS[$p]//,/\\,},g' " >> $config_renderer
echo "${p}: \"${MOD_PARAMS[$p]}\"" >> $INTERNAL_BUNDLE_CONFIG
done
fi
Expand Down
3 changes: 2 additions & 1 deletion kubernetes/module_defaults
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ MOD_PARAMS[__NUM_K8S_WORKER_UNITS__]=2
MOD_PARAMS[__NUM_K8S_LB_UNITS__]=1
MOD_PARAMS[__ETCD_SNAP_CHANNEL__]='latest/stable'
MOD_PARAMS[__CONTAINER_RUNTIME__]='containerd'

MOD_PARAMS[__CONTAINERD_PROXY__]='http://squid.internal:3128'
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'
16 changes: 16 additions & 0 deletions kubernetes/pipeline/02configure
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ do
conflicts_with $1 --docker
MOD_OVERLAYS+=( "kubernetes/k8s-containerd.yaml" )
;;
--containerd-use-proxy) ##__OPT__type:<bool> (default=true) Set false not to use the default containerd proxy (passing a blank string to --containerd-proxy won't work)
if [[ $2 != "true" ]]; then
MOD_PARAMS[__CONTAINERD_PROXY__]=""
MOD_PARAMS[__CONTAINERD_NO_PROXY__]=""
fi
shift
;;
--containerd-proxy) #__OPT__type:<str> (default=http://squid.internal:3128)
echo "XXX X: ${MOD_PARAMS[__CONTAINERD_PROXY__]} Y: $2"
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
;;
--calico)
conflicts_with $1 --canal
MOD_OVERLAYS+=( "kubernetes/k8s-cni-calico.yaml" )
Expand Down
4 changes: 4 additions & 0 deletions microk8s/microk8s.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ applications:
num_units: __NUM_MICROK8S_UNITS__
constraints: mem=8G
expose: true
options:
containerd_http_proxy: __CONTAINERD_PROXY__
containerd_https_proxy: __CONTAINERD_PROXY__
containerd_no_proxy: __CONTAINERD_NO_PROXY__
2 changes: 2 additions & 0 deletions microk8s/module_defaults
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

MOD_PARAMS[__MICROK8S_CHANNEL__]="latest/edge"
MOD_PARAMS[__NUM_MICROK8S_UNITS__]=1
MOD_PARAMS[__CONTAINERD_PROXY__]='http://squid.internal:3128'
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'
34 changes: 34 additions & 0 deletions microk8s/pipeline/02configure
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,37 @@ target=$series
[ -z "$pocket" ] || target=${target}-$pocket
target=${target}:${MOD_PARAMS[__MICROK8S_CHANNEL__]}
MOD_PASSTHROUGH_OPTS+=( --release-name $target )

# Skip processing input if it includes exclusive passthrough options
! has_excl_passthrough_opt && \
while (($# > 0))
do
case "$1" in
--containerd)
conflicts_with $1 --docker
MOD_OVERLAYS+=( "kubernetes/k8s-containerd.yaml" )
;;
--containerd-use-proxy) ##__OPT__type:<bool> (default=true) Set false not to use the default containerd proxy (passing a blank string to --containerd-proxy won't work)
if [[ $2 != "true" ]]; then
MOD_PARAMS[__CONTAINERD_PROXY__]=""
MOD_PARAMS[__CONTAINERD_NO_PROXY__]=""
fi
shift
;;
--containerd-proxy) #__OPT__type:<str> (default=http://squid.internal:3128)
echo "XXX X: ${MOD_PARAMS[__CONTAINERD_PROXY__]} Y: $2"
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
;;
*)
echo "ERROR: invalid input '$1'"
_usage
exit 1
;;
esac
shift
done
4 changes: 4 additions & 0 deletions overlays/kubernetes/k8s-containerd.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
applications:
containerd:
charm: __CHARM_STORE____CHARM_CS_NS____CHARM_CH_PREFIX__containerd
options:
http_proxy: __CONTAINERD_PROXY__
https_proxy: __CONTAINERD_PROXY__
no_proxy: __CONTAINERD_NO_PROXY__
relations:
- [ 'containerd:containerd', 'kubernetes-worker:container-runtime' ]
- [ 'containerd:containerd', 'kubernetes-control-plane:container-runtime' ]

0 comments on commit e2dee17

Please sign in to comment.