Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions maas/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

description: Chart to run MaaS
name: maas
version: 0.1.0
62 changes: 62 additions & 0 deletions maas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# aic-helm/maas

This chart installs a working version of MaaS on kubernetes.

### Quickstart

This chart requires a postgresql instance to be running.

To install postgresql:

```
helm install postgresql --namespace=maas
```

Note: Postgresql may take a short time to reach the 'Running' state. Verify that postgresql is running:

```
# kubectl get pods -n maas
NAME READY STATUS RESTARTS AGE
postgresql-0 1/1 Running 0 1m
```

To deploy your MaaS chart:

```
helm install maas --namespace=maas
```

To verify the helm deployment was successful:
```
# helm ls
NAME REVISION UPDATED STATUS CHART
opining-mule 1 Mon Feb 13 22:20:08 2017 DEPLOYED maas-0.1.0
sweet-manatee 1 Mon Feb 13 21:57:41 2017 DEPLOYED postgresql-0.1.0

```

To check that all resources are working as intended:
```
# kubectl get all --namespace=maas
NAME READY STATUS RESTARTS AGE
po/maas-rack-3238195061-tn5fv 1/1 Running 0 11m
po/maas-region-0 1/1 Running 0 11m
po/postgresql-0 1/1 Running 0 34m

NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/maas-region-ui 10.105.136.244 <none> 80/TCP,8000/TCP 11m
svc/postgresql 10.107.159.38 <none> 5432/TCP 34m

NAME DESIRED CURRENT AGE
statefulsets/maas-region 1 1 11m
statefulsets/postgresql 1 1 34m

NAME DESIRED SUCCESSFUL AGE
jobs/region-import-resources 1 1 11m

NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/maas-rack 1 1 1 1 11m

NAME DESIRED CURRENT READY AGE
rs/maas-rack-3238195061 1 1 1 11m
```
18 changes: 18 additions & 0 deletions maas/requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

dependencies:
- name: helm-toolkit
repository: http://localhost:8879/charts
version: 0.1.0
50 changes: 50 additions & 0 deletions maas/templates/bin/_import-boot-resources.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

function check_for_download {

TIMEOUT={{ .Values.jobs.import_boot_resources.timeout }}
while [[ ${TIMEOUT} -gt 0 ]]; do
if maas {{ .Values.credentials.admin_username }} boot-resources read | grep -q '\[\]';
then
echo 'Did not find boot resources. Will try again'
let TIMEOUT-={{ .Values.jobs.import_boot_resources.retry_timer }}
sleep {{ .Values.jobs.import_boot_resources.retry_timer }}
else
echo 'Boot resources found'
exit 0
fi
done
exit 1
}

maas-region local_config_set \
--database-host "{{ include "helm-toolkit.postgresql_host" . }}" \
--database-name "{{ .Values.database.db_name }}" \
--database-user "{{ .Values.database.db_user }}" \
--database-pass "{{ .Values.database.db_password }}" \
--maas-url "http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}:{{ .Values.network.port.service_gui }}/MAAS"

KEY=$(maas-region apikey --username={{ .Values.credentials.admin_username }})
maas login {{ .Values.credentials.admin_username }} http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS/ $KEY

# make call to import images
maas {{ .Values.credentials.admin_username }} boot-resources import
# see if we can find > 0 images
sleep {{ .Values.jobs.import_boot_resources.retry_timer }}
check_for_download
20 changes: 20 additions & 0 deletions maas/templates/bin/_job-readiness.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

