-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #90: Initial work for kapitan init
- Loading branch information
Showing
11 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
recursive-include kapitan/reclass/reclass/ *.py | ||
include kapitan/lib/*.libjsonnet | ||
include kapitan/inputs/templates/* | ||
include examples/kubernetes/lib/*.libjsonnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2019 The Kapitan 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. | ||
|
||
"initialiser module" | ||
|
||
import logging | ||
import os | ||
import sys | ||
import shutil | ||
from distutils.dir_util import copy_tree | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def initialise_skeleton(directory): | ||
""" Initialises a directory with a recommended skeleton structure | ||
Args: | ||
directory (string): path which to initialise, directory is assumed to exist | ||
""" | ||
|
||
templates_directory = os.path.join(os.path.dirname( | ||
__file__), 'inputs', 'templates') | ||
|
||
copy_tree(templates_directory, directory) | ||
|
||
# create lib/kube.libjsonnet | ||
kube_jsonnet_lib_path = os.path.join(os.path.dirname( | ||
__file__), '..', 'examples', 'kubernetes', 'lib', 'kube.libjsonnet') | ||
shutil.copy2(kube_jsonnet_lib_path, os.path.join(directory, 'lib')) | ||
|
||
logger.info("Populated {} with:".format(directory)) | ||
for dirName, subdirList, fileList in os.walk(directory): | ||
logger.info('{}'.format(dirName)) | ||
for fname in fileList: | ||
logger.info('\t {}'.format(fname)) | ||
# Remove the first entry in the list of sub-directories | ||
# if there are any sub-directories present | ||
if len(subdirList) > 0: | ||
del subdirList[0] |
7 changes: 7 additions & 0 deletions
7
kapitan/inputs/templates/components/my_component/my_component.jsonnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
local kube = import "lib/kube.libjsonnet"; | ||
local kap = import "lib/kapitan.libjsonnet"; | ||
local inventory = kap.inventory(); | ||
|
||
{ | ||
example: inventory.parameters.your_component.some_parameter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
parameters: | ||
kapitan: | ||
vars: | ||
target: ${target_name} |
29 changes: 29 additions & 0 deletions
29
kapitan/inputs/templates/inventory/classes/my_component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
parameters: | ||
your_component: | ||
some_parameter: true | ||
|
||
kapitan: | ||
|
||
compile: | ||
- output_path: jsonnet_output | ||
input_type: jsonnet | ||
output_type: yaml | ||
input_paths: | ||
- components/my_component/my_component.jsonnet | ||
|
||
- output_path: scripts | ||
input_type: jinja2 | ||
input_paths: | ||
- templates/scripts | ||
|
||
- output_path: . | ||
output_type: yaml | ||
input_type: jinja2 | ||
input_paths: | ||
- templates/docs | ||
|
||
# - output_path: manifests | ||
# input_type: kadet | ||
# output_type: yaml | ||
# input_paths: | ||
# - components/nginx/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
classes: | ||
- common | ||
- my_component | ||
|
||
parameters: | ||
target_name: my_target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# My Readme | ||
|
||
Target: {{ target }} | ||
|
||
# INVENTORY | ||
|
||
``` | ||
{{inventory.classes | yaml }} | ||
``` | ||
|
||
|
||
``` | ||
{{inventory.parameters | yaml }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash -eu | ||
|
||
{% set i = inventory.parameters %} | ||
DIR=$(dirname ${BASH_SOURCE[0]}) | ||
|
||
echo "Running for target {{ i.target_name }}" | ||
echo ${DIR} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2019 The Kapitan 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. | ||
|
||
|
||
"init tests" | ||
|
||
import logging | ||
import unittest | ||
import tempfile | ||
import os | ||
|
||
from kapitan.initialiser import initialise_skeleton | ||
|
||
logging.basicConfig(level=logging.CRITICAL, format="%(message)s") | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class InitTest(unittest.TestCase): | ||
def test_init(self): | ||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
initialise_skeleton(directory=tmp_dir) | ||
|
||
template_dir = os.path.join( | ||
os.getcwd(), 'kapitan', 'inputs', 'templates') | ||
|
||
diff_files = [] | ||
|
||
for root, dirs, files in os.walk(tmp_dir): | ||
diff_files += files | ||
|
||
for root, dirs, files in os.walk(template_dir): | ||
for f in files: | ||
if f in diff_files: | ||
diff_files.remove(f) | ||
|
||
self.assertEqual(len(diff_files), 1) |