Files
heat-templates/hot/software-config/elements/heat-config-kubelet/os-refresh-config/configure.d/50-heat-config-kubelet
Steve Baker 841ee38a35 heat-config-kubelet hook
This hook uses the kubelet agent from the kubernetes project
to provision containers. The StructuredConfig resource data
represents a pod of containers to be provisioned.

The files have the following purpose:
- extra-data.d/50-docker-images allows an archive file of docker images to
  be included in the dib image
- install.d/50-heat-config-kubelet installs kubernetes for redhat based distros
  during dib image build, along with the required systemd and config files required
  to enable a working kubelet service on the host
- install.d/hook-kubelet.py polls docker images and containers until the expected
  kubelet-provisioned containers are running (or a timeout occurs)
- os-refresh-config/configure.d/50-heat-config-kubelet runs before 55-heat-config
  (and the kubelet hook it triggers). This orc script writes out all pod definition files
  for the pods that should currently be running. Kubelet is configured to monitor
  the directory containing these files, so the current running containers will
  change when kubelet acts on these config changes

Author: Steve Baker <sbaker@redhat.com>
Co-Authored-By: Rabi Mishra <ramishra@redhat.com>

Change-Id: Iabb844c7d8a6f916093c364ad8caa0dbe50df3dd
2015-04-02 08:41:38 +05:30

73 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python
#
# 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.
import glob
import json
import logging
import os
import subprocess
import sys
import requests
MANIFESTS_DIR = os.environ.get('HEAT_KUBELET_MANIFESTS',
'/var/lib/heat-config/heat-config-kubelet'
'/kubelet-manifests')
CONF_FILE = os.environ.get('HEAT_SHELL_CONFIG',
'/var/run/heat-config/heat-config')
def main(argv=sys.argv):
log = logging.getLogger('heat-config')
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(
logging.Formatter(
'[%(asctime)s] (%(name)s) [%(levelname)s] %(message)s'))
log.addHandler(handler)
log.setLevel('DEBUG')
if not os.path.exists(CONF_FILE):
log.error('No config file %s' % CONF_FILE)
return 1
if not os.path.isdir(MANIFESTS_DIR):
os.makedirs(MANIFESTS_DIR, 0o700)
for f in glob.glob('%s/*.json'):
os.remove(f)
try:
configs = json.load(open(CONF_FILE))
except ValueError:
pass
else:
for c in configs:
try:
write_manifest(c)
except Exception as e:
log.exception(e)
def write_manifest(c):
group = c.get('group')
if group != 'kubelet':
return
fn = os.path.join(MANIFESTS_DIR, '%s.json' % c['id'])
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
json.dump(c['config'], f, indent=2)
if __name__ == '__main__':
sys.exit(main(sys.argv))