</dev/tcp/{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/{{ .Values.network.port.service_gui }} && \
</dev/tcp/{{ .Values.db_service_name }}.{{ .Release.Namespace }}/{{ .Values.network.port.db_service }} && \
pg_isready -h {{ .Values.db_service_name }}.{{ .Release.Namespace }} && \
maas-region apikey --username={{ .Values.credentials.admin_username }} || exit 1
129 changes: 129 additions & 0 deletions maas/templates/bin/_maas-region-controller.postinst.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/sh

# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

. /usr/share/debconf/confmodule
db_version 2.0

if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then
. /usr/share/dbconfig-common/dpkg/postinst.pgsql
fi

RELEASE=`lsb_release -rs` || RELEASE=""

maas_sync_migrate_db(){
maas-region dbupgrade
}

restart_postgresql(){
invoke-rc.d --force postgresql restart || true
}

configure_maas_default_url() {
local ipaddr="$1"
# The given address is either "[IPv6_IP]" or "IPv4_IP" or "name", such as
# [2001:db8::3:1]:5555 or 127.0.0.1 or maas.example.com.
# The ugly sed splits the given thing as:
# (string of anything but ":", or [ipv6_ip]),
# optionally followed by :port.
local address=$(echo "$ipaddr" |
sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\1/p')
local port=$(echo "$ipaddr" |
sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\2/p')
test -n "$port" || port=":80"
ipaddr="${ipaddr}${port}"
maas-region local_config_set --maas-url "http://${ipaddr}/MAAS"
}

extract_default_maas_url() {
# Extract DEFAULT_MAAS_URL IP/host setting from config file $1.
grep "^DEFAULT_MAAS_URL" "$1" | cut -d"/" -f3
}

configure_migrate_maas_dns() {
# This only runs on upgrade. We only run this if the
# there are forwarders to migrate or no
# named.conf.options.inside.maas are present.
maas-region edit_named_options \
--migrate-conflicting-options --config-path \
/etc/bind/named.conf.options
invoke-rc.d bind9 restart || true
}

if [ "$1" = "configure" ] && [ -z "$2" ]; then
#########################################################
########## Configure DEFAULT_MAAS_URL #################
#########################################################

# Obtain IP address of default route and change DEFAULT_MAAS_URL
# if default-maas-url has not been preseeded. Prefer ipv4 addresses if
# present, and use "localhost" only if there is no default route in either
# address family.
db_get maas/default-maas-url
ipaddr="$RET"
if [ -z "$ipaddr" ]; then
ipaddr="{{ .Values.ui_service_name }}.{{ .Release.Namespace }}"
fi
# Set the IP address of the interface with default route
configure_maas_default_url "$ipaddr"
db_subst maas/installation-note MAAS_URL "$ipaddr"
db_set maas/default-maas-url "$ipaddr"

#########################################################
################ Configure Database ###################
#########################################################

# Create the database
dbc_go maas-region-controller $@
maas-region local_config_set \
--database-host {{ include "helm-toolkit.postgresql_host" . | quote }} \
--database-name {{ .Values.database.db_name | quote }} \
--database-user {{ .Values.database.db_user | quote }} \
--database-pass {{ .Values.database.db_password | quote }}

# Only syncdb if we have selected to install it with dbconfig-common.
db_get maas-region-controller/dbconfig-install
if [ "$RET" = "true" ]; then
maas_sync_migrate_db
configure_migrate_maas_dns
fi

db_get maas/username
username="$RET"
if [ -n "$username" ]; then
db_get maas/password
password="$RET"
if [ -n "$password" ]; then
maas-region createadmin --username "$username" --password "$password" --email "$username@maas"
fi
fi

# Display installation note
db_input low maas/installation-note || true
db_go

fi

systemctl enable maas-regiond >/dev/null || true
systemctl restart maas-regiond >/dev/null || true
invoke-rc.d apache2 restart || true

if [ -f /lib/systemd/system/maas-rackd.service ]; then
systemctl restart maas-rackd >/dev/null || true
fi

db_stop
38 changes: 38 additions & 0 deletions maas/templates/bin/_register-rack-controller.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

# show env
env > /tmp/env

echo "register-rack-controller URL: "{{ .Values.ui_service_name }}.{{ .Release.Namespace }}

# note the secret must be a valid hex value

# register forever
while [ 1 ];
do
if maas-rack register --url=http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS --secret={{ .Values.secret | quote }};
then
echo "Successfully registered with MaaS Region Controller"
break
else
echo "Unable to register with http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS... will try again"
sleep 10
fi;

done;
24 changes: 24 additions & 0 deletions maas/templates/bin/_start.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

echo 'running postinst'

chmod 755 /var/lib/dpkg/info/maas-region-controller.postinst
/bin/sh /var/lib/dpkg/info/maas-region-controller.postinst configure

maas-region createadmin --username={{ .Values.credentials.admin_username }} --password={{ .Values.credentials.admin_password }} --email={{ .Values.credentials.admin_email }} || true
29 changes: 29 additions & 0 deletions maas/templates/configmap-bin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2017 The Openstack-Helm Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
name: maas-bin
data:
start.sh: |
{{ tuple "bin/_start.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}
maas-region-controller.postinst: |
{{ tuple "bin/_maas-region-controller.postinst.tpl" . | include "helm-toolkit.template" | indent 4 }}
import-boot-resources.sh: |
{{ tuple "bin/_import-boot-resources.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}
job-readiness.sh: |
{{ tuple "bin/_job-readiness.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}
register-rack-controller.sh: |
{{ tuple "bin/_register-rack-controller.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}
Loading