From fa00b283c613ce84f8f4e62549ebc14c6a161660 Mon Sep 17 00:00:00 2001 From: Guilherme Santos Date: Fri, 24 May 2024 17:25:40 -0300 Subject: [PATCH] C-state Management StarlingX Application This commit adds the `cstate-management` StarlingX application. Test Plan: PASS: AIO-SX: check whether the application installs successfully. PASS: AIO-DX: check whether the application installs successfully. PASS: AIO-DX: check whether the application is successfully removed and deleted. PASS: AIO-DX: check whether daemonsets and pods are removed on application removal/deletion. PASS: AIO-DX: check whether the namespace is deleted upon application removal/deletion. PASS: check whether `build-image` runs successfully. PASS: check whether label "app.starlingx.io/component" was applied to "cstate-management" namespace on install. Story: 2011105 Task: 50178 Authored-By: Guilherme Santos Co-Authored-By: Vinicius Lobo Change-Id: Ie99a605a81a1d9ccdabba78be4f020ed549c649d Signed-off-by: Guilherme Santos --- .zuul.yaml | 96 ++++++- debian_iso_image.inc | 1 + debian_pkg_dirs | 2 + .../debian/deb_folder/changelog | 5 + .../debian/deb_folder/control | 27 ++ .../debian/deb_folder/copyright | 41 +++ ...n3-k8sapp-cstate-management-wheels.install | 1 + .../python3-k8sapp-cstate-management.install | 1 + .../debian/deb_folder/rules | 33 +++ .../debian/deb_folder/source/format | 2 + .../debian/meta_data.yaml | 9 + .../k8sapp_cstate_management/.gitignore | 35 +++ .../k8sapp_cstate_management/.stestr.conf | 4 + .../k8sapp_cstate_management/LICENSE | 203 +++++++++++++++ .../k8sapp_cstate_management/README.rst | 5 + .../k8sapp_cstate_management/__init__.py | 0 .../common/__init__.py | 0 .../common/constants.py | 19 ++ .../k8sapp_cstate_management/helm/__init__.py | 0 .../helm/cstate_management.py | 43 ++++ .../lifecycle/__init__.py | 0 .../lifecycle/lifecycle_cstate_management.py | 153 +++++++++++ .../tests/__init__.py | 0 .../tests/test_cstate_management.py | 32 +++ .../tests/test_plugins.py | 37 +++ .../k8sapp_cstate_management/pylint.rc | 240 ++++++++++++++++++ .../k8sapp_cstate_management/requirements.txt | 2 + .../k8sapp_cstate_management/setup.cfg | 37 +++ .../k8sapp_cstate_management/setup.py | 12 + .../test-requirements.txt | 22 ++ .../k8sapp_cstate_management/tox.ini | 116 +++++++++ .../upper-constraints.txt | 2 + .../debian/deb_folder/changelog | 5 + .../debian/deb_folder/control | 17 ++ .../debian/deb_folder/copyright | 41 +++ stx-cstate-management/debian/deb_folder/rules | 63 +++++ .../debian/deb_folder/source/format | 1 + .../deb_folder/stx-cstate-management.install | 1 + stx-cstate-management/debian/meta_data.yaml | 13 + .../stx-cstate-management/files/metadata.yaml | 24 ++ .../fluxcd-manifests/base/helmrepository.yaml | 12 + .../fluxcd-manifests/base/kustomization.yaml | 9 + .../cstate-management-static-overrides.yaml | 5 + .../cstate-management-system-overrides.yaml | 5 + .../cstate-management/helmrelease.yaml | 36 +++ .../cstate-management/kustomization.yaml | 19 ++ .../fluxcd-manifests/kustomization.yaml | 11 + 47 files changed, 1441 insertions(+), 1 deletion(-) create mode 100644 debian_iso_image.inc create mode 100644 python3-k8sapp-cstate-management/debian/deb_folder/changelog create mode 100644 python3-k8sapp-cstate-management/debian/deb_folder/control create mode 100644 python3-k8sapp-cstate-management/debian/deb_folder/copyright create mode 100644 python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management-wheels.install create mode 100644 python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management.install create mode 100644 python3-k8sapp-cstate-management/debian/deb_folder/rules create mode 100644 python3-k8sapp-cstate-management/debian/deb_folder/source/format create mode 100644 python3-k8sapp-cstate-management/debian/meta_data.yaml create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/.gitignore create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/.stestr.conf create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/LICENSE create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/README.rst create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/__init__.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/common/__init__.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/common/constants.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/helm/__init__.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/helm/cstate_management.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/lifecycle/__init__.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/lifecycle/lifecycle_cstate_management.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/__init__.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_cstate_management.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_plugins.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/pylint.rc create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/requirements.txt create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.cfg create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.py create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/test-requirements.txt create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini create mode 100644 python3-k8sapp-cstate-management/k8sapp_cstate_management/upper-constraints.txt create mode 100644 stx-cstate-management/debian/deb_folder/changelog create mode 100644 stx-cstate-management/debian/deb_folder/control create mode 100644 stx-cstate-management/debian/deb_folder/copyright create mode 100644 stx-cstate-management/debian/deb_folder/rules create mode 100644 stx-cstate-management/debian/deb_folder/source/format create mode 100644 stx-cstate-management/debian/deb_folder/stx-cstate-management.install create mode 100644 stx-cstate-management/debian/meta_data.yaml create mode 100644 stx-cstate-management/stx-cstate-management/files/metadata.yaml create mode 100644 stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/helmrepository.yaml create mode 100644 stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/kustomization.yaml create mode 100644 stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-static-overrides.yaml create mode 100644 stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-system-overrides.yaml create mode 100644 stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/helmrelease.yaml create mode 100644 stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/kustomization.yaml create mode 100644 stx-cstate-management/stx-cstate-management/fluxcd-manifests/kustomization.yaml diff --git a/.zuul.yaml b/.zuul.yaml index f45c052..46f94bf 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -3,6 +3,11 @@ check: jobs: - openstack-tox-linters + - k8sapp-cstate-management-tox-py39 + - k8sapp-cstate-management-tox-pylint + - k8sapp-cstate-management-tox-flake8 + - k8sapp-cstate-management-tox-bandit + - k8sapp-cstate-management-tox-metadata - cstate-management-tox-py39 - cstate-management-tox-pylint - cstate-management-tox-flake8 @@ -10,6 +15,11 @@ gate: jobs: - openstack-tox-linters + - k8sapp-cstate-management-tox-py39 + - k8sapp-cstate-management-tox-pylint + - k8sapp-cstate-management-tox-flake8 + - k8sapp-cstate-management-tox-bandit + - k8sapp-cstate-management-tox-metadata - cstate-management-tox-py39 - cstate-management-tox-pylint - cstate-management-tox-flake8 @@ -18,6 +28,90 @@ jobs: - stx-app-cstate-management-upload-git-mirror +# Python Jobs +- job: + name: k8sapp-cstate-management-tox-py39 + parent: tox-py39 + description: | + Run py39 test for k8sapp-cstate-management + nodeset: debian-bullseye + required-projects: + - starlingx/config + - starlingx/fault + - starlingx/update + - starlingx/utilities + files: + - python3-k8sapp-cstate-management/* + vars: + tox_envlist: py39 + python_version: 3.9 + tox_extra_args: -c python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini + +- job: + name: k8sapp-cstate-management-tox-pylint + parent: tox + description: | + Run pylint test for k8sapp-cstate-management + nodeset: debian-bullseye + required-projects: + - starlingx/config + - starlingx/fault + - starlingx/update + - starlingx/utilities + files: + - python3-k8sapp-cstate-management/* + vars: + tox_envlist: pylint + tox_extra_args: -c python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini + +- job: + name: k8sapp-cstate-management-tox-flake8 + parent: tox + description: | + Run flake8 test for k8sapp_cstate_management + nodeset: debian-bullseye + required-projects: + - starlingx/config + - starlingx/fault + - starlingx/update + - starlingx/utilities + - starlingx/root + files: + - python3-k8sapp-cstate-management/* + vars: + tox_envlist: flake8 + tox_extra_args: -c python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini + tox_constraints_file: '{{ ansible_user_dir }}/src/opendev.org/starlingx/root/build-tools/requirements/debian/upper-constraints.txt' + +- job: + name: k8sapp-cstate-management-tox-metadata + parent: tox + description: | + Run metadata test for k8sapp_cstate_management + nodeset: debian-bullseye + required-projects: + - starlingx/config + - starlingx/fault + - starlingx/update + - starlingx/utilities + - starlingx/root + vars: + tox_envlist: metadata + tox_extra_args: -c python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini + tox_constraints_file: '{{ ansible_user_dir }}/src/opendev.org/starlingx/root/build-tools/requirements/debian/upper-constraints.txt' + +- job: + name: k8sapp-cstate-management-tox-bandit + parent: tox + description: | + Run bandit test for cstate-management + nodeset: debian-bullseye + files: + - python3-k8sapp-cstate-management/* + vars: + tox_envlist: bandit + tox_extra_args: -c python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini + # Application Jobs - job: name: cstate-management-tox-py39 @@ -94,7 +188,7 @@ name: cstate-management-tox-bandit parent: tox description: | - Run bandit test for cstate-management + Run bandit test for cstate-management nodeset: debian-bullseye files: - cstate-management/* diff --git a/debian_iso_image.inc b/debian_iso_image.inc new file mode 100644 index 0000000..d9c6ce8 --- /dev/null +++ b/debian_iso_image.inc @@ -0,0 +1 @@ +stx-cstate-management diff --git a/debian_pkg_dirs b/debian_pkg_dirs index 6f40789..54ab523 100644 --- a/debian_pkg_dirs +++ b/debian_pkg_dirs @@ -1 +1,3 @@ helm-charts/custom/cstate-management-helm +python3-k8sapp-cstate-management +stx-cstate-management diff --git a/python3-k8sapp-cstate-management/debian/deb_folder/changelog b/python3-k8sapp-cstate-management/debian/deb_folder/changelog new file mode 100644 index 0000000..7e333f7 --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/deb_folder/changelog @@ -0,0 +1,5 @@ +python3-k8sapp-cstate-management (1.0-0) unstable; urgency=medium + + * Initial Release + + -- Guilherme Santos Thu, 2 May 2024 10:26:00 +0000 diff --git a/python3-k8sapp-cstate-management/debian/deb_folder/control b/python3-k8sapp-cstate-management/debian/deb_folder/control new file mode 100644 index 0000000..f204e0c --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/deb_folder/control @@ -0,0 +1,27 @@ +Source: python3-k8sapp-cstate-management +Section: libs +Priority: optional +Maintainer: StarlingX Developers +Build-Depends: debhelper-compat (= 13), + dh-python, + python3-all, + python3-pbr, + python3-setuptools, + python3-wheel, + build-info +Standards-Version: 4.5.1 +Homepage: https://www.starlingx.io + +Package: python3-k8sapp-cstate-management +Section: libs +Architecture: any +Depends: ${misc:Depends}, ${python3:Depends} +Description: StarlingX Sysinv C-state Management Extensions + This package contains sysinv plugins for the C-state Management K8S app. + +Package: python3-k8sapp-cstate-management-wheels +Section: libs +Architecture: any +Depends: ${misc:Depends}, ${python3:Depends}, python3-wheel +Description: StarlingX Sysinv C-state Management Extension Wheels + This package contains python wheels for the C-state Management K8S app plugins. diff --git a/python3-k8sapp-cstate-management/debian/deb_folder/copyright b/python3-k8sapp-cstate-management/debian/deb_folder/copyright new file mode 100644 index 0000000..0a6fe5d --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/deb_folder/copyright @@ -0,0 +1,41 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: python3-k8sapp-cstate-management +Source: https://opendev.org/starlingx/app-kubernetes-power-manager/ + +Files: * +Copyright: (c) 2024 Wind River Systems, Inc +License: Apache-2 + 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 + . + https://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. + . + On Debian-based systems the full text of the Apache version 2.0 license + can be found in `/usr/share/common-licenses/Apache-2.0'. + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: debian/* +Copyright: 2024 Wind River Systems, Inc +License: Apache-2 + 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 + . + https://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. + . + On Debian-based systems the full text of the Apache version 2.0 license + can be found in `/usr/share/common-licenses/Apache-2.0'. diff --git a/python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management-wheels.install b/python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management-wheels.install new file mode 100644 index 0000000..19a9e4c --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management-wheels.install @@ -0,0 +1 @@ +plugins/*.whl diff --git a/python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management.install b/python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management.install new file mode 100644 index 0000000..91d1d9d --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/deb_folder/python3-k8sapp-cstate-management.install @@ -0,0 +1 @@ +usr/lib/python3/dist-packages/k8sapp_* diff --git a/python3-k8sapp-cstate-management/debian/deb_folder/rules b/python3-k8sapp-cstate-management/debian/deb_folder/rules new file mode 100644 index 0000000..ac16186 --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/deb_folder/rules @@ -0,0 +1,33 @@ +#!/usr/bin/make -f +# export DH_VERBOSE = 1 + +export APP_NAME = cstate-management +export PYBUILD_NAME = k8sapp-cstate-management + +export DEB_VERSION = $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ') +export MAJOR = $(shell cat /etc/build.info | grep SW_VERSION | cut -d'"' -f2) +export MINOR = $(shell echo $(DEB_VERSION) | cut -f 4 -d '.') +export PBR_VERSION = $(MAJOR).$(MINOR) + +export ROOT = $(CURDIR)/debian/tmp +export SKIP_PIP_INSTALL = 1 + +%: + dh $@ --with=python3 --buildsystem=pybuild + +override_dh_auto_install: + env | sort + + python3 setup.py install \ + --install-layout=deb \ + --root $(ROOT) + + python3 setup.py bdist_wheel \ + --universal \ + -d $(ROOT)/plugins + +override_dh_python3: + dh_python3 --shebang=/usr/bin/python3 + +override_dh_auto_test: + PYTHONDIR=$(CURDIR) stestr run diff --git a/python3-k8sapp-cstate-management/debian/deb_folder/source/format b/python3-k8sapp-cstate-management/debian/deb_folder/source/format new file mode 100644 index 0000000..c3d9f24 --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/deb_folder/source/format @@ -0,0 +1,2 @@ +3.0 (quilt) + diff --git a/python3-k8sapp-cstate-management/debian/meta_data.yaml b/python3-k8sapp-cstate-management/debian/meta_data.yaml new file mode 100644 index 0000000..a313533 --- /dev/null +++ b/python3-k8sapp-cstate-management/debian/meta_data.yaml @@ -0,0 +1,9 @@ +--- +debname: python3-k8sapp-cstate-management +debver: 1.0-0 +src_path: k8sapp_cstate_management +revision: + dist: $STX_DIST + GITREVCOUNT: + SRC_DIR: ${MY_REPO}/stx/app-cstate-management + BASE_SRCREV: dae78a8cccdfc11f34d195daf7d05b4c8c022b71 diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/.gitignore b/python3-k8sapp-cstate-management/k8sapp_cstate_management/.gitignore new file mode 100644 index 0000000..78c457c --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/.gitignore @@ -0,0 +1,35 @@ +# Compiled files +*.py[co] +*.a +*.o +*.so + +# Sphinx +_build +doc/source/api/ + +# Packages/installer info +*.egg +*.egg-info +dist +build +eggs +parts +var +sdist +develop-eggs +.installed.cfg + +# Other +*.DS_Store +.stestr +.testrepository +.tox +.venv +.*.swp +.coverage +bandit.xml +cover +AUTHORS +ChangeLog +*.sqlite diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/.stestr.conf b/python3-k8sapp-cstate-management/k8sapp_cstate_management/.stestr.conf new file mode 100644 index 0000000..208c04b --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/.stestr.conf @@ -0,0 +1,4 @@ +[DEFAULT] +test_path=./k8sapp_cstate_management/tests +top_dir=./k8sapp_cstate_management +#parallel_class=True \ No newline at end of file diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/LICENSE b/python3-k8sapp-cstate-management/k8sapp_cstate_management/LICENSE new file mode 100644 index 0000000..4419961 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/LICENSE @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2021 Wind River Systems, Inc. + + 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. + diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/README.rst b/python3-k8sapp-cstate-management/k8sapp_cstate_management/README.rst new file mode 100644 index 0000000..8c97d3d --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/README.rst @@ -0,0 +1,5 @@ +python3-k8sapp-cstate-management +================================ + +This project contains StarlingX Kubernetes application specific python plugins +for the C-state Management. diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/__init__.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/common/__init__.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/common/constants.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/common/constants.py new file mode 100644 index 0000000..1609717 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/common/constants.py @@ -0,0 +1,19 @@ +# +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# Application Name +HELM_APP_CSTATE_MANAGEMENT = 'cstate-management' + +# Namespace to deploy the application +HELM_NS_CSTATE_MANAGEMENT = 'cstate-management' + +# Chart Name +HELM_CHART_CSTATE_MANAGEMENT = 'cstate-management' + +# Component constants +HELM_COMPONENT_LABEL = 'app.starlingx.io/component' +HELM_DEFAULT_COMPONENT_VALUE = 'platform' +HELM_SUPPORTED_COMPONENT_VALUES = ['application', 'platform'] diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/helm/__init__.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/helm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/helm/cstate_management.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/helm/cstate_management.py new file mode 100644 index 0000000..8b99a85 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/helm/cstate_management.py @@ -0,0 +1,43 @@ +# +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +from sysinv.common import exception +from sysinv.helm import base + +from k8sapp_cstate_management.common import constants as app_constants + + +class CStateManagementHelm(base.BaseHelm): + """Class to encapsulate helm operations for the C-state Management chart""" + + SUPPORTED_NAMESPACES = base.BaseHelm.SUPPORTED_NAMESPACES + \ + [app_constants.HELM_NS_CSTATE_MANAGEMENT] + + SUPPORTED_APP_NAMESPACES = { + app_constants.HELM_APP_CSTATE_MANAGEMENT: SUPPORTED_NAMESPACES, + } + + CHART = app_constants.HELM_CHART_CSTATE_MANAGEMENT + + SERVICE_NAME = app_constants.HELM_APP_CSTATE_MANAGEMENT + + def get_namespaces(self): + return self.SUPPORTED_NAMESPACES + + def get_overrides(self, namespace=None): + + overrides = { + app_constants.HELM_NS_CSTATE_MANAGEMENT: {} + } + + if namespace in self.SUPPORTED_NAMESPACES: + return overrides[namespace] + + if namespace: + raise exception.InvalidHelmNamespace(chart=self.CHART, + namespace=namespace) + + return overrides diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/lifecycle/__init__.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/lifecycle/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/lifecycle/lifecycle_cstate_management.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/lifecycle/lifecycle_cstate_management.py new file mode 100644 index 0000000..141ad59 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/lifecycle/lifecycle_cstate_management.py @@ -0,0 +1,153 @@ +# +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +# All Rights Reserved. +# + +""" System inventory App lifecycle operator.""" +from k8sapp_cstate_management.common import constants as app_constants +from oslo_log import log as logging +from sysinv.common import constants as cst +from sysinv.helm import lifecycle_base as base +import yaml + + +LOG = logging.getLogger(__name__) + + +class CStateManagementAppLifecycleOperator(base.AppLifecycleOperator): + def app_lifecycle_actions(self, context, conductor_obj, app_op, + app, hook_info): + """Perform lifecycle actions for an operation + + :param context: request context, can be None + :param conductor_obj: conductor object, can be None + :param app_op: AppOperator object + :param app: AppOperator.Application object + :param hook_info: LifecycleHookInfo object + + """ + + # FluxCD Request + if (hook_info.lifecycle_type == cst.APP_LIFECYCLE_TYPE_FLUXCD_REQUEST + and hook_info.operation == cst.APP_APPLY_OP + and hook_info.relative_timing == cst.APP_LIFECYCLE_TIMING_PRE): + return self._pre_fluxcd_request(app, app_op) + + # Operation + if (hook_info.lifecycle_type == cst.APP_LIFECYCLE_TYPE_OPERATION + and hook_info.operation == cst.APP_REMOVE_OP + and hook_info.relative_timing == cst.APP_LIFECYCLE_TIMING_POST): + return self._post_remove(app, app_op) + + super(CStateManagementAppLifecycleOperator, + self).app_lifecycle_actions( + context, conductor_obj, app_op, app, hook_info + ) + + def _pre_fluxcd_request(self, app, app_op): + LOG.debug(f"Executing pre_fluxcd_request for {app.name} app") + + # Applying label on namespace before running FluxCD manifests + # to ensure that all pods in this namespace run on correct cores + self._update_component_label(app, app_op) + + def _update_component_label(self, app, app_op): + """Create the StarlingX component label in namespace + + :param app_op: AppOperator object + :param app: AppOperator.Application object + """ + + user_overrides = self._get_user_overrides(app._kube_app, app_op._dbapi) + component_label = user_overrides.get( + app_constants.HELM_COMPONENT_LABEL, + app_constants.HELM_DEFAULT_COMPONENT_VALUE) + + if component_label in app_constants.HELM_SUPPORTED_COMPONENT_VALUES: + # Get namespace attributes + k8s_client_core = app_op._kube._get_kubernetesclient_core() + namespace = k8s_client_core.read_namespace( + app_constants.HELM_NS_CSTATE_MANAGEMENT) + + # Previous value + previous_component_label = namespace.metadata.labels.get( + app_constants.HELM_COMPONENT_LABEL) + + # Set label in namespace + namespace.metadata.labels.update( + { + app_constants.HELM_COMPONENT_LABEL: + component_label + }) + app_op._kube.kube_patch_namespace( + app_constants.HELM_NS_CSTATE_MANAGEMENT, + namespace) + + # Restarts all pods in namespace if label has changed + if (previous_component_label is not None and + previous_component_label != component_label): + self._delete_pods(app_op, k8s_client_core) + + else: + raise ValueError(f"Value {component_label} for label:namespace" + f"{app_constants.HELM_COMPONENT_LABEL}:" + f"{app_constants.HELM_NS_CSTATE_MANAGEMENT}" + " is not supported") + + def _get_user_overrides(self, kube_app, dbapi): + """Get user overrides from db + + :param kube_app: Kubernetes Application instance + :param dbapi: dbapi + :return User overrides in dict format + """ + + user_overrides = {} + + overrides = dbapi.helm_override_get( + kube_app.id, + app_constants.HELM_CHART_CSTATE_MANAGEMENT, + app_constants.HELM_NS_CSTATE_MANAGEMENT) + + if overrides.user_overrides: + user_overrides = yaml.safe_load(overrides.user_overrides) + + return user_overrides + + def _post_remove(self, app, app_op): + LOG.debug(f"Executing post_remove for {app.name} app") + + k8s_client_core = app_op._kube._get_kubernetesclient_core() + + # Remove all pods started by the daemonset and any orphan + # pods in namespace + self._delete_pods(app_op, k8s_client_core) + + # Remove the namespace + app_op._kube.kube_delete_namespace( + app_constants.HELM_NS_CSTATE_MANAGEMENT) + + def _delete_pods(self, app_op, k8s_client_core): + """Delete all pods within the application namespace + + :param app_op: AppOperator object + :param k8s_client_core: Kubernetes client object + """ + + try: + pods = k8s_client_core.list_namespaced_pod( + app_constants.HELM_NS_CSTATE_MANAGEMENT) + + for pod in pods.items: + app_op._kube.kube_delete_pod( + name=pod.metadata.name, + namespace=app_constants.HELM_NS_CSTATE_MANAGEMENT, + grace_periods_seconds=0 + ) + + except Exception: + LOG.error("Failed to delete pods in namespace %s", + app_constants.HELM_NS_CSTATE_MANAGEMENT) diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/__init__.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_cstate_management.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_cstate_management.py new file mode 100644 index 0000000..cc41f0e --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_cstate_management.py @@ -0,0 +1,32 @@ +# +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +from k8sapp_cstate_management.common import constants as app_constants +from k8sapp_cstate_management.tests import test_plugins +from sysinv.db import api as dbapi +from sysinv.tests.db import base as dbbase +from sysinv.tests.db import utils as dbutils +from sysinv.tests.helm import base + + +class CStateManagementTestCase( + test_plugins.K8SAppCStateManagementAppMixin, + base.HelmTestCaseMixin): + + def setUp(self): + super(CStateManagementTestCase, self).setUp() + self.app = dbutils.create_test_app( + name=app_constants.HELM_APP_CSTATE_MANAGEMENT + ) + self.dbapi = dbapi.get_instance() + + +class CStateManagementTestCaseDummy( + CStateManagementTestCase, + dbbase.ProvisionedControllerHostTestCase): + # without a test zuul will fail + def test_dummy(self): + pass diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_plugins.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_plugins.py new file mode 100644 index 0000000..0df6b82 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/k8sapp_cstate_management/tests/test_plugins.py @@ -0,0 +1,37 @@ +# +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +from k8sapp_cstate_management.common import constants as app_constants +from sysinv.tests.db import base as dbbase + + +class K8SAppCStateManagementAppMixin(object): + app_name = app_constants.HELM_APP_CSTATE_MANAGEMENT + path_name = app_name + '.tgz' + + def setUp(self): + super(K8SAppCStateManagementAppMixin, self).setUp() + + +# Test Configuration: +# - Controller +# - IPv6 +# - cstate-management app +class K8sAppCStateManagementControllerTestCase( + K8SAppCStateManagementAppMixin, + dbbase.BaseIPv6Mixin, + dbbase.ControllerHostTestCase): + pass + + +# Test Configuration: +# - AIO +# - IPv4 +# - cstate-management app +class K8SAppCStateManagementAIOTestCase( + K8SAppCStateManagementAppMixin, + dbbase.AIOSimplexHostTestCase): + pass diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/pylint.rc b/python3-k8sapp-cstate-management/k8sapp_cstate_management/pylint.rc new file mode 100644 index 0000000..fda2068 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/pylint.rc @@ -0,0 +1,240 @@ +[MASTER] +# Specify a configuration file. +rcfile=pylint.rc + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Add files or directories to the blacklist. Should be base names, not paths. +ignore= + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Use multiple processes to speed up Pylint. +jobs=4 + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist=lxml.etree,greenlet + + + +[MESSAGES CONTROL] +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). +# See "Messages Control" section of +# https://pylint.readthedocs.io/en/latest/user_guide +disable= + # C codes refer to Convention + C0103, # invalid-name + C0114, # missing-module-docstring + C0115, # missing-class-docstring + C0116, # missing-function-docstring + C0411, # wrong-import-order + # R codes refer to refactoring + R0205, # useless-object-inheritance + R0901, # too-many-ancestors + R0903, # too-few-public-methods + R0913, # too-many-arguments + R1710, # inconsistent-return-statements + R1725, # super-with-arguments + # W codes are warnings + W0212, # protected-access + W0246, # useless-parent-delegation + W0718, # broad-exception-caught + +[REPORTS] +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + + +[SIMILARITIES] +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + + +[FORMAT] +# Maximum number of characters on a single line. +max-line-length=85 + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually 4 spaces or "\t" (1 tab). +indent-string=' ' + + +[TYPECHECK] +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis +ignored-modules=distutils,eventlet.green.subprocess,six,six.moves + +# List of classes names for which member attributes should not be checked +# (useful for classes with attributes dynamically set). +# pylint is confused by sqlalchemy Table, as well as sqlalchemy Enum types +# ie: (unprovisioned, identity) +# LookupDict in requests library confuses pylint +ignored-classes=SQLObject, optparse.Values, thread._local, _thread._local, + Table, unprovisioned, identity, LookupDict + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E0201 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST,acl_users,aq_parent + + +[BASIC] +# Regular expression which should only match correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression which should only match correct module level names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression which should only match correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Regular expression which should only match correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct method names +method-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct instance attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct list comprehension / +# generator expression variable names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Regular expression which should only match functions or classes name which do +# not require a docstring +no-docstring-rgx=__.*__ + + +[MISCELLANEOUS] +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[VARIABLES] +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the beginning of the name of dummy variables +# (i.e. not used). +dummy-variables-rgx=_|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + + +[IMPORTS] +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,string,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + + +[DESIGN] +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + + +[CLASSES] +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + + +[EXCEPTIONS] +# Exceptions that will emit a warning when caught. +overgeneral-exceptions=builtins.BaseException,builtins.Exception + diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/requirements.txt b/python3-k8sapp-cstate-management/k8sapp_cstate_management/requirements.txt new file mode 100644 index 0000000..4cdf135 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/requirements.txt @@ -0,0 +1,2 @@ +pbr>=2.0.0 +PyYAML>=3.13 diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.cfg b/python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.cfg new file mode 100644 index 0000000..1a02aa9 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.cfg @@ -0,0 +1,37 @@ +[metadata] +name = k8sapp-cstate-management +summary = StarlingX sysinv extensions for C-state Management +long_description = file: README.rst +long_description_content_type = text/x-rst +license = Apache 2.0 +author = StarlingX +author-email = starlingx-discuss@lists.starlingx.io +home-page = https://www.starlingx.io/ +classifier = + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.9 + +[files] +packages = + k8sapp_cstate_management + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[entry_points] +systemconfig.helm_applications = + cstate-management = systemconfig.helm_plugins.cstate_management + +systemconfig.app_lifecycle = + cstate-management = k8sapp_cstate_management.lifecycle.lifecycle_cstate_management:CStateManagementAppLifecycleOperator + +systemconfig.helm_plugins.cstate_management = + 001_cstate-management = k8sapp_cstate_management.helm.cstate_management:CStateManagementHelm + +[bdist_wheel] +universal = 1 + diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.py b/python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.py new file mode 100644 index 0000000..3a2d179 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/setup.py @@ -0,0 +1,12 @@ +# +# copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +import setuptools + + +setuptools.setup( + setup_requires=['pbr>=2.0.0'], + pbr=True) diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/test-requirements.txt b/python3-k8sapp-cstate-management/k8sapp_cstate_management/test-requirements.txt new file mode 100644 index 0000000..d42863c --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/test-requirements.txt @@ -0,0 +1,22 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +hacking>=1.1.0,<=2.0.0 # Apache-2.0 +astroid +bandit<1.7.2;python_version>="3.0" +coverage>=3.6 +fixtures>=3.0.0 # Apache-2.0/BSD +mock>=2.0.0 # BSD +python-subunit>=0.0.18 +requests-mock>=0.6.0 # Apache-2.0 +sphinx +oslosphinx +oslotest>=3.2.0 # Apache-2.0 +stestr>=1.0.0 # Apache-2.0 +testrepository>=0.0.18 +testtools!=1.2.0,>=0.9.36 +isort<5;python_version>="3.0" +pylint +pycryptodomex +flake8<3.8.0 + diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini b/python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini new file mode 100644 index 0000000..8682b93 --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/tox.ini @@ -0,0 +1,116 @@ +[tox] +envlist = flake8,py39,pylint,bandit,metadata +minversion = 1.6 +skipsdist = True + +# tox does not work if the path to the workdir is too long, so move it to /tmp +toxworkdir = /tmp/{env:USER}_k8sapp_cstate_management_tox +stxdir = {toxinidir}/../../.. +distshare={toxworkdir}/.tox/distshare + +[testenv] +sitepackages = True +basepython = python3.9 + +allowlist_externals = bash + find + echo + +install_command = pip install -v -v -v \ + -c{toxinidir}/upper-constraints.txt \ + -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/starlingx/root/raw/branch/master/build-tools/requirements/debian/upper-constraints.txt} \ + {opts} {packages} + +commands = + find . -type f -name "*.pyc" -delete + +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 + PYTHONDONTWRITEBYTECODE=1 + OS_TEST_PATH=./k8sapp_cstate_management/tests + LANG=en_US.UTF-8 + LANGUAGE=en_US:en + LC_ALL=C + SYSINV_TEST_ENV=True + EVENTS_YAML=./k8sapp_cstate_management/tests/events_for_testing.yaml + TOX_WORK_DIR={toxworkdir} + PYLINTHOME={toxworkdir} + +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt + -e{[tox]stxdir}/config/sysinv/sysinv/sysinv + -e{[tox]stxdir}/config/tsconfig/tsconfig + -e{[tox]stxdir}/fault/fm-api/source + -e{[tox]stxdir}/fault/python-fmclient/fmclient + -e{[tox]stxdir}/utilities/ceph/python-cephclient/python-cephclient + -e{[tox]stxdir}/update/sw-patch/cgcs-patch + +[flake8] +# H series are hacking +# H403 multi line docstrings should end on a new line +# H404 multi line docstring should start without a leading new line +# H405 multi line docstring summary not separated with an empty line +ignore = H403,H404,H405,W503,W504 +exclude = build,dist,tools,.eggs +max-line-length=80 + +[testenv:flake8] +deps = -r{toxinidir}/test-requirements.txt +commands = + flake8 {posargs} . + +[testenv:py39] +commands = + {[testenv]commands} + stestr run {posargs} + stestr slowest + +[testenv:venv] +commands = {posargs} + +[bandit] +# The following bandit tests are being skipped: +# B108: Test for insecure usage of tmp file/directory +# +# Note: 'skips' entry cannot be split across multiple lines +# +skips = B108 +exclude = tests + +[testenv:bandit] +deps = -r{toxinidir}/test-requirements.txt + bandit +commands = bandit --ini tox.ini -n 5 -r k8sapp_cstate_management + +[testenv:pylint] +commands = + pylint {posargs} k8sapp_cstate_management --rcfile=./pylint.rc + +[testenv:cover] +setenv = {[testenv]setenv} + PYTHON=coverage run --parallel-mode +commands = + {[testenv]commands} + coverage erase + stestr run {posargs} + coverage combine + coverage html -d cover + coverage xml -o cover/coverage.xml + coverage report + +[testenv:pip-missing-reqs] +# do not install test-requirements as that will pollute the virtualenv for +# determining missing packages +# this also means that pip-missing-reqs must be installed separately, outside +# of the requirements.txt files +deps = pip_missing_reqs + -rrequirements.txt +commands=pip-missing-reqs -d --ignore-file=/k8sapp_cstate_management/tests k8sapp_cstate_management + +[testenv:metadata] +install_command = pip install -v -v -v \ + -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/starlingx/root/raw/branch/master/build-tools/requirements/debian/upper-constraints.txt} \ + {opts} {packages} +# Pass top level app folder to 'sysinv-app tox' command. +commands = + bash -c "echo $(dirname $(dirname $(pwd))) | xargs -n 1 sysinv-app tox" \ No newline at end of file diff --git a/python3-k8sapp-cstate-management/k8sapp_cstate_management/upper-constraints.txt b/python3-k8sapp-cstate-management/k8sapp_cstate_management/upper-constraints.txt new file mode 100644 index 0000000..beb5a6f --- /dev/null +++ b/python3-k8sapp-cstate-management/k8sapp_cstate_management/upper-constraints.txt @@ -0,0 +1,2 @@ + +# Override upstream constraints based on StarlingX load diff --git a/stx-cstate-management/debian/deb_folder/changelog b/stx-cstate-management/debian/deb_folder/changelog new file mode 100644 index 0000000..b35ee31 --- /dev/null +++ b/stx-cstate-management/debian/deb_folder/changelog @@ -0,0 +1,5 @@ +stx-cstate-management (0.1-0) unstable; urgency=medium + + * Initial Release. + + -- Guilherme Santos Tue, 30 Apr 2024 15:29:00 +0000 diff --git a/stx-cstate-management/debian/deb_folder/control b/stx-cstate-management/debian/deb_folder/control new file mode 100644 index 0000000..9c04e14 --- /dev/null +++ b/stx-cstate-management/debian/deb_folder/control @@ -0,0 +1,17 @@ +Source: stx-cstate-management +Section: libs +Priority: optional +Maintainer: StarlingX Developers +Build-Depends: debhelper-compat (= 13), + build-info, + cstate-management-helm, + python3-k8sapp-cstate-management-wheels, +Standards-Version: 4.5.1 +Homepage: https://www.starlingx.io + +Package: stx-cstate-management +Section: libs +Architecture: any +Depends: ${misc:Depends} +Description: StarlingX C-state Management application + This package contains the STX C-state Management application. diff --git a/stx-cstate-management/debian/deb_folder/copyright b/stx-cstate-management/debian/deb_folder/copyright new file mode 100644 index 0000000..8ebfb16 --- /dev/null +++ b/stx-cstate-management/debian/deb_folder/copyright @@ -0,0 +1,41 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: stx-cstate-management +Source: https://opendev.org/starlingx/app-cstate-management/ + +Files: * +Copyright: (c) 2024 Wind River Systems, Inc +License: Apache-2 + 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 + . + https://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. + . + On Debian-based systems the full text of the Apache version 2.0 license + can be found in `/usr/share/common-licenses/Apache-2.0'. + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: debian/* +Copyright: 2024 Wind River Systems, Inc +License: Apache-2 + 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 + . + https://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. + . + On Debian-based systems the full text of the Apache version 2.0 license + can be found in `/usr/share/common-licenses/Apache-2.0'. diff --git a/stx-cstate-management/debian/deb_folder/rules b/stx-cstate-management/debian/deb_folder/rules new file mode 100644 index 0000000..22ae336 --- /dev/null +++ b/stx-cstate-management/debian/deb_folder/rules @@ -0,0 +1,63 @@ +#!/usr/bin/make -f +# export DH_VERBOSE = 1 + +export ROOT = debian/tmp +export APP_FOLDER = $(ROOT)/usr/local/share/applications/helm + +export DEB_VERSION = $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ') +export RELEASE = $(shell cat /etc/build.info | grep SW_VERSION | cut -d'"' -f2) +export REVISION = $(shell echo $(DEB_VERSION) | cut -f 4 -d '.') + +export APP_NAME = cstate-management +export APP_VERSION = $(RELEASE)-$(REVISION) +export APP_TARBALL = $(APP_NAME)-$(APP_VERSION).tgz +export HELM_REPO = stx-platform +export STAGING = staging + +%: + dh $@ + +override_dh_auto_build: + # Setup the staging directory. + mkdir -p $(STAGING) + cp files/metadata.yaml $(STAGING) + cp -R fluxcd-manifests $(STAGING) + mkdir -p $(STAGING)/charts + cp /usr/lib/helm/cstate-management*.tgz $(STAGING)/charts + + # Adjust the helmrelease yamls based on the chart versions + for c in $(STAGING)/charts/*; do \ + chart=$$(basename $$c .tgz); \ + chart_name=$${chart%-*}; \ + chart_version=$${chart##*-}; \ + echo "Found $$chart; name: $$chart_name, version: $$chart_version"; \ + chart_manifest=$$(find $(STAGING)/fluxcd-manifests/$$chart_name -name helmrelease.yaml -exec grep -q $$chart_name {} \; -print); \ + echo "Updating manifest: $$chart_manifest"; \ + sed -i "s/REPLACE_HELM_CHART_VERSION/$$chart_version/g" $$chart_manifest; \ + grep version $$chart_manifest; \ + done + + # Populate metadata + sed -i 's/APP_REPLACE_NAME/$(APP_NAME)/g' $(STAGING)/metadata.yaml + sed -i 's/APP_REPLACE_VERSION/$(APP_VERSION)/g' $(STAGING)/metadata.yaml + sed -i 's/HELM_REPLACE_REPO/$(HELM_REPO)/g' $(STAGING)/metadata.yaml + + # Copy the plugins: installed in the buildroot + mkdir -p $(STAGING)/plugins + cp /plugins/*.whl $(STAGING)/plugins + + # Create the app package. + cd $(STAGING) && find . -type f ! -name '*.md5' -print0 | xargs -0 md5sum > checksum.md5 + tar cfz $(APP_TARBALL) -C $(STAGING)/ . + + # Cleanup staging + rm -rf $(STAGING) + +override_dh_auto_install: + # Install the app tar file. + install -d -m 755 $(APP_FOLDER) + install -p -D -m 755 $(APP_TARBALL) $(APP_FOLDER) + +override_dh_auto_test: + +override_dh_usrlocal: diff --git a/stx-cstate-management/debian/deb_folder/source/format b/stx-cstate-management/debian/deb_folder/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/stx-cstate-management/debian/deb_folder/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/stx-cstate-management/debian/deb_folder/stx-cstate-management.install b/stx-cstate-management/debian/deb_folder/stx-cstate-management.install new file mode 100644 index 0000000..c86aa47 --- /dev/null +++ b/stx-cstate-management/debian/deb_folder/stx-cstate-management.install @@ -0,0 +1 @@ +usr/local/share/applications/helm/* \ No newline at end of file diff --git a/stx-cstate-management/debian/meta_data.yaml b/stx-cstate-management/debian/meta_data.yaml new file mode 100644 index 0000000..39a944a --- /dev/null +++ b/stx-cstate-management/debian/meta_data.yaml @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +debname: stx-cstate-management +debver: 0.1-0 +src_path: stx-cstate-management +revision: + dist: $STX_DIST + GITREVCOUNT: + SRC_DIR: ${MY_REPO}/stx/app-cstate-management + BASE_SRCREV: dae78a8cccdfc11f34d195daf7d05b4c8c022b71 \ No newline at end of file diff --git a/stx-cstate-management/stx-cstate-management/files/metadata.yaml b/stx-cstate-management/stx-cstate-management/files/metadata.yaml new file mode 100644 index 0000000..6283ab3 --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/files/metadata.yaml @@ -0,0 +1,24 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +app_name: APP_REPLACE_NAME +app_version: APP_REPLACE_VERSION +helm_repo: HELM_REPLACE_REPO + +maintain_user_overrides: true + +upgrades: + auto_update: true + +supported_k8s_version: + minimum: 1.24.4 + +behavior: + platform_managed_app: yes + evaluate_reapply: + triggers: + - type: host-modify + - type: host-delete + diff --git a/stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/helmrepository.yaml b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/helmrepository.yaml new file mode 100644 index 0000000..55e99cb --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/helmrepository.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: source.toolkit.fluxcd.io/v1beta1 +kind: HelmRepository +metadata: + name: stx-platform +spec: + url: http://192.168.206.1:8080/helm_charts/stx-platform + interval: 1m diff --git a/stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/kustomization.yaml b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/kustomization.yaml new file mode 100644 index 0000000..0c2150f --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/base/kustomization.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - helmrepository.yaml diff --git a/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-static-overrides.yaml b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-static-overrides.yaml new file mode 100644 index 0000000..a91c476 --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-static-overrides.yaml @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- \ No newline at end of file diff --git a/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-system-overrides.yaml b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-system-overrides.yaml new file mode 100644 index 0000000..535f645 --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/cstate-management-system-overrides.yaml @@ -0,0 +1,5 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- diff --git a/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/helmrelease.yaml b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/helmrelease.yaml new file mode 100644 index 0000000..d55f49d --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/helmrelease.yaml @@ -0,0 +1,36 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: helm.toolkit.fluxcd.io/v2beta1 +kind: HelmRelease + +metadata: + name: cstate-management + labels: + chart_group: cstate-management-charts +spec: + releaseName: cstate-management + chart: + spec: + chart: cstate-management + version: REPLACE_HELM_CHART_VERSION + sourceRef: + kind: HelmRepository + name: stx-platform + interval: 1m + timeout: 30m + test: + enable: false + install: + disableHooks: false + upgrade: + disableHooks: false + valuesFrom: + - kind: Secret + name: cstate-management-static-overrides + valuesKey: cstate-management-static-overrides.yaml + - kind: Secret + name: cstate-management-system-overrides + valuesKey: cstate-management-system-overrides.yaml diff --git a/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/kustomization.yaml b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/kustomization.yaml new file mode 100644 index 0000000..209468c --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/cstate-management/kustomization.yaml @@ -0,0 +1,19 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: cstate-management +resources: + - helmrelease.yaml +secretGenerator: + - name: cstate-management-system-overrides + files: + - cstate-management-system-overrides.yaml + - name: cstate-management-static-overrides + files: + - cstate-management-static-overrides.yaml +generatorOptions: + disableNameSuffixHash: true diff --git a/stx-cstate-management/stx-cstate-management/fluxcd-manifests/kustomization.yaml b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/kustomization.yaml new file mode 100644 index 0000000..b7df795 --- /dev/null +++ b/stx-cstate-management/stx-cstate-management/fluxcd-manifests/kustomization.yaml @@ -0,0 +1,11 @@ +# Copyright (c) 2024 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: cstate-management +resources: + - base + - cstate-management