From 0721eac74394d765e479c7d3c4d7940ee1e4c543 Mon Sep 17 00:00:00 2001 From: Stacky McStackface Date: Tue, 18 Jan 2022 15:51:07 +0000 Subject: [PATCH 1/2] Generated commit to update templated files based on rev 03fbccc in stackabletech/operator-templating repo. Original commit message: Various changes (#53) - YAML formatting (yamllint) - Pylint - Pull Requests to separate Helm Repo (helm-test) - Rustdoc will now error on warnings - Enable bors squash merge again - Enable helm chart testing and linting --- .github/dependabot.yml | 1 + .github/workflows/daily_security.yml | 3 +- .github/workflows/helm_tests.yml | 52 +++++ .github/workflows/publish_main_artifacts.yml | 14 +- .github/workflows/publish_pr_artifacts.yml | 15 +- .../workflows/publish_release_artifacts.yml | 13 +- .github/workflows/rust.yml | 13 +- .gitignore | 2 - .pylintrc | 9 + .yamllint.yaml | 10 + bors.toml | 3 +- deploy/DO_NOT_EDIT.md | 4 + deploy/helm/chart_testing.yaml | 5 - deploy/helm/ct.yaml | 8 + deploy/helm/hdfs-operator/Chart.yaml | 33 +--- deploy/helm/hdfs-operator/README.md | 17 +- .../hdfs-operator/templates/configmap.yaml | 5 +- .../hdfs-operator/templates/deployment.yaml | 5 +- .../helm/hdfs-operator/templates/roles.yaml | 3 +- .../templates/serviceaccount.yaml | 7 +- deploy/helm/hdfs-operator/values.yaml | 8 +- deploy/manifests/Kustomization | 5 +- python/cargo-version.py | 177 ----------------- python/cargo_version.py | 179 ++++++++++++++++++ 24 files changed, 317 insertions(+), 274 deletions(-) create mode 100644 .github/workflows/helm_tests.yml create mode 100644 .pylintrc create mode 100644 .yamllint.yaml create mode 100644 deploy/DO_NOT_EDIT.md delete mode 100644 deploy/helm/chart_testing.yaml create mode 100644 deploy/helm/ct.yaml delete mode 100755 python/cargo-version.py create mode 100755 python/cargo_version.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 65d54aa7..50eaadb2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,6 +2,7 @@ # This file is automatically generated from the templates in stackabletech/operator-templating # DON'T MANUALLY EDIT THIS FILE # ============= +--- version: 2 updates: - package-ecosystem: "github-actions" diff --git a/.github/workflows/daily_security.yml b/.github/workflows/daily_security.yml index f4627093..850a3f4d 100644 --- a/.github/workflows/daily_security.yml +++ b/.github/workflows/daily_security.yml @@ -2,11 +2,12 @@ # This file is automatically generated from the templates in stackabletech/operator-templating # DON'T MANUALLY EDIT THIS FILE # ============= +--- name: Security audit on: schedule: - - cron: '0 0 * * *' + - cron: '15 4 * * *' workflow_dispatch: jobs: diff --git a/.github/workflows/helm_tests.yml b/.github/workflows/helm_tests.yml new file mode 100644 index 00000000..49f39b45 --- /dev/null +++ b/.github/workflows/helm_tests.yml @@ -0,0 +1,52 @@ +name: Lint and Test Helm Charts + +on: + push: + branches: ["main"] + pull_request: + +env: + CT_CONFIG: deploy/helm/ct.yaml + +jobs: + lint-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2.4.0 + with: + fetch-depth: 0 + + - name: Set up Helm + uses: azure/setup-helm@v1 + with: + version: v3.7.2 + + - uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Compile chart + run: make compile-chart + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.2.0 + + - name: Run chart-testing (lint) + run: ct lint --config "${CT_CONFIG}" + + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --config "${CT_CONFIG}") + if [[ -n "$changed" ]]; then + echo "::set-output name=changed::true" + fi + + - name: Create kind cluster + uses: helm/kind-action@v1.2.0 + if: steps.list-changed.outputs.changed == 'true' + + - name: Run chart-testing (install) + run: ct install --config "${CT_CONFIG}" + if: steps.list-changed.outputs.changed == 'true' diff --git a/.github/workflows/publish_main_artifacts.yml b/.github/workflows/publish_main_artifacts.yml index 76211709..fb55a60d 100644 --- a/.github/workflows/publish_main_artifacts.yml +++ b/.github/workflows/publish_main_artifacts.yml @@ -2,7 +2,8 @@ # This file is automatically generated from the templates in stackabletech/operator-templating # DON'T MANUALLY EDIT THIS FILE # ============= -name: Publish nightly artifacts from main +--- +name: Publish nightly artifacts from main branch on: push: @@ -11,15 +12,14 @@ on: schedule: - cron: '30 4 * * *' workflow_dispatch: - env: PRODUCT_NAME: hdfs CARGO_TERM_COLOR: always CARGO_INCREMENTAL: '0' CARGO_PROFILE_DEV_DEBUG: '0' - RUSTFLAGS: "-D warnings -W rust-2021-compatibility" - REPO_HELM_DEV_URL: https://repo.stackable.tech/repository/helm-dev + RUSTFLAGS: "-D warnings" + REPO_HELM_URL: https://repo.stackable.tech/repository/helm-dev CHART_TESTING_CONFIG: deploy/helm/chart-testing.yaml jobs: @@ -47,6 +47,7 @@ jobs: - name: Package Chart run: mkdir -p target/helm && helm package --destination target/helm deploy/helm/${{ env.PRODUCT_NAME }}-operator + - name: Publish Chart env: NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} @@ -55,6 +56,5 @@ jobs: /usr/bin/curl --fail -u 'github:${{ secrets.NEXUS_PASSWORD }}' - --upload-file "./$(find target/helm/ -name *.tgz)" - "${{ env.REPO_HELM_DEV_URL }}/" - + --upload-file "./$(find target/helm/ -name '*.tgz')" + "${{ env.REPO_HELM_URL }}/" diff --git a/.github/workflows/publish_pr_artifacts.yml b/.github/workflows/publish_pr_artifacts.yml index 02209346..f06b3b9d 100644 --- a/.github/workflows/publish_pr_artifacts.yml +++ b/.github/workflows/publish_pr_artifacts.yml @@ -2,7 +2,8 @@ # This file is automatically generated from the templates in stackabletech/operator-templating # DON'T MANUALLY EDIT THIS FILE # ============= -name: Publish pull-requests artifacts to the dev repository +--- +name: Publish pull-request artifacts on: pull_request: @@ -12,8 +13,8 @@ env: CARGO_TERM_COLOR: always CARGO_INCREMENTAL: '0' CARGO_PROFILE_DEV_DEBUG: '0' - RUSTFLAGS: "-D warnings -W rust-2021-compatibility" - REPO_HELM_DEV_URL: https://repo.stackable.tech/repository/helm-dev + RUSTFLAGS: "-D warnings" + REPO_HELM_URL: https://repo.stackable.tech/repository/helm-test CHART_TESTING_CONFIG: deploy/helm/chart-testing.yaml jobs: @@ -36,7 +37,7 @@ jobs: python-version: '3.x' - run: pip install -r ./python/requirements.txt - - run: python ./python/cargo-version.py -m mr${{ github.event.number }} + - run: python ./python/cargo_version.py -m pr${{ github.event.number }} - name: Build Docker image env: @@ -49,6 +50,7 @@ jobs: - name: Package Chart run: mkdir -p target/helm && helm package --destination target/helm deploy/helm/${{ env.PRODUCT_NAME }}-operator + - name: Publish Chart env: NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} @@ -57,6 +59,5 @@ jobs: /usr/bin/curl --fail -u 'github:${{ secrets.NEXUS_PASSWORD }}' - --upload-file "./$(find target/helm/ -name *.tgz)" - "${{ env.REPO_HELM_DEV_URL }}/" - + --upload-file "./$(find target/helm/ -name '*.tgz')" + "${{ env.REPO_HELM_URL }}/" diff --git a/.github/workflows/publish_release_artifacts.yml b/.github/workflows/publish_release_artifacts.yml index 94fb6d99..3cd80f10 100644 --- a/.github/workflows/publish_release_artifacts.yml +++ b/.github/workflows/publish_release_artifacts.yml @@ -2,7 +2,8 @@ # This file is automatically generated from the templates in stackabletech/operator-templating # DON'T MANUALLY EDIT THIS FILE # ============= -name: Publish-Release-Artifacts +--- +name: Publish release artifacts on: push: @@ -14,9 +15,9 @@ env: CARGO_TERM_COLOR: always CARGO_INCREMENTAL: '0' CARGO_PROFILE_DEV_DEBUG: '0' - RUSTFLAGS: "-D warnings -W rust-2021-compatibility" - REPO_HELM_STABLE_URL: https://repo.stackable.tech/repository/helm-stable - CT_CONFIG: deploy/helm/ct.yaml + RUSTFLAGS: "-D warnings" + REPO_HELM_URL: https://repo.stackable.tech/repository/helm-stable + CHART_TESTING_CONFIG: deploy/helm/chart-testing.yaml jobs: helm: @@ -52,5 +53,5 @@ jobs: /usr/bin/curl --fail -u 'github:${{ secrets.NEXUS_PASSWORD }}' - --upload-file "./$(find target/helm/ -name *.tgz)" - "${{ env.REPO_HELM_STABLE_URL }}/" + --upload-file "./$(find target/helm/ -name '*.tgz')" + "${{ env.REPO_HELM_URL }}/" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 08f620c9..e7333134 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,7 +2,8 @@ # This file is automatically generated from the templates in stackabletech/operator-templating # DON'T MANUALLY EDIT THIS FILE # ============= -name: Rust +--- +name: Rust checks on: push: @@ -17,6 +18,8 @@ env: CARGO_INCREMENTAL: '0' CARGO_PROFILE_DEV_DEBUG: '0' RUSTFLAGS: "-D warnings" + RUSTDOCFLAGS: "-D warnings" + RUST_LOG: "info" jobs: @@ -79,10 +82,10 @@ jobs: - uses: actions/checkout@v2.4.0 - uses: actions-rs/toolchain@v1.0.7 with: - profile: minimal - toolchain: stable - components: clippy - override: true + profile: minimal + toolchain: stable + components: clippy + override: true - uses: Swatinem/rust-cache@v1.3.0 with: key: clippy diff --git a/.gitignore b/.gitignore index 17829b09..891289d9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,3 @@ target/ *.iml *.tgz -deploy/helm/hdfs-operator/configs -deploy/helm/hdfs-operator/templates/crds.yaml \ No newline at end of file diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..5df27e82 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,9 @@ +[MESSAGES CONTROL] + +# These rules are for missing docstrings which doesn't matter much for most of our simple scripts +disable=C0114,C0115,C0116 + +[FORMAT] + +max-line-length=999 +indent-string=' ' diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 00000000..91a7fec6 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,10 @@ +--- +extends: default + +ignore: | + deploy/helm/**/templates + +rules: + line-length: disable + truthy: + check-keys: false diff --git a/bors.toml b/bors.toml index d9c6dd48..4f305075 100644 --- a/bors.toml +++ b/bors.toml @@ -6,6 +6,7 @@ status = [ 'Run cargo deny (bans licenses sources)' ] delete_merged_branches = true +use_squash_merge = true pr_status = [ 'license/cla' ] timeout_sec = 7200 -cut_body_after = "" \ No newline at end of file +cut_body_after = "" diff --git a/deploy/DO_NOT_EDIT.md b/deploy/DO_NOT_EDIT.md new file mode 100644 index 00000000..da37bf18 --- /dev/null +++ b/deploy/DO_NOT_EDIT.md @@ -0,0 +1,4 @@ +These Helm charts and manifests are automatically generated. +Please do not edit anything in this directory manually. + +The details are in-motion but check this repository for a few details: https://github.com/stackabletech/operator-templating diff --git a/deploy/helm/chart_testing.yaml b/deploy/helm/chart_testing.yaml deleted file mode 100644 index 82b39c26..00000000 --- a/deploy/helm/chart_testing.yaml +++ /dev/null @@ -1,5 +0,0 @@ -remote: origin -target-branch: main -chart-dirs: - - deploy/helm -all: true diff --git a/deploy/helm/ct.yaml b/deploy/helm/ct.yaml new file mode 100644 index 00000000..fbef6924 --- /dev/null +++ b/deploy/helm/ct.yaml @@ -0,0 +1,8 @@ +# This file is used for chart-testing (https://github.com/helm/chart-testing) +# The name "ct.yaml" is not very self-descriptive but it is the default that chart-testing is looking for +--- +remote: origin +target-branch: main +chart-dirs: + - deploy/helm +all: true diff --git a/deploy/helm/hdfs-operator/Chart.yaml b/deploy/helm/hdfs-operator/Chart.yaml index e69d6afe..250352da 100644 --- a/deploy/helm/hdfs-operator/Chart.yaml +++ b/deploy/helm/hdfs-operator/Chart.yaml @@ -1,28 +1,11 @@ -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= +--- apiVersion: v2 name: hdfs-operator -description: The Stackable Operator for Apache HDFS -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application +version: +appVersion: "" + +home: https://github.com/stackabletech/hdfs-operator + maintainers: - - name: stackable - url: github.com/stackabletech -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -# Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.3.0-nightly -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. Versions are not expected to -# follow Semantic Versioning. They should reflect the version the application is using. -# It is recommended to use it with quotes. -appVersion: 0.3.0-nightly + - name: Stackable + url: https://www.stackable.tech diff --git a/deploy/helm/hdfs-operator/README.md b/deploy/helm/hdfs-operator/README.md index 2e778b12..21a15cba 100644 --- a/deploy/helm/hdfs-operator/README.md +++ b/deploy/helm/hdfs-operator/README.md @@ -1,8 +1,3 @@ -[//]: # (=============) -[//]: # (This file is automatically generated from the templates in stackabletech/operator-templating) -[//]: # (DON'T MANUALLY EDIT THIS FILE) -[//]: # (=============) - # Helm Chart for Stackable Operator for Apache HDFS This Helm Chart can be used to install Custom Resource Definitions and the Operator for Apache HDFS provided by Stackable. @@ -14,7 +9,7 @@ This Helm Chart can be used to install Custom Resource Definitions and the Opera - Install [Helm](https://helm.sh/docs/intro/install/) -## Install the Stackble Operator for Apache HDFS +## Install the Stackable Operator for Apache HDFS ```bash # From the root of the operator repository @@ -24,15 +19,11 @@ helm install hdfs-operator deploy/helm/hdfs-operator ``` +## Usage of the CRDs +The usage of this operator and its CRDs is described in the [documentation](https://docs.stackable.tech/hdfs/index.html) -## Create a Apache HDFS Cluster - -as described [here](https://docs.stackable.tech/hdfs/index.html) - - - -The operator has example requests included in the [`/examples`](https://github.com/stackabletech/hdfs/operator/tree/main/examples) directory that can be used to spin up a cluster. +The operator has example requests included in the [`/examples`](https://github.com/stackabletech/hdfs/operator/tree/main/examples) directory. ## Links diff --git a/deploy/helm/hdfs-operator/templates/configmap.yaml b/deploy/helm/hdfs-operator/templates/configmap.yaml index 8b85c759..7fa8613d 100644 --- a/deploy/helm/hdfs-operator/templates/configmap.yaml +++ b/deploy/helm/hdfs-operator/templates/configmap.yaml @@ -1,7 +1,4 @@ -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= +--- apiVersion: v1 data: {{ (.Files.Glob "configs/*").AsConfig | indent 2 }} diff --git a/deploy/helm/hdfs-operator/templates/deployment.yaml b/deploy/helm/hdfs-operator/templates/deployment.yaml index ff825661..90a210d5 100644 --- a/deploy/helm/hdfs-operator/templates/deployment.yaml +++ b/deploy/helm/hdfs-operator/templates/deployment.yaml @@ -1,7 +1,4 @@ -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= +--- apiVersion: apps/v1 kind: Deployment metadata: diff --git a/deploy/helm/hdfs-operator/templates/roles.yaml b/deploy/helm/hdfs-operator/templates/roles.yaml index a2f8a0d9..eecbdc59 100644 --- a/deploy/helm/hdfs-operator/templates/roles.yaml +++ b/deploy/helm/hdfs-operator/templates/roles.yaml @@ -1,3 +1,4 @@ +--- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: @@ -29,7 +30,7 @@ rules: - apiGroups: - rbac.authorization.k8s.io resources: - - rolebinding + - rolebindings verbs: - create - delete diff --git a/deploy/helm/hdfs-operator/templates/serviceaccount.yaml b/deploy/helm/hdfs-operator/templates/serviceaccount.yaml index fbd8b454..ff2b7f8e 100644 --- a/deploy/helm/hdfs-operator/templates/serviceaccount.yaml +++ b/deploy/helm/hdfs-operator/templates/serviceaccount.yaml @@ -1,7 +1,4 @@ -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= +--- {{ if .Values.serviceAccount.create -}} apiVersion: v1 kind: ServiceAccount @@ -29,4 +26,4 @@ roleRef: kind: ClusterRole name: {{ .Release.Name }}-clusterrole apiGroup: rbac.authorization.k8s.io -{{- end }} \ No newline at end of file +{{- end }} diff --git a/deploy/helm/hdfs-operator/values.yaml b/deploy/helm/hdfs-operator/values.yaml index 2be3efeb..58af189e 100644 --- a/deploy/helm/hdfs-operator/values.yaml +++ b/deploy/helm/hdfs-operator/values.yaml @@ -1,11 +1,5 @@ -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= - # Default values for hdfs-operator. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. +--- image: repository: docker.stackable.tech/stackable/hdfs-operator pullPolicy: IfNotPresent diff --git a/deploy/manifests/Kustomization b/deploy/manifests/Kustomization index 336cdb27..0e1ce898 100644 --- a/deploy/manifests/Kustomization +++ b/deploy/manifests/Kustomization @@ -1,7 +1,4 @@ -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= +--- apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: diff --git a/python/cargo-version.py b/python/cargo-version.py deleted file mode 100755 index 474240dd..00000000 --- a/python/cargo-version.py +++ /dev/null @@ -1,177 +0,0 @@ -#!/usr/bin/env python3 -# -# Utility for viewing and managing versions of cargo workspaces and crates. -# For workspaces, it assumes that all crate members use a single shared version. -# -# usage: cargo-version.py [-h] [-p PROJECT] [-r] [-n {major,minor,patch}] [-s SET] [-o] -# -# Change versions of cargo projects. -# -# optional arguments: -# -h, --help show this help message and exit -# -p PROJECT, --project PROJECT -# Project folder -# -r, --release Version -# -n {major,minor,patch}, --next {major,minor,patch} -# Version -# -s SET, --set SET Version -# -o, --show Version -# - -import toml -import semver -import argparse - -class Crate: - def __init__(self, path, name, version, dependencies): - self.path = path - self.name = name - self.version = version - self.dependencies = dependencies - - def with_dependencies(self, names): - deps = {k:v for k,v in self.dependencies.items() if k in names} - return Crate(self.path, self.name, self.version, deps) - - @classmethod - def finalize(cls, version): - return str(semver.VersionInfo.parse(version).finalize_version()) - - @classmethod - def bump_level(cls, version, level): - v = semver.VersionInfo.parse(version) - if level == 'major': - return str(v.bump_major()) - elif level == 'minor': - return str(v.bump_minor()) - elif level == 'patch': - return str(v.bump_patch()) - else: - return str(v.bump_prerelease('nightly'))[:-2] ### remove the .1 suffix that semver always adds to the prererelease. - - @classmethod - def prerelease(cls, version, prerelease): - v = semver.VersionInfo.parse(version) - return str(semver.VersionInfo(v.major, v.minor, v.patch, prerelease)) - - def finalize_version(self): - return Crate(self.path, self.name, Crate.finalize(self.version), self.dependencies.copy()) - - def bump_version(self, level): - return Crate(self.path, self.name, Crate.bump_level(self.version, level), self.dependencies.copy()) - - def set_version(self, version): - return Crate(self.path, self.name, version, self.dependencies.copy()) - - def set_prerelease(self, prerelease): - return Crate(self.path, self.name, Crate.prerelease(self.version, prerelease), self.dependencies.copy()) - - def next_version(self): - return Crate(self.path, self.name, str(semver.VersionInfo.parse(self.version).next_version('patch')), self.dependencies.copy()) - - def show_version(self): - return self.version - - def save(self, previous): - contents = [] - cargo_file = f"{self.path}/Cargo.toml" - with open(cargo_file, 'r') as r: - for line in r.readlines(): - if line.startswith("version"): - line = line.replace(previous.version, self.version) - else: - for dname, dversion in self.dependencies.items(): - if line.startswith(dname): - line = line.replace(previous.dependencies[dname], dversion) - contents.append(line) - - with open(cargo_file, 'w') as w: - w.write(''.join(contents)) - - def __str__(self): - return f'Crate({self.path}, {self.name}, {self.version}, {self.dependencies})' - -class Workspace: - def __init__(self, crates): - names = set([c.name for c in crates]) - self.crates = {c.name: c.with_dependencies(names) for c in crates} - - def finalize_version(self): - crates = {c.name: c.finalize_version() for c in self.crates.values()} - return Workspace(Workspace.update_dependencies(crates).values()) - - def bump_version(self, level): - crates = {c.name: c.bump_version(level) for c in self.crates.values()} - return Workspace(Workspace.update_dependencies(crates).values()) - - def set_version(self, version): - crates = {c.name: c.set_version(version) for c in self.crates.values()} - return Workspace(Workspace.update_dependencies(crates).values()) - - def set_prerelease(self, prerelease): - crates = {c.name: c.set_prerelease(prerelease) for c in self.crates.values()} - return Workspace(Workspace.update_dependencies(crates).values()) - - def next_version(self): - crates = {c.name: c.next_version() for c in self.crates.values()} - return Workspace(Workspace.update_dependencies(crates).values()) - - def show_version(self): - for c in self.crates.values(): - return c.show_version() - return "0.0.0" - - @classmethod - def update_dependencies(cls, crate_dict): - for crate in crate_dict.values(): - for dep in crate.dependencies.keys(): - crate.dependencies[dep] = crate_dict[dep].version - return crate_dict - - def __str__(self): - return f'Workspace({[str(c) for c in self.crates.values()]})' - - def save(self, previous): - for cn in self.crates.keys(): - self.crates[cn].save(previous.crates[cn]) - -def load(root): - r = toml.load(f"{root}/Cargo.toml") - if "workspace" in r: - return Workspace([load(f"{root}/{path}") for path in r["workspace"]["members"]]) - else: - return Crate(path=root, name=r["package"]["name"], version=r["package"]["version"], dependencies={dn: r["dependencies"][dn]["version"] for dn in r["dependencies"] if "version" in r["dependencies"][dn]}) - -def parse_args(): - parser = argparse.ArgumentParser(description="Change versions of cargo projects.") - parser.add_argument("-p", "--project", help="Project folder", default=".") - parser.add_argument("-r", "--release", help="Version", action="store_true") - parser.add_argument("-n", "--next", help="Version", choices=['major', 'minor', 'patch']) - parser.add_argument("-s", "--set", help="Version" ) - parser.add_argument("-o", "--show", help="Version", action="store_true") - parser.add_argument("-m", "--prerelease", help="Set pre-prelease string." ) - return parser.parse_args() - -if __name__ == "__main__": - args = parse_args() - - old = load(args.project.rstrip('/')) - - if args.release: - new = old.finalize_version() - new.save(old) - elif args.next: - new = old.bump_version(args.next).bump_version("prerelease") - new.save(old) - elif args.set: - # sanity check - semver.VersionInfo.parse(args.set) - new = old.set_version(args.set) - new.save(old) - elif args.prerelease: - new = old.set_prerelease(args.prerelease) - new.save(old) - elif args.show: - print(old.show_version()) - - diff --git a/python/cargo_version.py b/python/cargo_version.py new file mode 100755 index 00000000..c783ce58 --- /dev/null +++ b/python/cargo_version.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python3 +# +# Utility for viewing and managing versions of cargo workspaces and crates. +# For workspaces, it assumes that all crate members use a single shared version. +# +# usage: cargo_version.py [-h] [-p PROJECT] [-r] [-n {major,minor,patch}] [-s SET] [-o] +# +# Change versions of cargo projects. +# +# optional arguments: +# -h, --help show this help message and exit +# -p PROJECT, --project PROJECT +# Project folder +# -r, --release Version +# -n {major,minor,patch}, --next {major,minor,patch} +# Version +# -s SET, --set SET Version +# -o, --show Version + +import argparse +import semver +import toml + + +class Crate: + def __init__(self, path, name, version, dependencies): + self.path = path + self.name = name + self.version = version + self.dependencies = dependencies + + def with_dependencies(self, names): + deps = {k: v for k, v in self.dependencies.items() if k in names} + return Crate(self.path, self.name, self.version, deps) + + @classmethod + def finalize(cls, version): + return str(semver.VersionInfo.parse(version).finalize_version()) + + @classmethod + def bump_level(cls, version, level): + v = semver.VersionInfo.parse(version) + if level == 'major': + return str(v.bump_major()) + if level == 'minor': + return str(v.bump_minor()) + if level == 'patch': + return str(v.bump_patch()) + else: + return str(v.bump_prerelease('nightly'))[:-2] ### remove the .1 suffix that semver always adds to the prererelease. + + @classmethod + def prerelease(cls, version, prerelease): + v = semver.VersionInfo.parse(version) + return str(semver.VersionInfo(v.major, v.minor, v.patch, prerelease)) + + def finalize_version(self): + return Crate(self.path, self.name, Crate.finalize(self.version), self.dependencies.copy()) + + def bump_version(self, level): + return Crate(self.path, self.name, Crate.bump_level(self.version, level), self.dependencies.copy()) + + def set_version(self, version): + return Crate(self.path, self.name, version, self.dependencies.copy()) + + def set_prerelease(self, prerelease): + return Crate(self.path, self.name, Crate.prerelease(self.version, prerelease), self.dependencies.copy()) + + def next_version(self): + return Crate(self.path, self.name, str(semver.VersionInfo.parse(self.version).next_version('patch')), self.dependencies.copy()) + + def show_version(self): + return self.version + + def save(self, previous): + contents = [] + cargo_file = f"{self.path}/Cargo.toml" + with open(cargo_file, 'r') as r: + for line in r.readlines(): + if line.startswith("version"): + line = line.replace(previous.version, self.version) + else: + for dname, dversion in self.dependencies.items(): + if line.startswith(dname): + line = line.replace(previous.dependencies[dname], dversion) + contents.append(line) + + with open(cargo_file, 'w') as w: + w.write(''.join(contents)) + + def __str__(self): + return f'Crate({self.path}, {self.name}, {self.version}, {self.dependencies})' + + +class Workspace: + def __init__(self, crates): + names = set([c.name for c in crates]) + self.crates = {c.name: c.with_dependencies(names) for c in crates} + + def finalize_version(self): + crates = {c.name: c.finalize_version() for c in self.crates.values()} + return Workspace(Workspace.update_dependencies(crates).values()) + + def bump_version(self, level): + crates = {c.name: c.bump_version(level) for c in self.crates.values()} + return Workspace(Workspace.update_dependencies(crates).values()) + + def set_version(self, version): + crates = {c.name: c.set_version(version) for c in self.crates.values()} + return Workspace(Workspace.update_dependencies(crates).values()) + + def set_prerelease(self, prerelease): + crates = {c.name: c.set_prerelease(prerelease) for c in self.crates.values()} + return Workspace(Workspace.update_dependencies(crates).values()) + + def next_version(self): + crates = {c.name: c.next_version() for c in self.crates.values()} + return Workspace(Workspace.update_dependencies(crates).values()) + + def show_version(self): + for c in self.crates.values(): + return c.show_version() + return "0.0.0" + + @classmethod + def update_dependencies(cls, crate_dict): + for crate in crate_dict.values(): + for dep in crate.dependencies.keys(): + crate.dependencies[dep] = crate_dict[dep].version + return crate_dict + + def __str__(self): + return f'Workspace({[str(c) for c in self.crates.values()]})' + + def save(self, previous): + for cn in self.crates.keys(): + self.crates[cn].save(previous.crates[cn]) + + +def load(root): + r = toml.load(f"{root}/Cargo.toml") + if "workspace" in r: + return Workspace([load(f"{root}/{path}") for path in r["workspace"]["members"]]) + + return Crate(path=root, name=r["package"]["name"], version=r["package"]["version"], dependencies={dn: r["dependencies"][dn]["version"] for dn in r["dependencies"] if "version" in r["dependencies"][dn]}) + + +def parse_args(): + parser = argparse.ArgumentParser(description="Change versions of cargo projects.") + parser.add_argument("-p", "--project", help="Project folder", default=".") + parser.add_argument("-r", "--release", help="Version", action="store_true") + parser.add_argument("-n", "--next", help="Version", choices=['major', 'minor', 'patch']) + parser.add_argument("-s", "--set", help="Version") + parser.add_argument("-o", "--show", help="Version", action="store_true") + parser.add_argument("-m", "--prerelease", help="Set pre-prelease string.") + return parser.parse_args() + + +if __name__ == "__main__": + args = parse_args() + + old = load(args.project.rstrip('/')) + + if args.release: + new = old.finalize_version() + new.save(old) + elif args.next: + new = old.bump_version(args.next).bump_version("prerelease") + new.save(old) + elif args.set: + # sanity check + semver.VersionInfo.parse(args.set) + new = old.set_version(args.set) + new.save(old) + elif args.prerelease: + new = old.set_prerelease(args.prerelease) + new.save(old) + elif args.show: + print(old.show_version()) From 599c323de9512e93e7951ff96e76725243b42ff1 Mon Sep 17 00:00:00 2001 From: Stacky McStackface Date: Tue, 18 Jan 2022 15:59:10 +0000 Subject: [PATCH 2/2] Github Actions: Generated k8s manifest files --- deploy/helm/hdfs-operator/Chart.yaml | 6 ++---- deploy/manifests/configmap.yaml | 4 ---- deploy/manifests/deployment.yaml | 4 ---- deploy/manifests/roles.yaml | 2 +- deploy/manifests/serviceaccount.yaml | 4 ---- 5 files changed, 3 insertions(+), 17 deletions(-) diff --git a/deploy/helm/hdfs-operator/Chart.yaml b/deploy/helm/hdfs-operator/Chart.yaml index 250352da..f256aa30 100644 --- a/deploy/helm/hdfs-operator/Chart.yaml +++ b/deploy/helm/hdfs-operator/Chart.yaml @@ -1,11 +1,9 @@ --- apiVersion: v2 name: hdfs-operator -version: -appVersion: "" - +version: 0.3.0-nightly +appVersion: "0.3.0-nightly" home: https://github.com/stackabletech/hdfs-operator - maintainers: - name: Stackable url: https://www.stackable.tech diff --git a/deploy/manifests/configmap.yaml b/deploy/manifests/configmap.yaml index b6e94897..194e4e9c 100644 --- a/deploy/manifests/configmap.yaml +++ b/deploy/manifests/configmap.yaml @@ -1,8 +1,4 @@ --- -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= apiVersion: v1 data: properties.yaml: | diff --git a/deploy/manifests/deployment.yaml b/deploy/manifests/deployment.yaml index 4032942d..3df93532 100644 --- a/deploy/manifests/deployment.yaml +++ b/deploy/manifests/deployment.yaml @@ -1,8 +1,4 @@ --- -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= apiVersion: apps/v1 kind: Deployment metadata: diff --git a/deploy/manifests/roles.yaml b/deploy/manifests/roles.yaml index e22ea736..07848914 100644 --- a/deploy/manifests/roles.yaml +++ b/deploy/manifests/roles.yaml @@ -30,7 +30,7 @@ rules: - apiGroups: - rbac.authorization.k8s.io resources: - - rolebinding + - rolebindings verbs: - create - delete diff --git a/deploy/manifests/serviceaccount.yaml b/deploy/manifests/serviceaccount.yaml index a9dcd984..452ccab3 100644 --- a/deploy/manifests/serviceaccount.yaml +++ b/deploy/manifests/serviceaccount.yaml @@ -1,8 +1,4 @@ --- -# ============= -# This file is automatically generated from the templates in stackabletech/operator-templating -# DON'T MANUALLY EDIT THIS FILE -# ============= apiVersion: v1 kind: ServiceAccount metadata: