Deprecate all references and usage of Armada

Armada is no longer used in the current version of STX,
therefore it is being deprecated from this tool.

Test Plan:
PASS - Verify that fluxcd package continues to function.
PASS - Pytest continues to show all passing results.

Story: 2010937
Task: 49192

Change-Id: I3db42359a6b062042057caa564744845bdde59c0
Signed-off-by: Reed, Joshua <Joshua.Reed@windriver.com>
This commit is contained in:
Reed, Joshua 2023-12-04 15:39:41 -07:00
parent abf0044b41
commit 70841340c6
9 changed files with 10 additions and 363 deletions

4
.vscode/launch.json vendored
View File

@ -15,13 +15,12 @@
"args": [
"--input=${workspaceFolder}/example/app-test-adminer-1.yaml",
"--output=${workspaceFolder}/example/output",
"--type=fluxcd",
"--overwrite"
]
},
{
// First pip install this repo
// stx-app-generator --input=./example/app-test-adminer-1.yaml --output=./example/output --type=fluxcd --overwrite
// stx-app-generator --input=./example/app-test-adminer-1.yaml --output=./example/output --overwrite
"name": "Python: Installed Generator",
"type": "python",
"request": "launch",
@ -32,7 +31,6 @@
"args": [
"--input=${workspaceFolder}/example/app-test-adminer-1.yaml",
"--output=${workspaceFolder}/example/output",
"--type=fluxcd",
"--overwrite"
]
}

View File

