Skip to content

Commit

Permalink
Add neutron chart
Browse files Browse the repository at this point in the history
Support for linuxbridge and openvswitch network plug-ins
  • Loading branch information
caotingv committed Jul 30, 2022
1 parent 9433261 commit 80b8fc4
Show file tree
Hide file tree
Showing 47 changed files with 1,701 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/install-openstack-neutron.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Install neutron chart

on:
pull_request:
paths:
- 'charts/neutron/**'

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Fetch history
run: git fetch --prune --unshallow

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.1

- name: Create kind cluster
uses: helm/kind-action@v1.2.0

- name: create virt interface
run: tests/scripts/github-action-helper.sh create_virt_interface_test

- name: Create k8s namespace
run:
kubectl create namespace test-neutron

- name: Install password chart
run:
helm install openstack-password charts/password --namespace test-neutron

- name: Install openstack-dep chart
run: |
helm dependency build charts/openstack-dep
helm install openstack-dependency charts/openstack-dep --namespace test-neutron --wait --timeout 600s
- name: Install keystone chart
run: |
helm dependency build charts/keystone
helm install openstack-keystone charts/keystone --namespace test-neutron --wait --timeout 600s
- name: Run chart-testing (install)
run: ct install --namespace test-neutron --target-branch main --charts charts/neutron --debug --helm-extra-args "--timeout 600s"

- name: setup tmate session for debugging when event is PR
if: failure() && github.event_name == 'pull_request'
uses: mxschmitt/action-tmate@v3
timeout-minutes: 60

23 changes: 23 additions & 0 deletions charts/neutron/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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: v2
description: Openstack neutron service
name: neutron
version: 1.0.0
home: https://github.com/kungze/kolla-helm
maintainers:
- name: Kungze
dependencies:
- name: common
repository: https://kungze.github.io/kolla-helm
version: 1.x.x
75 changes: 75 additions & 0 deletions charts/neutron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

# neutron

The chart used to deploy openstack neutron project.

## TL;DR

```shell
$ helm repo add kolla-helm https://kungze.github.io/kolla-helm
$ helm install openstack-password kolla-helm/password
$ helm install openstack-dependency kolla-helm/openstack-dep
$ helm install openstack-keystone kolla-helm/keystone
$ helm install openstack-neutron kolla-helm/neutron --set networkPlugins.external_interface=eth1,networkPlugins.ovs.tunnel_interface=eth2
```

## Parameters

### Cluster Paramters

| Name | Form title | Description | Value |
| ----------------------- | --------------------- | -------------------------------------------- | --------------- |
| `cluster_domain_suffix` | Cluster Domain Suffix | The doamin suffix of the current k8s cluster | `cluster.local` |


### Dependency Parameters

| Name | Form title | Description | Value |
| --------------------- | --------------------- | --------------------------------------- | ---------------------- |
| `openstackDepRelease` | Openstack-dep Release | The release name of openstack-dep chart | `openstack-dependency` |
| `passwordRelease` | Password Release | The release name of password chart | `openstack-password` |
| `keystoneRelease` | keystone Release | The release name of keystone chart | `openstack-keystone` |


### Image Parameters

| Name | Form title | Description | Value |
| ---------------- | ----------------- | ----------------------------------------------- | ----------------------- |
| `imageRegistry` | Image Registry | The registry address of openstack kolla image | `registry.aliyuncs.com` |
| `imageNamespace` | Image Namespace | The registry namespace of openstack kolla image | `kolla-helm` |
| `openstackTag` | Openstack version | The openstack version | `yoga` |
| `pullPolicy` | Pull Policy | The image pull policy | `IfNotPresent` |


### Deployment Parameters

| Name | Form title | Description | Value |
| ---------------------- | ----------------------- | ------------------------------------------------------------------------ | -------- |
| `replicaCount` | | Number of neutron-server replicas to deploy | `1` |
| `serviceAccountName` | | ServiceAccount name | `neutron` |
| `enableLivenessProbe` | Enable Liveness Probe | Whether or not enable liveness probe | `true` |
| `enableReadinessProbe` | Enable Readliness Probe | Whether or not enable readiness probe | `true` |


### neutron Config parameters

| Name | Form title | Description | Value |
| ------------------------------------- | --------------------------- | --------------------------------------------------- | ----------|
| `db_database` | Neutron Database | The neutron database name | `neutron` |
| `db_username` | Neutron Database User | The neutron database user name | `neutron` |
| `enabled_notification` | Enable Notification | Whether or not enable notification | `false` |
| `tenant_network_types` | Tenant Network Types | The tenant network types | `vlan` |
| `network_vlan_ranges` | Network Vlan Ranges |Multiple ranges can be defined like so: 1100:1110 | `1001:1100`|
| `neutron_server.service_plugins` | Network Service Plugins | | `router` |
| `neutron_openvswitch_agent.enabled` | Enable Openvswitch | Whether or not enable openvswitch network plug-in | `true` |
| `neutron_openvswitch_agent.tunnel_interface` | Tunnel Interface Name | The tunnel interface name | `eth0` |
| `neutron_linuxbridge_agent.enabled` | Enable Linuxbridge | Whether or not enable linuxbridge network plug-in | `false` |
| `external_interface` | External Interface Name | The extertnal interface name | `eth1` |

### Ingress Parameters

| Name | Form title | Description | Value |
| ---------------------- | ------------- | --------------------------------------------------------------------------------------- | ----------------- |
| `ingress.enabled` | Ingress | Whether or not create ingress for neutron service | `true` |
| `ingress.ingressClass` | Ingress Class | Ingress Class Name | `openstack-nginx` |
| `ingress.path` | Path Prefix | Ingress will match the path prefix, and forward the matched request to neutron service | `network` |
23 changes: 23 additions & 0 deletions charts/neutron/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{/*
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.
*/}}


CHART NAME: {{ .Chart.Name }}
CHART VERSION: {{ .Chart.Version }}

** Please be patient while the chart is being deployed **

Verify:
source openstackrc
openstack network agent list
80 changes: 80 additions & 0 deletions charts/neutron/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Return the proper neutron server image name
*/}}
{{- define "neutron.server.image" -}}
{{ $repository := "ubuntu-source-neutron-server" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron dhcp image name
*/}}
{{- define "neutron.dhcp.image" -}}
{{ $repository := "ubuntu-source-neutron-dhcp-agent" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron linuxbridge image name
*/}}
{{- define "neutron.linuxbridge.image" -}}
{{ $repository := "ubuntu-source-neutron-linuxbridge-agent" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron openvswitch agent init image name
*/}}
{{- define "neutron.openvswitch-agent-init.image" -}}
{{ $repository := "ubuntu-source-kolla-toolbox" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron openvswitch agent image name
*/}}
{{- define "neutron.openvswitch-agent.image" -}}
{{ $repository := "ubuntu-source-neutron-openvswitch-agent" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron openvswitch db image name
*/}}
{{- define "neutron.openvswitch-db.image" -}}
{{ $repository := "ubuntu-source-openvswitch-db-server" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron openvswitch vswitchd image name
*/}}
{{- define "neutron.openvswitch-vswitchd.image" -}}
{{ $repository := "ubuntu-source-openvswitch-vswitchd" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron l3 agent image name
*/}}
{{- define "neutron.l3-agent.image" -}}
{{ $repository := "ubuntu-source-neutron-l3-agent" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the proper neutron metadata agent image name
*/}}
{{- define "neutron.metadata-agent.image" -}}
{{ $repository := "ubuntu-source-neutron-metadata-agent" }}
{{- include "common.images.image" (dict "registry" .Values.imageRegistry "namespace" .Values.imageNamespace "repository" $repository "tag" .Values.openstackTag) }}
{{- end -}}

{{/*
Return the neutron.cluster.endpoints
*/}}
{{- define "neutron.cluster.endpoint" -}}
{{ printf "http://%s.%s.svc.%s:9696" "neutron-api" .Release.Namespace .Values.cluster_domain_suffix }}
{{- end }}
90 changes: 90 additions & 0 deletions charts/neutron/templates/bin/_neutron-configmap-render.py.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import logging
import requests
import os
import sys
import tempfile
import netifaces as ni

