Skip to content

Commit c5ecd6b

Browse files
authored
Merge pull request #4 from v1k0d3n/move-init-addons
initial move to addons: maas and postgresql
2 parents 3ce8b33 + e4816bf commit c5ecd6b

26 files changed

Lines changed: 1051 additions & 0 deletions

maas/Chart.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2017 The Openstack-Helm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
description: Chart to run MaaS
16+
name: maas
17+
version: 0.1.0

maas/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# aic-helm/maas
2+
3+
This chart installs a working version of MaaS on kubernetes.
4+
5+
### Quickstart
6+
7+
This chart requires a postgresql instance to be running.
8+
9+
To install postgresql:
10+
11+
```
12+
helm install postgresql --namespace=maas
13+
```
14+
15+
Note: Postgresql may take a short time to reach the 'Running' state. Verify that postgresql is running:
16+
17+
```
18+
# kubectl get pods -n maas
19+
NAME READY STATUS RESTARTS AGE
20+
postgresql-0 1/1 Running 0 1m
21+
```
22+
23+
To deploy your MaaS chart:
24+
25+
```
26+
helm install maas --namespace=maas
27+
```
28+
29+
To verify the helm deployment was successful:
30+
```
31+
# helm ls
32+
NAME REVISION UPDATED STATUS CHART
33+
opining-mule 1 Mon Feb 13 22:20:08 2017 DEPLOYED maas-0.1.0
34+
sweet-manatee 1 Mon Feb 13 21:57:41 2017 DEPLOYED postgresql-0.1.0
35+
36+
```
37+
38+
To check that all resources are working as intended:
39+
```
40+
# kubectl get all --namespace=maas
41+
NAME READY STATUS RESTARTS AGE
42+
po/maas-rack-3238195061-tn5fv 1/1 Running 0 11m
43+
po/maas-region-0 1/1 Running 0 11m
44+
po/postgresql-0 1/1 Running 0 34m
45+
46+
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
47+
svc/maas-region-ui 10.105.136.244 <none> 80/TCP,8000/TCP 11m
48+
svc/postgresql 10.107.159.38 <none> 5432/TCP 34m
49+
50+
NAME DESIRED CURRENT AGE
51+
statefulsets/maas-region 1 1 11m
52+
statefulsets/postgresql 1 1 34m
53+
54+
NAME DESIRED SUCCESSFUL AGE
55+
jobs/region-import-resources 1 1 11m
56+
57+
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
58+
deploy/maas-rack 1 1 1 1 11m
59+
60+
NAME DESIRED CURRENT READY AGE
61+
rs/maas-rack-3238195061 1 1 1 11m
62+
```

