kubeler 0.1.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
kubeler-0.1.0/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011-2024 GitHub Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kubeler-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.2
2
+ Name: kubeler
3
+ Version: 0.1.0
4
+ Summary: A dead simple Kubernetes Resources installer
5
+ Home-page: https://github.com/glendmaatita/kubeler
6
+ Author: Glend Maatita
7
+ Author-email: me@glendmaatita.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.12
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: jinja2>=3.1.5
15
+ Requires-Dist: kubernetes>=32.0.0
16
+ Requires-Dist: pydantic>=2.10.6
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # Kubeler
28
+
29
+ Simple Kubernetes Resources installer
30
+
31
+ Dependencies
32
+ - Python >= 3.12
33
+
34
+ # Installation
35
+
36
+ ```
37
+ pip install kubeler
38
+ ```
39
+
40
+ ## Usage
41
+ ```
42
+ kubeler install --installer=./examples/installer.yaml
43
+ ```
@@ -0,0 +1,17 @@
1
+ # Kubeler
2
+
3
+ Simple Kubernetes Resources installer
4
+
5
+ Dependencies
6
+ - Python >= 3.12
7
+
8
+ # Installation
9
+
10
+ ```
11
+ pip install kubeler
12
+ ```
13
+
14
+ ## Usage
15
+ ```
16
+ kubeler install --installer=./examples/installer.yaml
17
+ ```
@@ -0,0 +1 @@
1
+ # init
@@ -0,0 +1,20 @@
1
+ import argparse
2
+ from scripts.installer import Installer
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser(description="Installer script")
6
+ subparsers = parser.add_subparsers(dest='command', required=True, help='Subcommands')
7
+
8
+ # Create a subparser for the 'install' command
9
+ install_parser = subparsers.add_parser('install', help='Install command')
10
+ install_parser.add_argument('--installer', type=str, default='./installer.yaml', help='Path to the config YAML file')
11
+ install_parser.add_argument('--kube-config', type=str, default='~/kube/config', help='Path to the kube config file')
12
+
13
+ args = parser.parse_args()
14
+
15
+ if args.command == 'install':
16
+ installer = Installer(installer=args.installer, kube_config=args.kube_config)
17
+ installer.install()
18
+
19
+ if __name__ == "__main__":
20
+ main()
@@ -0,0 +1 @@
1
+ # init
@@ -0,0 +1,131 @@
1
+ import yaml, os, sys, subprocess, shutil, jinja2
2
+ from scripts.models.kubeler import Kubeler
3
+
4
+ tmp_dir = "/tmp/kubeler"
5
+
6
+ class Installer:
7
+ def __init__(self, installer, kube_config):
8
+ self.installer = installer
9
+ self.kube_config = kube_config
10
+
11
+ # get the directory path of the installer and kube_config
12
+ self.installer_dir_path = os.path.dirname(installer)
13
+ self.kube_config_path = os.path.dirname(kube_config)
14
+
15
+ # create tmp dir if not exists
16
+ if not os.path.exists(tmp_dir):
17
+ os.makedirs(tmp_dir)
18
+
19
+ def install(self):
20
+ kubeler = self.load_config()
21
+
22
+ # process init
23
+ init_cmd = kubeler.init.cmd
24
+ for command in init_cmd:
25
+ cmd = command.split()
26
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
27
+ for line in process.stdout:
28
+ print(line, end="")
29
+ sys.stdout.flush()
30
+ process.wait()
31
+
32
+ # process steps
33
+ steps = kubeler.group.steps
34
+ for step in steps:
35
+ # extract step information
36
+ step_name = step.name
37
+ dir = os.path.join(self.installer_dir_path, step.dir)
38
+ files = step.files
39
+ vars = step.vars
40
+
41
+ # if files is not defined in installer.yaml, load all files in the directory
42
+ if files == None:
43
+ files = self.load_files_in_dir(dir)
44
+
45
+ for file in files:
46
+ file_path = os.path.join(dir, file)
47
+ config_path = os.path.join(tmp_dir, file)
48
+
49
+ # set execution dir. It will be in tmp folder if vars is defined
50
+ execution_dir = dir
51
+ if vars != None:
52
+ # copy files for execution
53
+ shutil.copy(file_path, config_path)
54
+
55
+ # create dictionary of variables
56
+ vars_dict = {var.name: var.value for var in vars}
57
+ # using jinja, replace variables in file
58
+ with open(config_path, "r") as config_file:
59
+ template_content = config_file.read()
60
+ template = jinja2.Template(template_content)
61
+ rendered_yaml = template.render(vars_dict)
62
+
63
+ with open(config_path, "w") as config_file:
64
+ config_file.write(rendered_yaml)
65
+
66
+ # update dir variable
67
+ execution_dir = tmp_dir
68
+
69
+ # get commands defined in the file
70
+ commands = self.load_file(file_path)
71
+ for command in commands:
72
+ print("Executing command: ", command)
73
+ cmd = command.split()
74
+ process = subprocess.Popen(cmd, cwd=execution_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
75
+ for line in process.stdout:
76
+ print(line, end="")
77
+ sys.stdout.flush()
78
+ process.wait()
79
+
80
+ # if config_path exists, restore the file
81
+ if os.path.exists(config_path):
82
+ os.remove(config_path)
83
+
84
+ # if there some files in the directory, load them
85
+ def load_files_in_dir(self, dir):
86
+ files = []
87
+ for file in os.listdir(dir):
88
+ if os.path.isfile(os.path.join(dir, file)):
89
+ files.append(file)
90
+ return files
91
+
92
+ # load commands on each files
93
+ def load_file(self, file_path):
94
+ commands = []
95
+ with open(file_path, "r") as file:
96
+ for line in file:
97
+ if line.startswith("#cmd:"):
98
+ command = line.split(":", 1)[1].strip()
99
+ commands.append(command)
100
+ return commands
101
+
102
+ # load the configuration file and parse to Kubeler model
103
+ def load_config(self) -> Kubeler:
104
+ data = self.open_config()
105
+ kubeler = Kubeler(**data)
106
+
107
+ # handle reference variables
108
+ for step in kubeler.group.steps:
109
+ if step.vars != None:
110
+ for var in step.vars:
111
+ if var.value.startswith("ref."):
112
+ ref_var = var.value.split("ref.")[1]
113
+ ref_vars = ref_var.split(".")
114
+ step_name = ref_vars[0]
115
+ var_name = ref_vars[2]
116
+ for step in kubeler.group.steps:
117
+ if step.vars != None:
118
+ if (step.name == step_name):
119
+ for ref in step.vars:
120
+ if ref.name == var_name:
121
+ var.value = ref.value
122
+ return kubeler
123
+
124
+ # open the configuration file
125
+ def open_config(self):
126
+ with open(self.installer, 'r') as stream:
127
+ try:
128
+ data = yaml.safe_load(stream)
129
+ return data
130
+ except yaml.YAMLError as exc:
131
+ raise ValueError("Failed to load configuration")
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.2
2
+ Name: kubeler
3
+ Version: 0.1.0
4
+ Summary: A dead simple Kubernetes Resources installer
5
+ Home-page: https://github.com/glendmaatita/kubeler
6
+ Author: Glend Maatita
7
+ Author-email: me@glendmaatita.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.12
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: jinja2>=3.1.5
15
+ Requires-Dist: kubernetes>=32.0.0
16
+ Requires-Dist: pydantic>=2.10.6
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # Kubeler
28
+
29
+ Simple Kubernetes Resources installer
30
+
31
+ Dependencies
32
+ - Python >= 3.12
33
+
34
+ # Installation
35
+
36
+ ```
37
+ pip install kubeler
38
+ ```
39
+
40
+ ## Usage
41
+ ```
42
+ kubeler install --installer=./examples/installer.yaml
43
+ ```
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ kubeler/__init__.py
5
+ kubeler/main.py
6
+ kubeler.egg-info/PKG-INFO
7
+ kubeler.egg-info/SOURCES.txt
8
+ kubeler.egg-info/dependency_links.txt
9
+ kubeler.egg-info/entry_points.txt
10
+ kubeler.egg-info/requires.txt
11
+ kubeler.egg-info/top_level.txt
12
+ kubeler/scripts/__init__.py
13
+ kubeler/scripts/installer.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kubeler = kubeler.main:main
@@ -0,0 +1,3 @@
1
+ jinja2>=3.1.5
2
+ kubernetes>=32.0.0
3
+ pydantic>=2.10.6
@@ -0,0 +1 @@
1
+ kubeler
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
kubeler-0.1.0/setup.py ADDED
@@ -0,0 +1,30 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='kubeler',
5
+ version='0.1.0',
6
+ packages=find_packages(),
7
+ include_package_data=True,
8
+ install_requires=[
9
+ "jinja2>=3.1.5",
10
+ "kubernetes>=32.0.0",
11
+ "pydantic>=2.10.6",
12
+ ],
13
+ entry_points={
14
+ 'console_scripts': [
15
+ 'kubeler=kubeler.main:main',
16
+ ],
17
+ },
18
+ author='Glend Maatita',
19
+ author_email='me@glendmaatita.com',
20
+ description='A dead simple Kubernetes Resources installer',
21
+ long_description=open('README.md').read(),
22
+ long_description_content_type='text/markdown',
23
+ url='https://github.com/glendmaatita/kubeler',
24
+ classifiers=[
25
+ 'Programming Language :: Python :: 3',
26
+ 'License :: OSI Approved :: MIT License',
27
+ 'Operating System :: OS Independent',
28
+ ],
29
+ python_requires='>=3.12',
30
+ )