diff --git a/.github/renovate.json b/.github/renovate.json index 8ec6eb6f..85808fe7 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -1,5 +1,31 @@ { - "extends": ["github>rancher/renovate-config#release"], - "baseBranches": ["main"], - "prHourlyLimit": 2 -} \ No newline at end of file + "extends": [ + "github>rancher/renovate-config#release", + "group:allNonMajor" + ], + "baseBranches": [ + "main" + ], + "enabledManagers": [ + "dockerfile", + "github-actions", + "helm-values", + "regex" + ], + "packageRules": [ + { + "groupName": "GitHub Workflow Actions", + "groupSlug": "gha-deps", + "matchManagers": [ + "github-actions" + ] + }, + { + "groupName": "Docker File Deps", + "groupSlug": "docker-bumps", + "matchManagers": [ + "dockerfile" + ] + } + ] +} diff --git a/.github/workflows/e2e/scripts/create-project-namespace.sh b/.github/workflows/e2e/scripts/create-project-namespace.sh index 212441cb..a63ccc92 100755 --- a/.github/workflows/e2e/scripts/create-project-namespace.sh +++ b/.github/workflows/e2e/scripts/create-project-namespace.sh @@ -8,10 +8,10 @@ cd $(dirname $0)/../../../.. USE_RANCHER=${USE_RANCHER:-"false"} if [ "$USE_RANCHER" = "true" ]; then - kubectl apply -f ./examples/ci/project.yaml + kubectl apply -f ./examples/prometheus-federator/ci/project.yaml fi -kubectl apply -f ./examples/ci/namespace.yaml +kubectl apply -f ./examples/prometheus-federator/ci/namespace.yaml sleep "${DEFAULT_SLEEP_TIMEOUT_SECONDS}" if ! kubectl get namespace cattle-project-p-example; then diff --git a/.github/workflows/e2e/scripts/create-projecthelmchart.sh b/.github/workflows/e2e/scripts/create-projecthelmchart.sh index 5ce0611b..27018561 100755 --- a/.github/workflows/e2e/scripts/create-projecthelmchart.sh +++ b/.github/workflows/e2e/scripts/create-projecthelmchart.sh @@ -7,9 +7,9 @@ source $(dirname $0)/entry cd $(dirname $0)/../../../.. if [[ "${E2E_CI}" == "true" ]]; then - kubectl apply -f ./examples/ci/project-helm-chart.yaml + kubectl apply -f ./examples/prometheus-federator/ci/project-helm-chart.yaml else - kubectl apply -f ./examples/project-helm-chart.yaml + kubectl apply -f ./examples/prometheus-federator/project-helm-chart.yaml fi sleep ${DEFAULT_SLEEP_TIMEOUT_SECONDS}; diff --git a/.github/workflows/e2e/scripts/delete-projecthelmchart.sh b/.github/workflows/e2e/scripts/delete-projecthelmchart.sh index f4862a42..f55e7d17 100755 --- a/.github/workflows/e2e/scripts/delete-projecthelmchart.sh +++ b/.github/workflows/e2e/scripts/delete-projecthelmchart.sh @@ -7,9 +7,9 @@ source $(dirname $0)/entry cd $(dirname $0)/../../../.. if [[ "${E2E_CI}" == "true" ]]; then - kubectl delete -f ./examples/ci/project-helm-chart.yaml + kubectl delete -f ./examples/prometheus-federator/ci/project-helm-chart.yaml else - kubectl delete -f ./examples/project-helm-chart.yaml + kubectl delete -f ./examples/prometheus-federator/project-helm-chart.yaml fi if kubectl get -n cattle-monitoring-system job/helm-delete-cattle-project-p-example-monitoring --ignore-not-found; then if ! kubectl wait --for=condition=complete --timeout="${KUBECTL_WAIT_TIMEOUT}" -n cattle-monitoring-system job/helm-delete-cattle-project-p-example-monitoring; then diff --git a/.github/workflows/ci.yaml b/.github/workflows/prom-fed-ci.yaml similarity index 56% rename from .github/workflows/ci.yaml rename to .github/workflows/prom-fed-ci.yaml index 5eb39f75..881a8546 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/prom-fed-ci.yaml @@ -1,6 +1,7 @@ -name: ci +name: "[prom-fed] ci" on: + workflow_call: pull_request: paths-ignore: - 'docs/**' @@ -11,6 +12,9 @@ on: - 'CODEOWNERS' - 'LICENSE' - 'Makefile' + push: + branches: + - main env: YQ_VERSION : v4.25.1 @@ -18,7 +22,12 @@ env: jobs: build: - runs-on: ubuntu-latest + strategy: + matrix: + arch: + - x64 + - arm64 + runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }} steps: - uses: actions/checkout@v4 - name : Set up Go @@ -27,13 +36,8 @@ jobs: go-version: '1.22' - name : Install YQ run: | - sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; + sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }} -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; - name : Install helm - run : | - curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 - chmod 700 get_helm.sh - ./get_helm.sh - rm get_helm.sh - helm version + uses: azure/setup-helm@v3 - name: Run CI run: make ci diff --git a/.github/workflows/e2e-ci.yaml b/.github/workflows/prom-fed-e2e-ci.yaml similarity index 89% rename from .github/workflows/e2e-ci.yaml rename to .github/workflows/prom-fed-e2e-ci.yaml index 32b165c9..4e531bc4 100644 --- a/.github/workflows/e2e-ci.yaml +++ b/.github/workflows/prom-fed-e2e-ci.yaml @@ -1,4 +1,4 @@ -name: E2E Prometheus Federator +name: "[prom-fed] E2E CI" on: workflow_dispatch: @@ -24,6 +24,14 @@ on: - 'CODEOWNERS' - 'LICENSE' - 'Makefile' + push: + branches: + - main + paths-ignore: + - 'docs/**' + - '*.md' + - 'CODEOWNERS' + - 'LICENSE' env: GOARCH: amd64 @@ -44,7 +52,12 @@ permissions: jobs: prebuild-env: name: Prebuild needed Env vars - runs-on: ubuntu-latest + strategy: + matrix: + arch: + - x64 + - arm64 + runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }} steps: - name: Check out the repository to the runner uses: actions/checkout@v4 @@ -59,14 +72,17 @@ jobs: needs: [ prebuild-env, ] - runs-on: ubuntu-latest - env: - TAG: ${{ needs.prebuild-env.outputs.branch_static_tag }} strategy: matrix: + arch: + - x64 + - arm64 k3s_version: # k3d version list k3s | sed 's/+/-/' | sort -h - ${{ github.event.inputs.k3s_version || 'v1.28.14-k3s1' }} + runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }} + env: + TAG: ${{ needs.prebuild-env.outputs.branch_static_tag }} steps: - uses: actions/checkout@v3 @@ -82,7 +98,7 @@ jobs: - name: Install mikefarah/yq run: | - sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; + sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${{ matrix.arch == 'x64' && 'amd64' || matrix.arch }} -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; - name: Perform pre-e2e image build run: | @@ -167,7 +183,7 @@ jobs: if: failure() uses: actions/upload-artifact@v3 with: - name: artifacts + name: artifacts-${{ matrix.arch }}-${{ matrix.k3s_version }} path: artifacts/ retention-days: 1 - diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 4628e8d2..3b658d3d 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -37,7 +37,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . - file: ./package/Dockerfile + file: ./package/Dockerfile-prometheus-federator push: true tags: ${{ env.IMAGE }} platforms: linux/amd64,linux/arm64 \ No newline at end of file diff --git a/.gitignore b/.gitignore index bfae014b..efa3c3c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /.cache /bin /build +!/cmd/prometheus-federator/fs/.gitkeep +/cmd/prometheus-federator/fs/* /dist *.swp .idea diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0836786..a3ae5e91 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,7 +40,7 @@ Scan through our [existing issues](https://github.com/rancher/helm-project-opera - Using the command line: - [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) so that you can make your changes without affecting the original project until you're ready to merge them. -3. Install or update to **Go 1.17**. For more information, see [the development guide](docs/developing.md). +3. Install or update to **Go 1.17**. For more information, see [the development guide](docs/prometheus-federator/developing.md). 4. Create a working branch and start with your changes! diff --git a/Makefile b/Makefile index e7720925..32446662 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TARGETS := $(shell ls scripts) +TARGETS := $(shell ls scripts|grep -ve "^util-\|entry\|^pull-scripts") $(TARGETS): ./scripts/$@ diff --git a/README.md b/README.md index c7d007f0..fbb63009 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ For more information on how to configure the underlying Project Monitoring Stack ## Getting Started -For more information, see the [Getting Started guide](docs/gettingstarted.md). +For more information, see the [Getting Started guide](docs/prometheus-federator/gettingstarted.md). ## Developing @@ -27,13 +27,13 @@ For more information, see the [Getting Started guide](docs/gettingstarted.md). Prometheus Federator is built and released off the contents of the `main` branch. To make a contribution, open up a PR to the `main` branch. -For more information, see the [Developing guide](docs/developing.md). +For more information, see the [Developing guide](docs/prometheus-federator/developing.md). ## Building `make` -> **Note:** For a more in-depth explanation of how Prometheus Federator is built (intended for anyone who would like to fork this repo to create a new Project Operator!), see the [Build guide](docs/build.md). +> **Note:** For a more in-depth explanation of how Prometheus Federator is built (intended for anyone who would like to fork this repo to create a new Project Operator!), see the [Build guide](docs/prometheus-federator/build.md). ## Running @@ -45,7 +45,7 @@ While this repository does maintain a standalone Helm repository for vanilla Hel **The chart in rancher/charts is generally the version that is intended for use in production since that is the chart that will be tested by Rancher's QA team.** Generally, these charts will match stable versions of charts available in this repository, so non-Rancher users **should** be able to safely use those versions in this repository for production use cases (at their own risk). -For more information on the process maintainers of this repository use to mirror these charts over to [`rancher/charts`](https://github.com/rancher/charts), see the [Rancher release guide](docs/rancher_release.md). +For more information on the process maintainers of this repository use to mirror these charts over to [`rancher/charts`](https://github.com/rancher/charts), see the [Rancher release guide](docs/prometheus-federator/rancher_release.md). ## License Copyright (c) 2020 [Rancher Labs, Inc.](http://rancher.com) diff --git a/cmd/prometheus-federator/fs/.gitkeep b/cmd/prometheus-federator/fs/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/main.go b/cmd/prometheus-federator/main.go similarity index 97% rename from main.go rename to cmd/prometheus-federator/main.go index 81265b34..322839a5 100644 --- a/main.go +++ b/cmd/prometheus-federator/main.go @@ -29,7 +29,7 @@ var ( // SystemNamespaces is the system namespaces scoped for the embedded monitoring chart (rancher-project-monitoring) SystemNamespaces = []string{"kube-system", "cattle-monitoring-system", "cattle-dashboards"} - //go:embed build/chart/rancher-project-monitoring.tgz.base64 + //go:embed fs/rancher-project-monitoring.tgz.base64 base64TgzChart string debugConfig command.DebugConfig diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..6afff8f3 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,9 @@ +# prometheus-federator collective + +The information in this top level docs folder should be relevant to all packages in this repo. +For package specific information each sub-package should have an equivalent directory. + +The packages maintained from this repo are: +- `prometheus-federator`, +- `helm-project-operator`, +- `helm-locker` diff --git a/docs/build.md b/docs/prometheus-federator/build.md similarity index 85% rename from docs/build.md rename to docs/prometheus-federator/build.md index d7fd37e6..a20765da 100644 --- a/docs/build.md +++ b/docs/prometheus-federator/build.md @@ -11,7 +11,7 @@ The underlying Helm Chart whose releases are deployed on behalf of every registe While the source of this chart is found in the `packages/` directory, which is a construct of any [rancher/charts-build-scripts](https://github.com/rancher/charts-build-scripts) repository (see [the docs on Packages](https://github.com/rancher/charts-build-scripts/blob/master/templates/template/docs/packages.md) for more information), it is expected that a developer who files a PR with changes will run the `make charts` command to ensure that the package is read by the `rancher/charts-build-scripts` binary to **produce / auto-generate** the Helm Charts and manage the `assets/`+`charts/` directories as well as the `index.yaml` entries to introduce this package in a standard Helm repository fashion. -Once `make charts` has been run and the chart is built from `packages/rancher-project-monitoring/` -> `charts/rancher-project-monitoring/${VERSION}` (part of the `make charts` command), the built chart is then converted into a `.tgz.base64` version of itself in [scripts/build-chart](../scripts/build-chart) and left in `bin/rancher-project-monitoring/rancher-project-monitoring.tgz.base64`. +Once `make charts` has been run and the chart is built from `packages/rancher-project-monitoring/` -> `charts/rancher-project-monitoring/${VERSION}` (part of the `make charts` command), the built chart is then converted into a `.tgz.base64` version of itself in [scripts/build-chart](../../scripts/build-chart) and left in `bin/rancher-project-monitoring/rancher-project-monitoring.tgz.base64`. ```bash helm package charts/${CHART}/${VERSION} --destination bin/${CHART} @@ -21,7 +21,7 @@ rm bin/${CHART}/${CHART}-${VERSION}.tgz ## The Project Operator Image -To implement a Project Operator, Helm Project Operator expects a user to run the `operator.Init` command, which appears in Prometheus Federator's [`main.go`](../main.go) as follows: +To implement a Project Operator, Helm Project Operator expects a user to run the `operator.Init` command, which appears in Prometheus Federator's [`main.go`](../../main.go) as follows: ```go operator.Init(ctx, f.Namespace, cfg, common.Options{ @@ -36,7 +36,7 @@ operator.Init(ctx, f.Namespace, cfg, common.Options{ }) ``` -While the `HelmAPIVersion`, `ReleaseName`, and `SystemNamespaces` supplied are hard-coded into the [`main.go`](../main.go) and the `RuntimeOptions` are taken from the CLI arguments provided, the only additional value that is needed to build this chart is the `.tgz.base64` version of the chart that is passed in as a string to the operator. +While the `HelmAPIVersion`, `ReleaseName`, and `SystemNamespaces` supplied are hard-coded into the [`main.go`](../../main.go) and the `RuntimeOptions` are taken from the CLI arguments provided, the only additional value that is needed to build this chart is the `.tgz.base64` version of the chart that is passed in as a string to the operator. This is precisely what we build in the prior step at `bin/rancher-project-monitoring/rancher-project-monitoring.tgz.base64`, which is why that path is found as a `go embed` directive on building the `main.go`: @@ -45,9 +45,9 @@ This is precisely what we build in the prior step at `bin/rancher-project-monito base64TgzChart string ``` -Once your [`main.go`](../main.go) is ready to be built, you can run `./scripts/build`, which will run the underlying `go build` command and place the created binary in `bin/prometheus-federator`. +Once your [`main.go`](../../main.go) is ready to be built, you can run `./scripts/build`, which will run the underlying `go build` command and place the created binary in `bin/prometheus-federator`. -Once the binary has been created, it is then packaged into a container image in the [`scripts/package`](../scripts/package) step, where we build the Dockerfile found in `packages/Dockerfile` to produce the final image. +Once the binary has been created, it is then packaged into a container image in the [`scripts/package`](../../scripts/package) step, where we build the Dockerfile found in `packages/Dockerfile` to produce the final image. ## The Project Operator Helm Chart @@ -62,7 +62,7 @@ Once `make charts` has been run and the chart is built from `packages/prometheus Therefore, as a whole, the build process of Underlying Helm Chart looks as follows: - By a developer on making a PR to change the Underlying Helm Chart: - Run `make charts` to produce the Underlying Helm Chart in `charts/rancher-project-monitoring/${VERSION}` from `packages/rancher-project-monitoring/` -- By running `make` (which runs [rancher/dapper](https://github.com/rancher/dapper) on the `Dockerfile.dapper`, which in turn runs [`./scripts/ci`](../scripts/ci) that runs the following commands in an container image): +- By running `make` (which runs [rancher/dapper](https://github.com/rancher/dapper) on the `Dockerfile.dapper`, which in turn runs [`./scripts/ci`](../../scripts/ci) that runs the following commands in an container image): - Run `./scripts/build-chart` to produce `bin/rancher-project-monitoring/rancher-project-monitoring.tgz.base64` from the Underlying Helm Chart - Run `./scripts/build` to produce the Project Operator Binary `bin/prometheus-federator`; **this will work since `bin/rancher-project-monitoring/rancher-project-monitoring.tgz.base64` exists from the previous step** - Run `./scripts/package` to produce the Project Operator Image diff --git a/docs/design.md b/docs/prometheus-federator/design.md similarity index 100% rename from docs/design.md rename to docs/prometheus-federator/design.md diff --git a/docs/developer/monitoring_v1.md b/docs/prometheus-federator/developer/monitoring_v1.md similarity index 93% rename from docs/developer/monitoring_v1.md rename to docs/prometheus-federator/developer/monitoring_v1.md index d77a347c..27b5fabd 100644 --- a/docs/developer/monitoring_v1.md +++ b/docs/prometheus-federator/developer/monitoring_v1.md @@ -63,14 +63,14 @@ When only Alerting is enabled, unlike in Monitoring V2 which only supports **met From a chart design perspective, it's easier to compare Monitoring V1 against the upstream [`kube-prometheus-stack`](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) chart, since they were developed in parallel around the same timeframe. -When both Monitoring V1 and Alerting V1 are enabled, Monitoring V1 deploys all the underlying components listed in [the Monitoring V2 docs around `kube-prometheus-stack`](./monitoring_v2.md#what-does-it-deploy). +When both Monitoring V1 and Alerting V1 are enabled, Monitoring V1 deploys all the underlying components listed in [the Monitoring V2 docs around `kube-prometheus-stack`](monitoring_v2.md#what-does-it-deploy). The primary differences include that it: - Has far fewer configuration options than upstream **(this is primarily why Monitoring V2 is based on an upstream chart instead of Monitoring V1)** - Uses a completely different set of Rancher-original dashboards and alerts instead of upstream dashboards and alerts, which requires more maintainence from Rancher **(a secondary reason why Monitoring V2 is based on an upstream chart instead of Monitoring V1)** -- Supports deploying `wmi_exporter` (now called [`windows_exporter`](./monitoring_v2.md#windowsexporterhttpsgithubcomprometheus-communitywindowsexporter-for-windows-support) in Monitoring V2, but it's the exact same codebase / solution) for RKE1 Windows Monitoring. +- Supports deploying `wmi_exporter` (now called [`windows_exporter`](monitoring_v2.md#windowsexporterhttpsgithubcomprometheus-communitywindowsexporter-for-windows-support) in Monitoring V2, but it's the exact same codebase / solution) for RKE1 Windows Monitoring. - Has default exporters for integration with Rancher's Logging V1 and Istio V1 System Charts -- Deploys [`rancher/webhook-receiver`](https://github.com/rancher/webhook-receiver), which is the Monitoring V1 equivalent of [Alerting Drivers](./monitoring_v2.md#add-on-chart-alerting-drivers) with Rancher-maintained non-native notification providers for Alertmanager, as opposed to Alerting Drivers which entirely packages official upstream solutions. +- Deploys [`rancher/webhook-receiver`](https://github.com/rancher/webhook-receiver), which is the Monitoring V1 equivalent of [Alerting Drivers](monitoring_v2.md#add-on-chart-alerting-drivers) with Rancher-maintained non-native notification providers for Alertmanager, as opposed to Alerting Drivers which entirely packages official upstream solutions. - Uses [`rancher/prometheus-auth`](https://github.com/rancher/prometheus-auth) as a proxy in front of all Prometheus instances to ensure that users (or Grafana) are only able to see the values that they should have permissions to be able to see > **Note**: How does Prometheus Auth work on a high-level? @@ -103,10 +103,10 @@ In order to be fully functional, Monitoring V1 also required the use of controll While some of these controllers operate on native Kubernetes resources (such as the `ExporterEndpointController`), some controllers also sometimes directly operate / manage Prometheus Operator CRs -The issue with this appraoch is explained in more depth in a note in [the main Monitoring V2 docs around the CRD chart](./monitoring_v2.md#crd-chart-with-install--uninstall-jobs), but essentially splitting ownership of Prometheus Operator CRs between Prometheus Operator itself (that is deployed by the Monitoring V1 chart) and Rancher creates a lot of edge conditions; this is why Monitoring V2 primarily moved towards a **decoupled** approach with respect to Rancher and Monitoring V2. +The issue with this appraoch is explained in more depth in a note in [the main Monitoring V2 docs around the CRD chart](monitoring_v2.md#crd-chart-with-install--uninstall-jobs), but essentially splitting ownership of Prometheus Operator CRs between Prometheus Operator itself (that is deployed by the Monitoring V1 chart) and Rancher creates a lot of edge conditions; this is why Monitoring V2 primarily moved towards a **decoupled** approach with respect to Rancher and Monitoring V2. However, assuming that this doesn't cause an issue, here are the different controllers that get deployed for **Monitoring V1**: -- `ExporterEndpointController`: keeps track of all nodes in the cluster and manually maintains (injects into or removes endpoints from) the `Endpoints` objects tied to `etcd`, `kube-scheduler`, `kube-controller-manager`, and `node-windows`. These Endpoints objects were tied to headless Services deployed by the Monitoring V1 chart that the Monitoring V1 chart would already have `ServiceMonitors` pointing to, but unlike in Monitoring V2 where we have [PushProx](./monitoring_v2.md#pushprox-exporters-for-most-kubernetes-internal-components) that handles discovering new targets itself via scheduling the clients onto those nodes and populating the `Endpoints` objects based on labelSelectors on workloads, this needed to be manually maintained by Rancher legacy controllers +- `ExporterEndpointController`: keeps track of all nodes in the cluster and manually maintains (injects into or removes endpoints from) the `Endpoints` objects tied to `etcd`, `kube-scheduler`, `kube-controller-manager`, and `node-windows`. These Endpoints objects were tied to headless Services deployed by the Monitoring V1 chart that the Monitoring V1 chart would already have `ServiceMonitors` pointing to, but unlike in Monitoring V2 where we have [PushProx](monitoring_v2.md#pushprox-exporters-for-most-kubernetes-internal-components) that handles discovering new targets itself via scheduling the clients onto those nodes and populating the `Endpoints` objects based on labelSelectors on workloads, this needed to be manually maintained by Rancher legacy controllers - `ConfigRefreshHandler`: keeps track of which namespaces are in a current Project and triggers an update of a Project Monitoring Stack deployment if necessary. - `MetricsServiceController` diff --git a/docs/developer/monitoring_v2.md b/docs/prometheus-federator/developer/monitoring_v2.md similarity index 99% rename from docs/developer/monitoring_v2.md rename to docs/prometheus-federator/developer/monitoring_v2.md index 4123458b..f12971cf 100644 --- a/docs/developer/monitoring_v2.md +++ b/docs/prometheus-federator/developer/monitoring_v2.md @@ -194,7 +194,7 @@ In addition, the main chart `rancher-monitoring` has `catalog.cattle.io/provides However, **unlike normal CRD charts in Rancher (which just directly package CRDs in the `templates/` directory**, Monitoring also utilizes a pre-install / pre-upgrade Job and post-delete Job to install and remove CRDs from the cluster. -This is necessary since Rancher has legacy controllers for the old [Monitoring V1](./monitoring_v1.md#legacy-what-is-monitoring--alerting-v1) solution embedded within it, so on initializing the management agent controllers when Monitoring V1's feature flag is enabled **(even if Monitoring V1 is not currently installed in the cluster)**, Rancher creates the Prometheus Operator CRDs within the cluster before starting the controllers. +This is necessary since Rancher has legacy controllers for the old [Monitoring V1](monitoring_v1.md#legacy-what-is-monitoring--alerting-v1) solution embedded within it, so on initializing the management agent controllers when Monitoring V1's feature flag is enabled **(even if Monitoring V1 is not currently installed in the cluster)**, Rancher creates the Prometheus Operator CRDs within the cluster before starting the controllers. This poses a problem since Helm **cannot naturally assume ownership of non-Helm resources** (which gives a familiar error that says that it cannot import an object into a release due to missing labels), so instead Helm simply deploys a Job that runs `kubectl apply` and `kubectl delete` to manage the CRDs on Helm's behalf. diff --git a/docs/developing.md b/docs/prometheus-federator/developing.md similarity index 100% rename from docs/developing.md rename to docs/prometheus-federator/developing.md diff --git a/docs/experimental/e2e.md b/docs/prometheus-federator/experimental/e2e.md similarity index 80% rename from docs/experimental/e2e.md rename to docs/prometheus-federator/experimental/e2e.md index 1cd6137f..46046651 100644 --- a/docs/experimental/e2e.md +++ b/docs/prometheus-federator/experimental/e2e.md @@ -2,7 +2,7 @@ ## What does E2E CI do? -The E2E CI described in [.github/scripts/](../../.github/workflows/e2e-ci.yaml) checks out the current Git repository, builds a Docker image using the repository's build scripts, sets up a [k3d](https://k3d.io) cluster, imports the built `prometheus-federator` image into the cluster (which automatically uses the latest `rancher-project-monitoring` chart since it is embedded into the binary as part of the build process), and then uses Helm to install both `rancher-monitoring` (using the latest released version) and `prometheus-federator` (using the Helm chart contained in the repository). +The E2E CI described in [.github/scripts/](../../../.github/workflows/prom-fed-e2e-ci.yaml) checks out the current Git repository, builds a Docker image using the repository's build scripts, sets up a [k3d](https://k3d.io) cluster, imports the built `prometheus-federator` image into the cluster (which automatically uses the latest `rancher-project-monitoring` chart since it is embedded into the binary as part of the build process), and then uses Helm to install both `rancher-monitoring` (using the latest released version) and `prometheus-federator` (using the Helm chart contained in the repository). Once both are installed, it will run checks to ensure that all workloads are up and running in both Helm installs and then mimic creating a Project (by creating a namespace with a particular label on it). @@ -16,7 +16,7 @@ Finally, it deletes the ProjectHelmChart, asserts the helm uninstall Job on the To run the end-to-end GitHub Workflow CI locally to test whether your changes work, it's recommended to install [`nektos/act`](https://github.com/nektos/act). -An slim image has been defined in [`.github/workflows/e2e/package/Dockerfile`](../../.github/workflows/e2e/package/Dockerfile) that has the necessary dependencies to be used as a Runner for act for this GitHub Workflow. To build the image, run the following commmand (make sure you re-run it if you make any changes to add dependencies): +An slim image has been defined in [`.github/workflows/e2e/package/Dockerfile`](../../../.github/workflows/e2e/package/Dockerfile) that has the necessary dependencies to be used as a Runner for act for this GitHub Workflow. To build the image, run the following commmand (make sure you re-run it if you make any changes to add dependencies): ```bash docker build -f ./.github/workflows/e2e/package/Dockerfile -t rancher/prometheus-federator-e2e:latest . @@ -32,7 +32,7 @@ act pull_request -j e2e-prometheus-federator -P ubuntu-latest=rancher/prometheus ## Running E2E Tests on an already provisioned cluster -To verify that the functionality of Prometheus Federator on a live cluster that you have already configured your `KUBECONFIG` environment variable to point to, you can use the utility script found in [script/e2e-ci](../../scripts/e2e-ci) to run the relevant CI commands to install Monitoring, install Prometheus Federator using your forked image, and run the remaining CI steps. +To verify that the functionality of Prometheus Federator on a live cluster that you have already configured your `KUBECONFIG` environment variable to point to, you can use the utility script found in [script/e2e-ci](../../../scripts/e2e-ci) to run the relevant CI commands to install Monitoring, install Prometheus Federator using your forked image, and run the remaining CI steps. > **Note:** For now, this script only works on k3s, RKE1, and RKE2 clusters but it can be easily extended to work on different cluster types by supplying the right values in `install-federator.sh`, `install-monitoring.sh`, and `validate-monitoring.sh` to enable and verify the correct cluster-type specific testing. Contributions are welcome! diff --git a/docs/experimental/rebasing.md b/docs/prometheus-federator/experimental/rebasing.md similarity index 75% rename from docs/experimental/rebasing.md rename to docs/prometheus-federator/experimental/rebasing.md index d77340c3..92776b77 100644 --- a/docs/experimental/rebasing.md +++ b/docs/prometheus-federator/experimental/rebasing.md @@ -16,7 +16,7 @@ Therefore, in order to rebase the `rancher-project-monitoring` chart against the PACKAGE=rancher-project-monitoring TO_COMMIT= TO_DIR=charts/rancher-monitoring/ make rebase ``` -On running this command locally, the script will automatically pull in the `rancher/charts` repository as a Git remote, construct the patch from the current chart base (listed in the [`package.yaml` of `rancher-project-monitoring`](../../packages/rancher-project-monitoring/package.yaml)) to the new chart base (defined from the environment variables provided, namely `TO_REMOTE`, `TO_COMMIT` , `TO_DIR`), and try to `git apply -3` the patches onto the current version of the charts created by running the `make prepare` command. +On running this command locally, the script will automatically pull in the `rancher/charts` repository as a Git remote, construct the patch from the current chart base (listed in the [`package.yaml` of `rancher-project-monitoring`](../../../packages/rancher-project-monitoring/package.yaml)) to the new chart base (defined from the environment variables provided, namely `TO_REMOTE`, `TO_COMMIT` , `TO_DIR`), and try to `git apply -3` the patches onto the current version of the charts created by running the `make prepare` command. On applying the 3-way merge from the `git apply` command, the script will automatically create a shell (titled `interactive-rebase-shell`) that allows you to look through the changes that have been absorbed from upstream, resolve any conflicts (using the same Git conflict resolution experience you would have on executing a `git rebase -i`), and add all your changes to `staging` (`git add` **only**; the script will force you to stage any unstaged or committed changes if you try to). @@ -27,16 +27,16 @@ Once all your conflicts have been resolved (which you can check by running `git Once you have made the changes using the rebase script, you will need to manually rebase the Grafana dependency as well. To do this, take the following steps: 1. Run `export PACKAGE=rancher-project-monitoring; make prepare` to prepare the working directory using your existing base -2. Modify the `.url`, `.subdirectory`, and `.commit` fields in [packages/rancher-project-monitoring/generated-changes/dependencies/grafana/dependency.yaml](../../packages/rancher-project-monitoring/generated-changes/dependencies/grafana/dependency.yaml) to reflect the contents of [packages/rancher-project-monitoring/package.yaml](../../packages/rancher-project-monitoring/package.yaml). **Note: The subdirectory should be the same as `rancher-project-monitoring` with `charts/grafana` appended after.** -3. Run `make patch`. This should regenerate [packages/rancher-project-monitoring/generated-changes](../../packages/rancher-project-monitoring/generated-changes). +2. Modify the `.url`, `.subdirectory`, and `.commit` fields in [packages/rancher-project-monitoring/generated-changes/dependencies/grafana/dependency.yaml](../../../packages/rancher-project-monitoring/generated-changes/dependencies/grafana/dependency.yaml) to reflect the contents of [packages/rancher-project-monitoring/package.yaml](../../../packages/rancher-project-monitoring/package.yaml). **Note: The subdirectory should be the same as `rancher-project-monitoring` with `charts/grafana` appended after.** +3. Run `make patch`. This should regenerate [packages/rancher-project-monitoring/generated-changes](../../../packages/rancher-project-monitoring/generated-changes). 4. Add all your changes and create a commit, i.e. `Update grafana dependency to new base ${TO_COMMIT}` ### Once you have successfully run the scripts and rebased Grafana -1. Bump the minor version listed under [`packages/prometheus-federator/charts/Chart.yaml`](../../packages/prometheus-federator/charts/Chart.yaml) under `appVersion` and `version` and reset the patch version (i.e. `0.1.1` -> `0.2.0`); they should both match. -1. Update the tag in [`packages/prometheus-federator/charts/values.yaml`](../../packages/prometheus-federator/charts/values.yaml) under `helmProjectOperator.image.tag` to `v`, where `` is the version you identified in the previous step (i.e. `0.2.0`) -1. Modify the `version` field under [`packages/rancher-project-monitoring/package.yaml`](../../packages/rancher-project-monitoring/package.yaml) to the same version from above (i.e. `0.2.0`) -1. Modify the `VERSION` environment variable under [`scripts/build-chart`](../../scripts/build-chart) to the same version (i.e. `0.2.0`) +1. Bump the minor version listed under [`packages/prometheus-federator/charts/Chart.yaml`](../../../packages/prometheus-federator/charts/Chart.yaml) under `appVersion` and `version` and reset the patch version (i.e. `0.1.1` -> `0.2.0`); they should both match. +1. Update the tag in [`packages/prometheus-federator/charts/values.yaml`](../../../packages/prometheus-federator/charts/values.yaml) under `helmProjectOperator.image.tag` to `v`, where `` is the version you identified in the previous step (i.e. `0.2.0`) +1. Modify the `version` field under [`packages/rancher-project-monitoring/package.yaml`](../../../packages/rancher-project-monitoring/package.yaml) to the same version from above (i.e. `0.2.0`) +1. Modify the `VERSION` environment variable under [`scripts/build-chart`](../../../scripts/build-chart) to the same version (i.e. `0.2.0`) 1. Run `make charts`; this should produce: - `assets/prometheus-federator/prometheus-federator-.tgz` - `assets/rancher-project-monitoring/rancher-project-monitoring-.tgz` diff --git a/docs/gettingstarted.md b/docs/prometheus-federator/gettingstarted.md similarity index 97% rename from docs/gettingstarted.md rename to docs/prometheus-federator/gettingstarted.md index ecd3c8ad..ff4b132b 100644 --- a/docs/gettingstarted.md +++ b/docs/prometheus-federator/gettingstarted.md @@ -7,7 +7,7 @@ In order to install Prometheus Federator, you first need to have Prometheus Operator deployed; it is also suggested that you configure at least one Cluster Prometheus that is collecting metrics using common exporters (kube-state-metrics, node-exporter, etc.) for the dashboards to work out-of-the-box. It is recommended that you install either: -- [`rancher-monitoring`](https://rancher.com/docs/rancher/v2.6/en/monitoring-alerting/), which should work out-of-the-box with Prometheus Federator (see the [`README.md` on the Helm Chart](../packages/prometheus-federator/charts/README.md) for more information on how to optimally configure rancher-monitoring to work with Prometheus Federator) +- [`rancher-monitoring`](https://rancher.com/docs/rancher/v2.6/en/monitoring-alerting/), which should work out-of-the-box with Prometheus Federator (see the [`README.md` on the Helm Chart](../../packages/prometheus-federator/charts/README.md) for more information on how to optimally configure rancher-monitoring to work with Prometheus Federator) - [`kube-prometheus-stack`](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack), which should work with minor modifications to Prometheus Federator. > Note: this is currently untested but we welcome contributions to update our docs to help users get supported for using Prometheus Federator with vanilla kube-prometheus-stack! In theory, the only changes that should be necessary would be to configure the Prometheus Federator chart to use a different `helmProjectOperator.valuesOverrides.federate.targets` and to override all the selectors on the Prometheus Operator resources (or Grafana Sidecars) in the underlying chart; it could also be possible that this would work out-of-the-box with `kube-prometheus-stack` as long as you supply `.Values.nameOverride=rancher-monitoring` and `.Values.namespaceOverride=cattle-monitoring-system`. diff --git a/docs/rancher_release.md b/docs/prometheus-federator/rancher_release.md similarity index 98% rename from docs/rancher_release.md rename to docs/prometheus-federator/rancher_release.md index 78e84865..95e5e8fe 100644 --- a/docs/rancher_release.md +++ b/docs/prometheus-federator/rancher_release.md @@ -6,7 +6,7 @@ Any time a PR is merged into this repository, the chart should be mirrored to th Prior to making changes to [`rancher/charts`](https://github.com/rancher/charts), you will need to cut a GitHub tag / release to trigger CI into creating [the Project Operator Image on DockerHub](https://hub.docker.com/r/rancher/prometheus-federator): 1. Navigate to the page to [`Draft a new release`](https://github.com/rancher/prometheus-federator/releases/new) -2. On the `Choose a tag` dropdown, carefully type in the version **prefixed with `v`** that corresponds to the version of Prometheus Federator that was just merged in the PR (i.e. the value found on the `version` field of [`packages/prometheus-federator/charts/Chart.yaml`](../packages/prometheus-federator/charts/Chart.yaml)). +2. On the `Choose a tag` dropdown, carefully type in the version **prefixed with `v`** that corresponds to the version of Prometheus Federator that was just merged in the PR (i.e. the value found on the `version` field of [`packages/prometheus-federator/charts/Chart.yaml`](../../packages/prometheus-federator/charts/Chart.yaml)). 3. Copy the tag name into the Release Name field (i.e. `vX.X.X`) 4. Click on the button that says `Generate release notes` 5. **Review all your changes**; once a tag is created, **it should never be deleted**. diff --git a/examples/ci/namespace.yaml b/examples/prometheus-federator/ci/namespace.yaml similarity index 100% rename from examples/ci/namespace.yaml rename to examples/prometheus-federator/ci/namespace.yaml diff --git a/examples/ci/project-helm-chart.yaml b/examples/prometheus-federator/ci/project-helm-chart.yaml similarity index 100% rename from examples/ci/project-helm-chart.yaml rename to examples/prometheus-federator/ci/project-helm-chart.yaml diff --git a/examples/ci/project.yaml b/examples/prometheus-federator/ci/project.yaml similarity index 100% rename from examples/ci/project.yaml rename to examples/prometheus-federator/ci/project.yaml diff --git a/examples/project-helm-chart.yaml b/examples/prometheus-federator/project-helm-chart.yaml similarity index 100% rename from examples/project-helm-chart.yaml rename to examples/prometheus-federator/project-helm-chart.yaml diff --git a/scripts/boilerplate.go.txt b/gen/boilerplate.go.txt similarity index 100% rename from scripts/boilerplate.go.txt rename to gen/boilerplate.go.txt diff --git a/package/Dockerfile b/package/Dockerfile-prometheus-federator similarity index 100% rename from package/Dockerfile rename to package/Dockerfile-prometheus-federator diff --git a/scripts/build b/scripts/build index f3f04ce6..c8606bb4 100755 --- a/scripts/build +++ b/scripts/build @@ -2,20 +2,22 @@ set -e source $(dirname $0)/version +BUILD_CMD_TARGET=${BUILD_CMD_TARGET:-"./cmd/${BUILD_TARGET}/main.go"} cd $(dirname $0)/.. ./scripts/build-chart -echo "Starting \`prometheus-federator\` binary build:"; +echo "Building \`${BUILD_TARGET}\` from \`${BUILD_CMD_TARGET}\`"; mkdir -p build/bin if [ "$(uname)" = "Linux" ]; then OTHER_LINKFLAGS="-extldflags -static -s" fi -LINKFLAGS="-X github.com/rancher/prometheus-federator/pkg/version.Version=$VERSION" -LINKFLAGS="-X github.com/rancher/prometheus-federator/pkg/version.GitCommit=$COMMIT $LINKFLAGS" +LINKFLAGS="-X github.com/rancher/${BUILD_TARGET}/pkg/version.Version=$VERSION" +LINKFLAGS="-X github.com/rancher/${BUILD_TARGET}/pkg/version.GitCommit=$COMMIT $LINKFLAGS" +BIN_DEST="build/bin/${BUILD_TARGET}" ARCHES=( "$ARCH" ) # Set CROSS_ARCH to build for the other architecture @@ -30,18 +32,17 @@ fi echo "Building for Arch(s): ${ARCHES[*]}" for A in "${ARCHES[@]}" ; do - GOARCH="$A" CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o "build/bin/prometheus-federator-$A" + GOARCH="$A" CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o "${BIN_DEST}-$A" "${BUILD_CMD_TARGET}" # Set CROSS to build for other OS'es if [ "$CROSS" = "true" ]; then for OS in darwin windows ; do - GOARCH="$A" GOOS=$OS go build -ldflags "$LINKFLAGS" -o "build/bin/prometheus-federator-$OS-$A" - echo "Built \`prometheus-federator-$OS-$A\`" + GOARCH="$A" GOOS=$OS go build -ldflags "$LINKFLAGS" -o "${BIN_DEST}-$OS-$A" "${BUILD_CMD_TARGET}" done fi done cd build/bin -ln -sf "./prometheus-federator-$ARCH" "./prometheus-federator" +ln -sf "${BUILD_TARGET}-$ARCH" "${BUILD_TARGET}" cd ../.. -echo "Completed \`prometheus-federator\` binary build." \ No newline at end of file +echo "Build complete, binary at: \`"${BIN_DEST}"\`" \ No newline at end of file diff --git a/scripts/build-chart b/scripts/build-chart index 4196c4ef..3b1f05e9 100755 --- a/scripts/build-chart +++ b/scripts/build-chart @@ -2,16 +2,28 @@ set -e source $(dirname $0)/version +source $(dirname $0)/util-chart + +# We don't do this for helm-locker +if [[ "${BUILD_TARGET}" == "helm-locker" ]]; then + exit +fi cd $(dirname $0)/.. -CHART=${CHART:-rancher-project-monitoring} -VERSION=${EMBEDED_CHART_VERSION:-$(find ./charts/${CHART} -maxdepth 1 -mindepth 1 -type d | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4)} +declare -r chart_options=( + #["helm-project-operator"]="project-operator-example", + ["prometheus-federator"]="rancher-project-monitoring" +) + +CHART=${CHART:-${chart_options[$BUILD_TARGET]}} +CHART_VERSION=${EMBEDED_CHART_VERSION:-$(find ./charts/${CHART} -maxdepth 1 -mindepth 1 -type d | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4)} -mkdir -p build/bin +# Prepare and package charts +package-charts "charts/${CHART}/${CHART_VERSION}" ./build/charts -helm package charts/${CHART}/${VERSION} --destination build/chart -base64 -i build/chart/${CHART}-${VERSION}.tgz > build/chart/${CHART}.tgz.base64 -rm build/chart/${CHART}-${VERSION}.tgz +# Prepare chart for embedding location +base64 -i "build/charts/${CHART}-${CHART_VERSION}.tgz" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64" +rm "build/charts/${CHART}-${CHART_VERSION}.tgz" -echo "Completed ${CHART} (${VERSION}) build process." \ No newline at end of file +echo "Completed ${CHART} (${CHART_VERSION}) build process." \ No newline at end of file diff --git a/scripts/package b/scripts/package index 9f7a9160..f3d6d458 100755 --- a/scripts/package +++ b/scripts/package @@ -2,20 +2,13 @@ set -e source $(dirname $0)/version +DOCKER_TARGET=${DOCKER_TARGET:-"-${BUILD_TARGET}"} cd $(dirname $0)/.. -echo "Starting \`prometheus-federator\` packaging:"; +echo "Starting \`${DOCKER_TARGET}\` image packaging:"; -mkdir -p dist/artifacts -cp build/bin/prometheus-federator dist/artifacts/prometheus-federator${SUFFIX} - -IMAGE=${REPO}/prometheus-federator:${TAG} -DOCKERFILE=package/Dockerfile -if [ -e ${DOCKERFILE}.${ARCH} ]; then - DOCKERFILE=${DOCKERFILE}.${ARCH} -fi - -echo "Building \`${DOCKERFILE}\` with name \`${IMAGE}\`:"; -docker build -f ${DOCKERFILE} -t ${IMAGE} . +DOCKERFILE=package/Dockerfile${DOCKER_TARGET} +echo "Building \`${IMAGE}\` from \`${DOCKERFILE}\`:"; +docker build -f "${DOCKERFILE}" -t "${IMAGE}" . echo "Completed building ${IMAGE} container image" diff --git a/scripts/pull-scripts b/scripts/pull-scripts index 9a8464d5..99bb8bdc 100755 --- a/scripts/pull-scripts +++ b/scripts/pull-scripts @@ -6,7 +6,7 @@ cd $(dirname $0) source ./version if ls ../bin/charts-build-scripts 1>/dev/null 2>/dev/null; then - CURRENT_SCRIPT_VERSION=$(../bin/charts-build-scripts --version | cut -d' ' -f3) + CURRENT_SCRIPT_VERSION="v$(../bin/charts-build-scripts --version | cut -d' ' -f3)" if [[ "${CURRENT_SCRIPT_VERSION}" == "${CHARTS_BUILD_SCRIPT_VERSION}" ]]; then exit 0 fi diff --git a/scripts/test b/scripts/test index 08662432..c9183cac 100755 --- a/scripts/test +++ b/scripts/test @@ -3,5 +3,12 @@ set -e cd $(dirname $0)/.. -echo Running tests -go test -cover -tags=test ./... +declare -r target_test_tags=( + #["helm-locker"]="helm_locker", + #["helm-project-operator"]="helm_locker", + ["prometheus-federator"]="prometheus_federator" +) +TARGET_TEST_TAG=${target_test_tags[$BUILD_TARGET]} + +echo "Running tests for ${TARGET_TEST_TAG}" +go test -cover -tags="test,${TARGET_TEST_TAG}" ./... diff --git a/scripts/util-chart b/scripts/util-chart new file mode 100644 index 00000000..cb268f92 --- /dev/null +++ b/scripts/util-chart @@ -0,0 +1,12 @@ +#!/bin/bash + +function edit-charts() { + sed -i \ + -e 's/^version:.*/version: '${2}'/' \ + -e 's/^appVersion:.*/appVersion: '${3}'/' \ + "${1}" +} + +function package-charts() { + helm package --debug "${1:-"./build/charts/helm-project-operator"}" -d "${2:-"./dist/artifacts"}" +} \ No newline at end of file diff --git a/scripts/validate-chart b/scripts/validate-chart index 11677faf..ab08226f 100755 --- a/scripts/validate-chart +++ b/scripts/validate-chart @@ -1,6 +1,11 @@ #!/bin/bash set -e +# We don't do this for helm-locker +if [[ "${BUILD_TARGET}" == "helm-locker" ]]; then + exit +fi + cd $(dirname $0)/.. echo "Validating newest prometheus-federator chart" diff --git a/scripts/validate-ci b/scripts/validate-ci index 38121d5e..b91da85e 100755 --- a/scripts/validate-ci +++ b/scripts/validate-ci @@ -1,12 +1,20 @@ #!/bin/bash set -e +source $(dirname $0)/version cd $(dirname $0)/.. -echo "Verifying code is generated and repo is clean" -go generate +echo "[validate-ci] starting to validate" +echo "Running go mod tidy" +go mod tidy -source ./scripts/version +echo "Running go mod verify" +go mod verify + +if [ -f "generate.go" ]; then + echo "Verifying code is generated and repo is clean" + go generate +fi if [ -n "$DIRTY" ]; then echo Git is dirty @@ -14,3 +22,5 @@ if [ -n "$DIRTY" ]; then git diff exit 1 fi + +echo "[validate-ci] success" diff --git a/scripts/version b/scripts/version index 2215508b..be0311ab 100755 --- a/scripts/version +++ b/scripts/version @@ -1,9 +1,10 @@ #!/bin/bash -set -x CHARTS_BUILD_SCRIPTS_REPO=https://github.com/rancher/charts-build-scripts.git CHARTS_BUILD_SCRIPT_VERSION=v0.9.2 +BUILD_TARGET=${BUILD_TARGET:-"prometheus-federator"} + if [ -n "$(git status --porcelain --untracked-files=no)" ]; then DIRTY="-dirty" fi @@ -27,14 +28,26 @@ SUFFIX="-${ARCH}" TAG=${TAG:-${VERSION}} REPO=${REPO:-rancher} +HELM_IMAGE_TAG=${HELM_IMAGE_TAG:-${TAG}} +if [ "$TAG" == "$COMMIT" ]; then + HELM_CHART_VERSION="0.0.0-dev.${COMMIT}" +else + HELM_CHART_VERSION=${HELM_IMAGE_TAG/v/} +fi + if echo "$TAG" | grep -q dirty; then TAG="v0.0.0-dev.1-${COMMIT}" + HELM_IMAGE_TAG=$TAG + HELM_CHART_VERSION=${HELM_CHART_VERSION_DEV:-${HELM_IMAGE_TAG/v/}} fi -IMAGE=${IMAGE:-"$REPO/prometheus-federator:${TAG}"} +IMAGE=${IMAGE:-"$REPO/${BUILD_TARGET}:${TAG}"} function print_version_debug() { + echo "DIRTY: $DIRTY" echo "BUILD_TARGET: $BUILD_TARGET"; echo "SUFFIX: $SUFFIX"; + echo "HELM_IMAGE_TAG: $HELM_IMAGE_TAG"; + echo "HELM_CHART_VERSION: $HELM_CHART_VERSION"; echo "REPO: $REPO; TAG: $TAG"; echo "IMAGE: $IMAGE"; }