KUBE_HOST = None
KUBE_CERT = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
KUBE_TOKEN = None
NAMESPACE = os.environ['KUBERNETES_NAMESPACE']
TUNNEL_INTERFACE_NAME = os.getenv('TUNNEL_INTERFACE_NAME', None)
CONF_FILE_NAME = os.getenv('CONF_FILE_NAME', None)
CONFIG_MAP_NAME = os.getenv('CONFIG_MAP_NAME', None)
LOG_DATEFMT = "%Y-%m-%d %H:%M:%S"
LOG_FORMAT = "%(asctime)s.%(msecs)03d - %(levelname)s - %(message)s"
logging.basicConfig(format=LOG_FORMAT, datefmt=LOG_DATEFMT)
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.INFO)


def get_tunnel_interface_address(if_name):
return ni.ifaddresses(if_name)[ni.AF_INET][0]['addr']


def read_kube_config():
global KUBE_HOST, KUBE_TOKEN
KUBE_HOST = "https://%s:%s" % ('kubernetes.default',
os.environ['KUBERNETES_SERVICE_PORT'])
with open('/var/run/secrets/kubernetes.io/serviceaccount/token', 'r') as f:
KUBE_TOKEN = f.read()


def get_configmap_definition(name):
url = '%s/api/v1/namespaces/%s/configmaps/%s' % (KUBE_HOST,
NAMESPACE,
name)
resp = requests.get(url,
headers={'Authorization': 'Bearer %s' % KUBE_TOKEN},
verify=KUBE_CERT)
if resp.status_code != 200:
LOG.error('Cannot get configmap %s.', name)
LOG.error(resp.text)
return None
LOG.info('Request configmaps url %s.', url)
return resp.json()


def update_configmap(name, configmap):
url = '%s/api/v1/namespaces/%s/configmaps/%s' % (KUBE_HOST, NAMESPACE, name)
resp = requests.put(url,
json=configmap,
headers={'Authorization': 'Bearer %s' % KUBE_TOKEN},
verify=KUBE_CERT)
if resp.status_code != 200:
LOG.error('Cannot update configmap %s.', name)
LOG.error(resp.text)
return False
return True

def update_connection_fields(content):
tmp = tempfile.NamedTemporaryFile(prefix='tmp', suffix='.ini', dir='/tmp')
LOG.info('Start update configmap file data %s.', CONF_FILE_NAME)
with open(tmp.name, 'w') as f:
f.seek(0, 0)
for line in content.split("\n"):
if "tunnel_interface_address_placeholder" in line:
tunnel_interface_address = get_tunnel_interface_address(TUNNEL_INTERFACE_NAME)
line = line.replace("tunnel_interface_address_placeholder", tunnel_interface_address )
f.write(line + "\n")
f.truncate()
with open(tmp.name, 'r') as f:
info = f.read()
return info


def main():
read_kube_config()
updated_keys = ""
configmap = get_configmap_definition(CONFIG_MAP_NAME)
conf = configmap['data'][CONF_FILE_NAME]
print(conf)
updated_keys = update_connection_fields(conf)

configmap['data'][CONF_FILE_NAME] = updated_keys
if not update_configmap(CONFIG_MAP_NAME, configmap):
sys.exit(1)

if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions charts/neutron/templates/conf/_neutron_db_sync.json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"command": "/tmp/db-sync.sh",
"config_files": [
{
"source": "/var/lib/kolla/config_files/neutron.conf",
"dest": "/etc/neutron/neutron.conf",
"owner": "neutron",
"perm": "0600"
}
],
"permissions": [
{
"path": "/var/log/kolla",
"owner": "neutron:kolla"
},
{
"path": "/var/log/kolla/neutron/neutron.log",
"owner": "neutron:neutron"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[DEFAULT]
{{- if .Values.neutron_linuxbridge_agent.enabled }}
interface_driver = linuxbridge
{{- else if .Values.neutron_openvswitch_agent.enabled }}
interface_driver = openvswitch
{{- end }}
dnsmasq_config_file = /etc/neutron/dnsmasq.conf
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true
force_metadata = true
dnsmasq_dns_servers = 1.1.1.1,8.8.8.8,8.8.4.4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
log-facility=/var/log/kolla/neutron/dnsmasq.log
Loading

0 comments on commit 80b8fc4

Please sign in to comment.