@ -21,16 +21,11 @@ Below you will find the steps to deploy an application as a **StarlingX App**.
- [Plugins](#plugins)
- [Metadata](#metadata)
- [Tarballs](#tarballs)
- [Armada Packaging](#armada-packaging)
- [Armada Manifest](#armada-manifest)
- [Metadata](#metadata-1)
- [Tarballs](#tarballs-1)
- [Customizing the application](#customizing-the-application)
- [FluxCD Manifest](#fluxcd-manifest)
- [FluxCD](#fluxcd)
- [Plugins](#plugins-1)
- [Other files](#other-files)
- [Armada Manifest](#armada-manifest-1)
## Why deploy an application as a StarlingX application?
@ -53,7 +48,7 @@ Deploying applications offers a number of benefits in a deployed environment:
## Software Requirements
- Helm version 2+
- Helm version 3+
- Python version 3.8+
- Python packages tracked in ./stx-app-generator/stx-app-generator/requirements.txt
- For Testing, Python packages tracked in ./test-requirements.txt
@ -130,7 +125,6 @@ This is what you'll find in the `app-gen-tool` repository:
│ ├── app_gen_tool
│ │ ├── __init__.py
│ │ ├── application.py
│ │ ├── armada.py
│ │ ├── cmd
│ │ │ ├── __init__.py
│ │ │ └── generator.py
@ -138,10 +132,6 @@ This is what you'll find in the `app-gen-tool` repository:
│ │ ├── constants.py
│ │ ├── fluxcd.py
│ │ ├── generator.py
│ │ ├── templates_armada
│ │ │ ├── armada-chart.template
│ │ │ ├── armada-chartgroup.template
│ │ │ └── armada-manifest.template
│ │ ├── templates_flux
│ │ │ ├── base
│ │ │ │ ├── helmrepository.template
@ -226,9 +216,6 @@ Note that the minimum required fields that will need to be filled in order
for the StarlingX App Generator to work properly will depend on the intended
type of packaging.
>_NOTE_: The two other sections bellow ([Metadata file configuration](#metadata-file-configuration)
and [App Setup Configuration](#app-setup-configuration)) will only be necessary
if you intend to package your application utilizing FluxCD.
### Metadata File Configuration
In this stage the section **metadataFile-config** from the
@ -274,7 +261,7 @@ Recommend reviewing the '-h' output for a full list of options.
Here is an example.
```shell
stx-app-generator -i app_manifest.yaml -t [armada/fluxcd/both] -o ./output
stx-app-generator -i app_manifest.yaml -o ./output
```
With the command above, the StarlingX App Generator will create a set of files
@ -355,8 +342,6 @@ everything.
Firstly it will package every helm-chart, that was given in the
`app_manifest.yaml` file, into a `.tgz` file, saving these files into a folder
named `charts`.
>_NOTE_: For the Armada packaging, the creation of the helm-charts tarball will
be before the creation of the manifest.
The generator, then, will package the plugins with the [wheel](https://peps.python.org/pep-0491/)
format.
@ -383,19 +368,7 @@ The structure of the app inside the tarball will be the following:
> At this point, the generated package is a working StarlingX App, however it
> contains empty templates for some files. The following sections will describe
> how to further enhance your StarlingX App.
### Armada Packaging
#### Armada Manifest
TODO: Check about adding this link
https://opendev.org/airship/armada/src/commit/2b714888c490a9f7c5a11383eb18b7226d1b1dc8/docs/source/operations/guide-build-armada-yaml.rst
#### Metadata
#TODO
#### Tarballs
#TODO
## Customizing the application
If you wish to add customization for the particularities of your application,
it is important to modify some of the generated files.
@ -404,13 +377,12 @@ In order to allow such customization, the generator provides additional
functions to modify specific files in the package.
```shell
stx-app-generator -i app_manifest.yaml -t <armada/fluxcd/both> [-o ./output] [--overwrite] [--no-package]|[--package-only]
stx-app-generator -i app_manifest.yaml [-o ./output] [--overwrite] [--no-package]|[--package-only]
```
Where:
- `-i/--input`: path to the `app_manifest.yaml` configuration file.
- `-t/--type`: type of packaging, needs to choose between armada, fluxcd or both.
- `-o/--output`: output folder. Defaults to a new folder with the app name in
the current directory.
- `--overwrite`: deletes existing output folder before starting.
@ -466,7 +438,3 @@ StarlingX platform.
With that in mind, it is recommended to check if the `metadata` and the `setup.cfg`
have been created as they should. Particularly, the `setup.cfg` may need careful
attention if the modifications on the plugin file should be reflected in it.
### Armada Manifest
#TODO

View File

@ -1,248 +0,0 @@
''' Module for generating Armada package'''
import os
import subprocess
from app_gen_tool.application import Application
from app_gen_tool import constants
class Armada(Application):
"""Class for generating Armada package"""
def __init__(self, app_data, output_folder):
super().__init__(app_data, output_folder)
for i in range(len(self._chart)):
self._chart[i]['releasePrefix'] = self._app['manifest']['releasePrefix']
# Initialize Armada manifest
self._manifest = self._app['manifest']
self._manifest['chart_groups'] = []
for i in range(len(self._chartgroup)):
self._manifest['chart_groups'].append(self._chartgroup[i]['name'])
# Generate armada application, including:
# 1. Check chart values
# 2. Create Armada directory
# 3. Generate helm chart tarballs
# 4. Generate armada manifest
# 5. Generate metadata file
# 6. Generage checksum file
# 7. Package Armada application
#
def generate(self, package_only, no_package):
"""Function called for generating Armada application"""
ret = False
if not self._validate_app_attributes():
print('Error: Some of the app attributes are not valid!')
return ret
self._app['outputDir'] = self.output_folder
self._app['outputArmadaDir'] = os.path.join(self.output_folder, 'Armada')
self._app['outputArmadaChartDir'] = os.path.join(
self.output_folder, 'Armada', 'charts'
)
# 1 - Validate input file and helm chart data
self.check_charts()
if not package_only:
# 2. Generate armada directories
self._create_armada_dir()
# 3. Generating helm chart tarball
for chart in self._chart:
ret = self._gen_helm_chart_tarball(
chart, self._app['outputArmadaChartDir']
)
if ret:
print(f'Helm chart {chart["name"]} tarball generated!')
print('')
else:
print(
f'Generating tarball for helm chart: {chart["name"]} error!'
)
return ret
# 4. Generating armada manifest
ret = self._gen_armada_manifest()
if ret:
print('Armada manifest generated!')
else:
print('Armada manifest generation failed!')
return ret
# 5. Generating metadata file
ret = self._gen_metadata(self._app['outputArmadaDir'])
if ret:
print('Metadata generated!')
else:
print('Armada Metadata generation failed!')
return ret
if not no_package:
# 6&7. Generating checksum file and tarball
ret = self._gen_checksum_and_app_tarball(self._app['outputArmadaDir'])
if ret:
print('Checksum generated!')
print(
f'Armada App tarball generated at {self._app["outputArmadaDir"]}/{ret}'
)
print('')
else:
print('Checksum and App tarball generation failed!')
return ret
return ret
# TODO: Validate values
def _validate_app_values(self, app_data): # pylint: disable=unused-argument
return True
# TODO: Validate values
def _validate_manifest_values(
self, manifest_data
): # pylint: disable=unused-argument
return True
# TODO: Validate values
def _validate_chartgroup_values(
self, chartgroup_data
): # pylint: disable=unused-argument
return True
# TODO: Validate values
def _validate_chart_values(self, chart_data): # pylint: disable=unused-argument
return True
def _validate_app_attributes(self):
if not self._validate_app_values(self._app):
return False
if not self._validate_manifest_values(self._manifest):
return False
if not self._validate_chartgroup_values(self._chartgroup):
return False
if not self._validate_chart_values(self._chart):
return False
return True
def _create_armada_dir(self):
if not os.path.exists(self._app['outputArmadaDir']):
os.makedirs(self._app['outputArmadaDir'])
if not os.path.exists(self._app['outputArmadaChartDir']):
os.makedirs(self._app['outputArmadaChartDir'])
def _gen_armada_manifest(self):
'''Sub-process of app generation. Generate application manifest file.'''
# check manifest file existance
app_yaml_file = f'{self._app["appName"]}.yaml'
manifest_file = os.path.join(self._app['outputArmadaDir'], app_yaml_file)
if os.path.exists(manifest_file):
os.remove(manifest_file)
# update schema path to abspath
chart_template = os.path.join(
constants.APP_GEN_PY_PATH, constants.ARMADA_CHART_TEMPLATE
)
chartgroup_template = os.path.join(
constants.APP_GEN_PY_PATH, constants.ARMADA_CHARTGROUP_TEMPLATE
)
manifest_template = os.path.join(
constants.APP_GEN_PY_PATH, constants.ARMADA_MANIFEST_TEMPLATE
)
# generate chart schema
try:
with open(chart_template, 'r', encoding='utf-8') as f:
chart_schema = f.readlines()
except FileNotFoundError:
print(f'File {chart_template} not found')
return False
with open(manifest_file, 'a', encoding='utf-8') as f:
# iterate each armada_chart
for idx in range(len(self._chart)):
a_chart = self._chart[idx]
# fetch chart specific info
if not self._fetch_info_from_chart(idx):
return False
for line in chart_schema:
# substitute template values and blocks
self._write_values_and_blocks(f, line, a_chart)
# generate chartgroup schema
try:
with open(chartgroup_template, 'r', encoding='utf-8') as f:
chartgroup_schema = f.readlines()
except FileNotFoundError:
print(f'File {chartgroup_template} not found')
return False
with open(manifest_file, 'a', encoding='utf-8') as f:
# iterate each chartgroup
for chartgroup in self._chartgroup:
for line in chartgroup_schema:
self._write_values_and_blocks(f, line, chartgroup)
# generate manifest schema
try:
with open(manifest_template, 'r', encoding='utf-8') as f:
manifest_schema = f.readlines()
except FileNotFoundError:
print(f'File {manifest_template} not found')
return False
with open(manifest_file, 'a', encoding='utf-8') as f:
# only one manifest in an application
manifest = self._manifest
# substitute values
for line in manifest_schema:
self._write_values_and_blocks(f, line, manifest)
return True
# Fetch info from helm chart to fill
# the values that needs to be substituted
# Below info are needed:
# - waitLabelKey
# - chartArcname
def _fetch_info_from_chart(self, chart_idx):
a_chart = self._chart[chart_idx]
bin_fetch_script = os.path.join(
constants.APP_GEN_PY_PATH, constants.BIN_FETCH_CHART_INFO
)
# waitLabelKey
# search for the key of label which indicates '.Release.Name'
# within deployment, statefulset, daemonset yaml file
cmd = [bin_fetch_script, 'waitlabel', a_chart['path']]
subproc = subprocess.run(
cmd, env=os.environ.copy(), stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if subproc.returncode == 0:
output = str(subproc.stdout, encoding='utf-8')
if output.strip():
a_chart['waitLabelKey'] = output.strip()
if 'waitLabelKey' not in a_chart:
print(
f'The label which indicates .Release.Name is not found in {a_chart["name"]}.'
)
return False
# chartArcname is the helm chart name in Chart.yaml
# it is used as tarball arcname during helm package
cmd = [bin_fetch_script, 'chartname', a_chart['path']]
subproc = subprocess.run(
cmd, env=os.environ.copy(), stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if subproc.returncode == 0:
output = str(subproc.stdout, encoding='utf-8')
if output.strip():
a_chart['chartArcname'] = output.strip()
if 'chartArcname' not in a_chart:
print(
f'The name within Chart.yaml of chart {a_chart["name"]} folder is not found'
)
return False
return True

View File

@ -1,13 +1,7 @@
"""Declare Constants for Repository Here."""
# Variables for armada packaging
import getpass
import os
# Variables for Aramada packaging
ARMADA_CHART_TEMPLATE = os.path.join('templates_armada', 'armada-chart.template')
ARMADA_CHARTGROUP_TEMPLATE = os.path.join('templates_armada', 'armada-chartgroup.template')
ARMADA_MANIFEST_TEMPLATE = os.path.join('templates_armada', 'armada-manifest.template')
# Variables for FluxCD packaging
FLUXCD_KUSTOMIZATION_TEMPLATE = os.path.join('templates_fluxcd', 'kustomization.template')
FLUXCD_BASE_TEMPLATES = os.path.join('templates_fluxcd', 'base')

View File

@ -6,7 +6,6 @@ import shutil
import sys
import yaml
from app_gen_tool.armada import Armada
from app_gen_tool.fluxcd import FluxCD
@ -129,7 +128,6 @@ def print_help():
print('Options:')
print(' -i, --input yaml_file generate app from yaml_file')
print(' -o, --output folder generate app to output folder')
print(' -t, --type package select Armada, Fluxcd or Both packaging')
print(' --overwrite overwrite the output dir')
print(' --no-package does not create app tarball')
print(' --package-only only creates tarball from dir')
@ -177,24 +175,16 @@ def create_app_directories(app_out, overwrite):
os.makedirs(app_out)
def generate_app(app_data, package_type, output_folder, package_only, no_package):
"""Generates the app based on the package type"""
if package_type in ('armada', 'both'):
app = Armada(app_data, output_folder)
app.generate(package_only, no_package)
elif package_type in ('fluxcd', 'both'):
app = FluxCD(app_data, output_folder)
app.generate(package_only, no_package)
else:
print('Error: Invalid package type')
sys.exit(1)
def generate_app(app_data, output_folder, package_only, no_package):
"""Generates the app."""
app = FluxCD(app_data, output_folder)
app.generate(package_only, no_package)
def main(argv):
"""Main Method with argument parsing."""
input_file = ''
output_folder = '.'
package_type = ''
overwrite = False
package_only = False
no_package = False
@ -224,8 +214,6 @@ def main(argv):
input_file = value
if option in ('-o', '--output', '--output='):
output_folder = value
if option in ('-t', '--type', '--type='):
package_type = value.lower()
if option in ('--no-package'):
no_package = True
if option in ('--package-only'):
@ -237,9 +225,7 @@ def main(argv):
'. Please consult our README if further clarification is needed'
)
sys.exit(1)
if not package_type:
print('Error: Select type of packaging (armada/fluxcd/both)')
sys.exit(1)
if not os.path.isfile(os.path.abspath(input_file)):
print('Error: input file not found')
sys.exit(1)
@ -257,5 +243,4 @@ def main(argv):
create_app_directories(output_folder, overwrite)
# app = Application(app_data, package_type, output_folder)
generate_app(app_data, package_type, output_folder, package_only, no_package)
generate_app(app_data, output_folder, package_only, no_package)

View File

@ -1,26 +0,0 @@
---
schema: armada/Chart/v1
metadata:
schema: metadata/Document/v1
name: $NAME$
data:
chart_name: $NAME$
release: $NAME$
namespace: $NAMESPACE$
test:
enabled: false
wait:
timeout: $WAIT%600$
labels:
$WAIT_LABEL_KEY$: $RELEASE_PREFIX$-$NAME$
install:
no_hooks: false
upgrade:
no_hooks: false
@VALUES|2@
source:
type: tar
location: http://172.17.0.1:8080/helm_charts/starlingx/$TARBALL_NAME$
subpath: $CHART_ARCNAME$
dependencies: []

View File

@ -1,11 +0,0 @@
---
schema: armada/ChartGroup/v1
metadata:
schema: metadata/Document/v1
name: $NAME$
data:
description: $DESCRIPTION%This is a chartgroup$
sequenced: $SEQUENCED%false$
chart_group:
@CHART_NAMES|4@

View File

@ -1,9 +0,0 @@
---
schema: armada/Manifest/v1
metadata:
schema: metadata/Document/v1
name: $NAME$
data:
release_prefix: $RELEASE_PREFIX$
chart_groups:
@CHART_GROUPS|4@

View File

@ -49,9 +49,5 @@ setup(
f'{SITE_PACKAGES_DIR}/{PACKAGE_DIRECTORY}/templates_plugins',
_get_list_of_files(f'{PACKAGE_DIRECTORY}/templates_plugins')
),
(
f'{SITE_PACKAGES_DIR}/{PACKAGE_DIRECTORY}/templates_armada',
_get_list_of_files(f'{PACKAGE_DIRECTORY}/templates_armada')
),
]
)