Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

[Chart] adding-swift-chart #197

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
B64_DIRS := helm-toolkit/secrets
B64_EXCLUDE := $(wildcard helm-toolkit/secrets/*.b64)

CHARTS := ceph mariadb etcd postgresql rabbitmq memcached keystone glance horizon neutron nova cinder heat maas openstack
CHARTS := ceph mariadb etcd postgresql rabbitmq memcached keystone glance horizon neutron nova cinder heat swift maas openstack
TOOLKIT_TPL := helm-toolkit/templates/_globals.tpl

all: helm-toolkit ceph bootstrap mariadb etcd postgresql rabbitmq memcached keystone glance horizon neutron nova cinder heat maas openstack
all: helm-toolkit ceph bootstrap mariadb etcd postgresql rabbitmq memcached keystone glance horizon neutron nova cinder heat swift maas openstack

helm-toolkit: build-helm-toolkit

Expand Down Expand Up @@ -51,6 +51,8 @@ nova: build-nova

heat: build-heat

swift: build-swift

maas: build-maas

memcached: build-memcached
Expand Down
43 changes: 42 additions & 1 deletion helm-toolkit/templates/_endpoints.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@
{{- end -}}
{{- end -}}

# this function returns the endpoint uri for a service, it takes an tuple
# input in the form: service-type, endpoint-class, port-name. eg:
# { tuple "orchestration" "public" "api" . | include "helm-toolkit.endpoint_type_lookup_addr" }
# will return the appropriate URI. Once merged this should phase out the above.

{{- define "helm-toolkit.endpoint_type_lookup_addr" -}}
{{- $type := index . 0 -}}
{{- $endpoint := index . 1 -}}
{{- $port := index . 2 -}}
{{- $context := index . 3 -}}
{{- $endpointMap := index $context.Values.endpoints $type }}
{{- $fqdn := $context.Release.Namespace -}}
{{- if $context.Values.endpoints.fqdn -}}
{{- $fqdn := $context.Values.endpoints.fqdn -}}
{{- end -}}
{{- with $endpointMap -}}
{{- $endpointScheme := .scheme }}
{{- $endpointHost := index .hosts $endpoint | default .hosts.default}}
{{- $endpointPort := index .port $port }}
{{- $endpointPath := .path | default "" }}
{{- printf "%s://%s.%s:%1.f%s" $endpointScheme $endpointHost $fqdn $endpointPort $endpointPath -}}
{{- end -}}
{{- end -}}

#-------------------------------
# endpoint type lookup
Expand All @@ -145,7 +168,25 @@
{{- $endpointType | quote -}}
{{- end -}}


#-------------------------------
# endpoint name lookup
#-------------------------------

# this function is used in endpoint management templates
# it returns the service type for an openstack service eg:
# { tuple orchestration . | include "ks_endpoint_type" }
# will return "heat"

{{- define "helm-toolkit.endpoint_name_lookup" -}}
{{- $type := index . 0 -}}
{{- $context := index . 1 -}}
{{- $endpointMap := index $context.Values.endpoints $type }}
{{- $endpointName := index $endpointMap "name" }}
{{- $endpointName | quote -}}
{{- end -}}

#-------------------------------
# kolla helpers
#-------------------------------
{{ define "helm-toolkit.keystone_auth" }}{'auth_url':'{{ include "helm-toolkit.endpoint_keystone_internal" . }}', 'username':'{{ .Values.keystone.admin_user }}','password':'{{ .Values.keystone.admin_password }}','project_name':'{{ .Values.keystone.admin_project_name }}','domain_name':'default'}{{end}}
{{ define "helm-toolkit.keystone_auth" }}{'auth_url':'{{ tuple "identity" "internal" "api" . | include "helm-toolkit.endpoint_type_lookup_addr" }}', 'username':'{{ .Values.keystone.admin_user }}','password':'{{ .Values.keystone.admin_password }}','project_name':'{{ .Values.keystone.admin_project_name }}','domain_name':'default'}{{end}}
117 changes: 117 additions & 0 deletions helm-toolkit/templates/scripts/_job-create-db.py.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{{- define "helm-toolkit.job_create_db" }}
#!/usr/bin/env python

# Copyright 2017 Pete Birley
#
# 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.

# Creates db and user for an OpenStack Service:
# Set ROOT_DB_CONNECTION and DB_CONNECTION environment variables to contain
# SQLAlchemy strings for the root connection to the database and the one you
# wish the service to use. Alternatively, you can use an ini formatted config
# at the location specified by OPENSTACK_CONFIG_FILE, and extract the string
# from the key OPENSTACK_CONFIG_DB_KEY, in the section specified by
# OPENSTACK_CONFIG_DB_SECTION.

import os
import sys
import ConfigParser
from sqlalchemy import create_engine

# Get the connection string for the service db root user
if "ROOT_DB_CONNECTION" in os.environ:
db_connection = os.environ['ROOT_DB_CONNECTION']
else:
print 'ROOT_DB_CONNECTION env var missing'
sys.exit(1)

# Get the connection string for the service db
if "OPENSTACK_CONFIG_FILE" in os.environ:
try:
os_conf = os.environ['OPENSTACK_CONFIG_FILE']
if "OPENSTACK_CONFIG_DB_SECTION" in os.environ:
os_conf_section = os.environ['OPENSTACK_CONFIG_DB_SECTION']
else:
print 'Env var OPENSTACK_CONFIG_DB_SECTION not set'
sys.exit(1)
if "OPENSTACK_CONFIG_DB_KEY" in os.environ:
os_conf_key = os.environ['OPENSTACK_CONFIG_DB_KEY']
else:
print 'Env var OPENSTACK_CONFIG_DB_KEY not set'
sys.exit(1)
config = ConfigParser.RawConfigParser()
print("Using {0} as db config source".format(os_conf))
config.read(os_conf)
print("Trying to load db config from {0}:{1}".format(
os_conf_section, os_conf_key))
user_db_conn = config.get(os_conf_section, os_conf_key)
print("Got config from {0}".format(os_conf))
except:
print("Tried to load config from {0} but failed.".format(os_conf))
sys.exit(1)
elif "DB_CONNECTION" in os.environ:
user_db_conn = os.environ['DB_CONNECTION']
print 'Got config from DB_CONNECTION env var'
else:
print 'Could not get db config, either from config file or env var'
sys.exit(1)

# Root DB engine
try:
root_engine = create_engine(db_connection)
connection = root_engine.connect()
connection.close()
except:
print 'Could not connect to database as root user'
sys.exit(1)

# User DB engine
try:
user_engine = create_engine(user_db_conn)
# Get our user data out of the user_engine
database = user_engine.url.database
user = user_engine.url.username
password = user_engine.url.password
print 'Got user db config'
except:
print 'Could not get user database config'
sys.exit(1)

# Create DB
try:
root_engine.execute("CREATE DATABASE IF NOT EXISTS {0}".format(database))
print("Created database {0}".format(database))
except:
print("Could not create database {0}".format(database))
sys.exit(1)

# Create DB User
try:
root_engine.execute(
"GRANT ALL ON `{0}`.* TO \'{1}\'@\'%%\' IDENTIFIED BY \'{2}\'".format(
database, user, password))
print("Created user {0} for {1}".format(user, database))
except:
print("Could not create user {0} for {1}".format(user, database))
sys.exit(1)

# Test connection
try:
connection = user_engine.connect()
connection.close()
print 'Database connection for user ok'
except:
print 'Could not connect to database as user'
sys.exit(1)
{{- end }}

13 changes: 13 additions & 0 deletions helm-toolkit/templates/snippets/_db_secret_root.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- define "helm-toolkit.secret_db_root" }}
{{- $envAll := . -}}
{{- $dbRootConnection := printf "mysql+pymysql://%s:%s@%s:%1.f" $envAll.Values.database.root_user $envAll.Values.database.root_password $envAll.Values.database.address $envAll.Values.database.port }}
apiVersion: v1
kind: Secret
metadata:
name: {{ $envAll.Values.database.secret.root }}
type: Opaque
data:
DB_CONNECTION: |
{{ $dbRootConnection | b64enc | indent 4 }}
{{- end }}

21 changes: 21 additions & 0 deletions swift/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
18 changes: 18 additions & 0 deletions swift/Chart.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.

apiVersion: v1
description: A Helm chart for Swift
name: swift
version: 0.1.0
20 changes: 20 additions & 0 deletions swift/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# OpenStack-Helm - Swift

Swift is a highly available, distributed, eventually consistent object/blob store. Organizations can use Swift to store lots of data efficiently, safely, and cheaply.

## Prequisites:

* helm-toolkit 0.1.0+

## Installing the Chart

`$ helm install --name=swift local/swift --namespace=openstack`

## Uninstalling the Chart

`$ helm delete swift`

## Configuraion

> **Tip**: You can use the default [values.yaml](values.yaml)

18 changes: 18 additions & 0 deletions swift/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
27 changes: 27 additions & 0 deletions swift/templates/configmap-bin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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: swift-bin
data:
db-create.py: |
{{- include "helm-toolkit.job_create_db" . | indent 4 }}
ks-service.sh: |
{{- include "helm-toolkit.keystone_service" . | indent 4 }}
ks-endpoints.sh: |
{{- include "helm-toolkit.keystone_endpoints" . | indent 4 }}
ks-user.sh: |
{{- include "helm-toolkit.keystone_user" . | indent 4 }}
29 changes: 29 additions & 0 deletions swift/templates/configmap-etc.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: swift-etc
data:
swift.conf: |
{{ tuple "etc/_swift.conf.tpl" . | include "template" | indent 4 }}
proxy-server.conf: |
{{ tuple "etc/_proxy-server.conf.tpl" . | include "template" | indent 4 }}
object-server.conf: |
{{ tuple "etc/_object-server.conf.tpl" . | include "template" | indent 4 }}
container-server.conf: |
{{ tuple "etc/_container-server.conf.tpl" . | include "template" | indent 4 }}
account-server.conf: |
{{ tuple "etc/_account-server.conf.tpl" . | include "template" | indent 4 }}
Loading