maas/requirements.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2017 The Openstack-Helm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
dependencies:
16+
- name: helm-toolkit
17+
repository: http://localhost:8879/charts
18+
version: 0.1.0
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
# Copyright 2017 The Openstack-Helm Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -ex
18+
19+
function check_for_download {
20+
21+
TIMEOUT={{ .Values.jobs.import_boot_resources.timeout }}
22+
while [[ ${TIMEOUT} -gt 0 ]]; do
23+
if maas {{ .Values.credentials.admin_username }} boot-resources read | grep -q '\[\]';
24+
then
25+
echo 'Did not find boot resources. Will try again'
26+
let TIMEOUT-={{ .Values.jobs.import_boot_resources.retry_timer }}
27+
sleep {{ .Values.jobs.import_boot_resources.retry_timer }}
28+
else
29+
echo 'Boot resources found'
30+
exit 0
31+
fi
32+
done
33+
exit 1
34+
}
35+
36+
maas-region local_config_set \
37+
--database-host "{{ include "helm-toolkit.postgresql_host" . }}" \
38+
--database-name "{{ .Values.database.db_name }}" \
39+
--database-user "{{ .Values.database.db_user }}" \
40+
--database-pass "{{ .Values.database.db_password }}" \
41+
--maas-url "http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}:{{ .Values.network.port.service_gui }}/MAAS"
42+
43+
KEY=$(maas-region apikey --username={{ .Values.credentials.admin_username }})
44+
maas login {{ .Values.credentials.admin_username }} http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS/ $KEY
45+
46+
# make call to import images
47+
maas {{ .Values.credentials.admin_username }} boot-resources import
48+
# see if we can find > 0 images
49+
sleep {{ .Values.jobs.import_boot_resources.retry_timer }}
50+
check_for_download
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 The Openstack-Helm Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
</dev/tcp/{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/{{ .Values.network.port.service_gui }} && \
18+
</dev/tcp/{{ .Values.db_service_name }}.{{ .Release.Namespace }}/{{ .Values.network.port.db_service }} && \
19+
pg_isready -h {{ .Values.db_service_name }}.{{ .Release.Namespace }} && \
20+
maas-region apikey --username={{ .Values.credentials.admin_username }} || exit 1
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/sh
2+
3+
# Copyright 2017 The Openstack-Helm Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -ex
18+
19+
. /usr/share/debconf/confmodule
20+
db_version 2.0
21+
22+
if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then
23+
. /usr/share/dbconfig-common/dpkg/postinst.pgsql
24+
fi
25+
26+
RELEASE=`lsb_release -rs` || RELEASE=""
27+
28+
maas_sync_migrate_db(){
29+
maas-region dbupgrade
30+
}
31+
32+
restart_postgresql(){
33+
invoke-rc.d --force postgresql restart || true
34+
}
35+
36+
configure_maas_default_url() {
37+
local ipaddr="$1"
38+
# The given address is either "[IPv6_IP]" or "IPv4_IP" or "name", such as
39+
# [2001:db8::3:1]:5555 or 127.0.0.1 or maas.example.com.
40+
# The ugly sed splits the given thing as:
41+
# (string of anything but ":", or [ipv6_ip]),
42+
# optionally followed by :port.
43+
local address=$(echo "$ipaddr" |
44+
sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\1/p')
45+
local port=$(echo "$ipaddr" |
46+
sed -rn 's/^([^:]*|\[[0-9a-fA-F:]*\])(|:[0-9]*)?$/\2/p')
47+
test -n "$port" || port=":80"
48+
ipaddr="${ipaddr}${port}"
49+
maas-region local_config_set --maas-url "http://${ipaddr}/MAAS"
50+
}
51+
52+
extract_default_maas_url() {
53+
# Extract DEFAULT_MAAS_URL IP/host setting from config file $1.
54+
grep "^DEFAULT_MAAS_URL" "$1" | cut -d"/" -f3
55+
}
56+
57+
configure_migrate_maas_dns() {
58+
# This only runs on upgrade. We only run this if the
59+
# there are forwarders to migrate or no
60+
# named.conf.options.inside.maas are present.
61+
maas-region edit_named_options \
62+
--migrate-conflicting-options --config-path \
63+
/etc/bind/named.conf.options
64+
invoke-rc.d bind9 restart || true
65+
}
66+
67+
if [ "$1" = "configure" ] && [ -z "$2" ]; then
68+
#########################################################
69+
########## Configure DEFAULT_MAAS_URL #################
70+
#########################################################
71+
72+
# Obtain IP address of default route and change DEFAULT_MAAS_URL
73+
# if default-maas-url has not been preseeded. Prefer ipv4 addresses if
74+
# present, and use "localhost" only if there is no default route in either
75+
# address family.
76+
db_get maas/default-maas-url
77+
ipaddr="$RET"
78+
if [ -z "$ipaddr" ]; then
79+
ipaddr="{{ .Values.ui_service_name }}.{{ .Release.Namespace }}"
80+
fi
81+
# Set the IP address of the interface with default route
82+
configure_maas_default_url "$ipaddr"
83+
db_subst maas/installation-note MAAS_URL "$ipaddr"
84+
db_set maas/default-maas-url "$ipaddr"
85+
86+
#########################################################
87+
################ Configure Database ###################
88+
#########################################################
89+
90+
# Create the database
91+
dbc_go maas-region-controller $@
92+
maas-region local_config_set \
93+
--database-host {{ include "helm-toolkit.postgresql_host" . | quote }} \
94+
--database-name {{ .Values.database.db_name | quote }} \
95+
--database-user {{ .Values.database.db_user | quote }} \
96+
--database-pass {{ .Values.database.db_password | quote }}
97+
98+
# Only syncdb if we have selected to install it with dbconfig-common.
99+
db_get maas-region-controller/dbconfig-install
100+
if [ "$RET" = "true" ]; then
101+
maas_sync_migrate_db
102+
configure_migrate_maas_dns
103+
fi
104+
105+
db_get maas/username
106+
username="$RET"
107+
if [ -n "$username" ]; then
108+
db_get maas/password
109+
password="$RET"
110+
if [ -n "$password" ]; then
111+
maas-region createadmin --username "$username" --password "$password" --email "$username@maas"
112+
fi
113+
fi
114+
115+
# Display installation note
116+
db_input low maas/installation-note || true
117+
db_go
118+
119+
fi
120+
121+
systemctl enable maas-regiond >/dev/null || true
122+
systemctl restart maas-regiond >/dev/null || true
123+
invoke-rc.d apache2 restart || true
124+
125+
if [ -f /lib/systemd/system/maas-rackd.service ]; then
126+
systemctl restart maas-rackd >/dev/null || true
127+
fi
128+
129+
db_stop
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 The Openstack-Helm Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -ex
18+
19+
# show env
20+
env > /tmp/env
21+
22+
echo "register-rack-controller URL: "{{ .Values.ui_service_name }}.{{ .Release.Namespace }}
23+
24+
# note the secret must be a valid hex value
25+
26+
# register forever
27+
while [ 1 ];
28+
do
29+
if maas-rack register --url=http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS --secret={{ .Values.secret | quote }};
30+
then
31+
echo "Successfully registered with MaaS Region Controller"
32+
break
33+
else
34+
echo "Unable to register with http://{{ .Values.ui_service_name }}.{{ .Release.Namespace }}/MAAS... will try again"
35+
sleep 10
36+
fi;
37+
38+
done;

maas/templates/bin/_start.sh.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 The Openstack-Helm Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -ex
18+
19+
echo 'running postinst'
20+
21+
chmod 755 /var/lib/dpkg/info/maas-region-controller.postinst
22+
/bin/sh /var/lib/dpkg/info/maas-region-controller.postinst configure
23+
24+
maas-region createadmin --username={{ .Values.credentials.admin_username }} --password={{ .Values.credentials.admin_password }} --email={{ .Values.credentials.admin_email }} || true

maas/templates/configmap-bin.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2017 The Openstack-Helm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: maas-bin
19+
data:
20+
start.sh: |
21+
{{ tuple "bin/_start.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}
22+
maas-region-controller.postinst: |
23+
{{ tuple "bin/_maas-region-controller.postinst.tpl" . | include "helm-toolkit.template" | indent 4 }}
24+
import-boot-resources.sh: |
25+
{{ tuple "bin/_import-boot-resources.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}
26+
job-readiness.sh: |
27+
{{ tuple "bin/_job-readiness.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}
28+
register-rack-controller.sh: |
29+
{{ tuple "bin/_register-rack-controller.sh.tpl" . | include "helm-toolkit.template" | indent 4 }}

0 commit comments

Comments
 (0)