From 38d7b5d004688d1b380d12966556ce142ed5a953 Mon Sep 17 00:00:00 2001 From: Argonus <9743549+Argonus@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:26:57 +0100 Subject: [PATCH 1/6] Add resource version parameter for kubernates strategy. --- CHANGELOG.md | 4 ++ lib/strategy/kubernetes.ex | 18 +++++- test/fixtures/vcr_cassettes/kubernetes.json | 32 +++++++++++ .../vcr_cassettes/kubernetes_pods.json | 32 +++++++++++ test/kubernetes_test.exs | 55 +++++++++++++++++++ 5 files changed, 139 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b70566..715af4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Add `kubernates_resource_version` option to Kubernetes strategy + +## 3.4.1 + - Use new cypher names - Allow Epmd strategy to reconnect after connection failures - Detect Self Signed Certificate Authority for Kubernetes Strategy diff --git a/lib/strategy/kubernetes.ex b/lib/strategy/kubernetes.ex index e365699..e4e2c68 100644 --- a/lib/strategy/kubernetes.ex +++ b/lib/strategy/kubernetes.ex @@ -25,6 +25,7 @@ defmodule Cluster.Strategy.Kubernetes do - `:kubernetes_selector` - `:kubernetes_service_name` - `:kubernetes_ip_lookup_mode` + - `:kubernetes_resource_version` - `:mode` ## Getting `` @@ -70,6 +71,12 @@ defmodule Cluster.Strategy.Kubernetes do Then, this strategy will fetch the IP of all pods with that label and attempt to connect. + ### `kubernetes_resource_version` option + + When setting this value, this strategy will use given resource version value to fetch k8s resources, + where each modification of the resource increments the resource version. + + If set to `0` kubernetes will use cached version, that may be outdated. ### `:mode` option @@ -361,6 +368,7 @@ defmodule Cluster.Strategy.Kubernetes do service_name = Keyword.get(config, :kubernetes_service_name) selector = Keyword.fetch!(config, :kubernetes_selector) ip_lookup_mode = Keyword.get(config, :kubernetes_ip_lookup_mode, :endpoints) + resource_version = Keyword.get(config, :kubernetes_resource_version, nil) master_name = Keyword.get(config, :kubernetes_master, @kubernetes_master) cluster_domain = System.get_env("CLUSTER_DOMAIN", "#{cluster_name}.local") @@ -382,10 +390,16 @@ defmodule Cluster.Strategy.Kubernetes do app_name != nil and selector != nil -> selector = URI.encode(selector) + resource_version_param = + if is_nil(resource_version), do: "", else: "&resourceVersion=#{resource_version}" + path = case ip_lookup_mode do - :endpoints -> "api/v1/namespaces/#{namespace}/endpoints?labelSelector=#{selector}" - :pods -> "api/v1/namespaces/#{namespace}/pods?labelSelector=#{selector}" + :endpoints -> + "api/v1/namespaces/#{namespace}/endpoints?labelSelector=#{selector}#{resource_version_param}" + + :pods -> + "api/v1/namespaces/#{namespace}/pods?labelSelector=#{selector}#{resource_version_param}" end headers = [{~c"authorization", ~c"Bearer #{token}"}] diff --git a/test/fixtures/vcr_cassettes/kubernetes.json b/test/fixtures/vcr_cassettes/kubernetes.json index b92ea50..5490851 100644 --- a/test/fixtures/vcr_cassettes/kubernetes.json +++ b/test/fixtures/vcr_cassettes/kubernetes.json @@ -31,6 +31,38 @@ "type": "ok" } }, + { + "request": { + "body": "", + "headers": { + "authorization": "***" + }, + "method": "get", + "options": { + "httpc_options": [], + "http_options": { + "ssl": "[verify: :verify_none]" + } + }, + "request_body": "", + "url": "https://cluster.localhost./api/v1/namespaces/__libcluster_test/endpoints?labelSelector=app=test_selector&resourceVersion=0" + }, + "response": { + "binary": false, + "body": "{\"kind\":\"EndpointsList\",\"apiVersion\":\"v1\",\"metadata\":{\"selfLink\":\"SELFLINK_PLACEHOLDER\",\"resourceVersion\":\"17042410\"},\"items\":[{\"metadata\":{\"name\":\"development-development\",\"namespace\":\"airatel-service-localization\",\"selfLink\":\"SELFLINK_PLACEHOLDER\",\"uid\":\"7e3faf1e-0294-11e8-bcad-42010a9c01cc\",\"resourceVersion\":\"17037787\",\"creationTimestamp\":\"2018-01-26T12:29:03Z\",\"labels\":{\"app\":\"development\",\"chart\":\"CHART_PLACEHOLDER\"}},\"subsets\":[{\"addresses\":[{\"hostname\":\"my-hostname-0\",\"ip\":\"10.48.33.136\",\"nodeName\":\"gke-jshmrtn-cluster-default-pool-a61da41f-db9x\",\"targetRef\":{\"kind\":\"Pod\",\"namespace\":\"airatel-service-localization\",\"name\":\"development-4292695165-mgq9f\",\"uid\":\"eb0f3e80-0295-11e8-bcad-42010a9c01cc\",\"resourceVersion\":\"17037783\"}}],\"ports\":[{\"name\":\"web\",\"port\":8443,\"protocol\":\"TCP\"}]}]}]}\n", + "headers": { + "date": "Fri, 26 Jan 2018 13:18:46 GMT", + "content-length": "877", + "content-type": "application/json" + }, + "status_code": [ + "HTTP/1.1", + 200, + "OK" + ], + "type": "ok" + } + }, { "request": { "body": "", diff --git a/test/fixtures/vcr_cassettes/kubernetes_pods.json b/test/fixtures/vcr_cassettes/kubernetes_pods.json index 222095f..6dcebe9 100644 --- a/test/fixtures/vcr_cassettes/kubernetes_pods.json +++ b/test/fixtures/vcr_cassettes/kubernetes_pods.json @@ -30,5 +30,37 @@ ], "type": "ok" } + }, + { + "request": { + "body": "", + "headers": { + "authorization": "***" + }, + "method": "get", + "options": { + "httpc_options": [], + "http_options": { + "ssl": "[verify: :verify_none]" + } + }, + "request_body": "", + "url": "https://cluster.localhost./api/v1/namespaces/__libcluster_test/pods?labelSelector=app=test_selector&resourceVersion=0" + }, + "response": { + "binary": false, + "body": "{\"kind\":\"PodList\",\"apiVersion\":\"v1\",\"metadata\":{\"selfLink\":\"SELFLINK_PLACEHOLDER\",\"resourceVersion\":\"17042410\"},\"items\":[{\"metadata\":{\"name\":\"development-development\",\"namespace\":\"airatel-service-localization\",\"selfLink\":\"SELFLINK_PLACEHOLDER\",\"uid\":\"7e3faf1e-0294-11e8-bcad-42010a9c01cc\",\"resourceVersion\":\"17037787\",\"creationTimestamp\":\"2018-01-26T12:29:03Z\",\"labels\":{\"app\":\"development\",\"chart\":\"CHART_PLACEHOLDER\"}},\"spec\": { \"hostname\": \"my-hostname-0\" },\"status\":{\"podIP\": \"10.48.33.136\"}}]}\n", + "headers": { + "date": "Fri, 26 Jan 2018 13:18:46 GMT", + "content-length": "877", + "content-type": "application/json" + }, + "status_code": [ + "HTTP/1.1", + 200, + "OK" + ], + "type": "ok" + } } ] diff --git a/test/kubernetes_test.exs b/test/kubernetes_test.exs index 2a86b70..fc37019 100644 --- a/test/kubernetes_test.exs +++ b/test/kubernetes_test.exs @@ -81,6 +81,33 @@ defmodule Cluster.Strategy.KubernetesTest do end end + test "works with resource version" do + use_cassette "kubernetes", custom: true do + capture_log(fn -> + start_supervised!({Kubernetes, + [ + %Cluster.Strategy.State{ + topology: :name, + config: [ + kubernetes_node_basename: "test_basename", + kubernetes_selector: "app=test_selector", + kubernetes_resource_version: 0, + # If you want to run the test freshly, you'll need to create a DNS Entry + kubernetes_master: "cluster.localhost.", + kubernetes_service_account_path: + Path.join([__DIR__, "fixtures", "kubernetes", "service_account"]) + ], + connect: {Nodes, :connect, [self()]}, + disconnect: {Nodes, :disconnect, [self()]}, + list_nodes: {Nodes, :list_nodes, [[]]} + } + ]}) + + assert_receive {:connect, _}, 5_000 + end) + end + end + test "works with dns and cluster_name" do use_cassette "kubernetes", custom: true do capture_log(fn -> @@ -201,6 +228,34 @@ defmodule Cluster.Strategy.KubernetesTest do end end + test "works with pods and resource version" do + use_cassette "kubernetes_pods", custom: true do + capture_log(fn -> + start_supervised!({Kubernetes, + [ + %Cluster.Strategy.State{ + topology: :name, + config: [ + kubernetes_node_basename: "test_basename", + kubernetes_selector: "app=test_selector", + # If you want to run the test freshly, you'll need to create a DNS Entry + kubernetes_master: "cluster.localhost.", + kubernetes_ip_lookup_mode: :pods, + kubernetes_resource_version: 0, + kubernetes_service_account_path: + Path.join([__DIR__, "fixtures", "kubernetes", "service_account"]) + ], + connect: {Nodes, :connect, [self()]}, + disconnect: {Nodes, :disconnect, [self()]}, + list_nodes: {Nodes, :list_nodes, [[]]} + } + ]}) + + assert_receive {:connect, :"test_basename@10.48.33.136"}, 5_000 + end) + end + end + test "works with pods and dns" do use_cassette "kubernetes_pods", custom: true do capture_log(fn -> From 5f93f8b029f57126f4f26bb0003441befe615c19 Mon Sep 17 00:00:00 2001 From: Argonus <9743549+Argonus@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:21:13 +0100 Subject: [PATCH 2/6] Setup priv package --- .github/CODEOWNERS | 1 + .github/ISSUE_TEMPLATE.md | 10 -- .github/PULL_REQUEST_TEMPLATE.md | 11 -- .github/workflows/ci.yaml | 267 +++++++++++++++++++++++++++++ .github/workflows/dev-publish.yaml | 76 ++++++++ .github/workflows/elixir.yml | 60 ------- .gitignore | 2 + mix.exs | 10 +- 8 files changed, 351 insertions(+), 86 deletions(-) create mode 100644 .github/CODEOWNERS delete mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/dev-publish.yaml delete mode 100644 .github/workflows/elixir.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..d797cf4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@surgeventures/developers diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 860ce3f..0000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,10 +0,0 @@ -### Steps to reproduce - -- Configuration Used -- Strategy Used -- Errors/Incorrect Behaviour Encountered - -### Description of issue - -- What are the expected results? -- Is the documentation incorrect? diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ca1b94a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,11 +0,0 @@ -### Summary of changes - -I'll review the commits, so I mostly want to understand the "why" rather than the "what" - -### Checklist - -- [ ] New functions have typespecs, changed functions were updated -- [ ] Same for documentation, including moduledocs -- [ ] Tests were added or updated to cover changes -- [ ] Commits were squashed into a single coherent commit -- [ ] Notes added to CHANGELOG file which describe changes at a high-level diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..5638675 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,267 @@ +name: Elixir CI Checks + +env: + DEBIAN_FRONTEND: noninteractive + DEPENDENCY_FILE: mix.lock + ELIXIR_VERSION: 1.10.4 # Elixir version used during package publishing + JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + OTP_VERSION: 22.3.4.7 # OTP version used during package publishing + RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right + REPOSITORY: fresha_libcluster + RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 + SHA: ${{ github.sha }} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - master + pull_request: + types: + - synchronize + - opened + - reopened + +jobs: + static: + name: Static Checks (Elixir ${{ matrix.elixir }} & OTP ${{ matrix.otp }}) + runs-on: runs-on,runner=2cpu-linux-x64 + outputs: + HASH: ${{ steps.hash.outputs.HASH }} + strategy: + fail-fast: false + matrix: + otp: [22.3.4.7] + elixir: [1.10.4] + runner-os: [ubuntu20] + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ matrix.runner-os }} + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + version-type: strict + - name: Get SHA sum (HASH) of relevant files + id: hash + run: | + git config --global --add safe.directory /__w/${{ env.REPOSITORY }}/${{ env.REPOSITORY }} + echo "Get SHA sum (HASH) of relevant files" + HASH="$(git ls-tree ${{ env.SHA }} -- ${{ env.RELEVANT_FILES }} | sha1sum | cut -d' ' -f1)" + echo "BUILD HASH FOR THE CODEBASE IS: $HASH" + echo "HASH=$HASH" >> $GITHUB_OUTPUT + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + - uses: runs-on/cache@v4 + id: deps-cache + with: + path: | + deps + _build/dev + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-precompile-deps-dev-${{ hashFiles('mix.lock') }} + - name: Install dependencies + if: steps.deps-cache.outputs.cache-hit != 'true' + env: + MIX_ENV: dev + run: | + echo "Installing dependencies" + mix deps.get + mix deps.compile + - uses: runs-on/cache@v4 + id: build-cache + with: + path: '**/*' + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-compile-dev-${{ steps.hash.outputs.HASH }} + - name: Compile with warning as --warnings-as-errors + if: steps.build-cache.outputs.cache-hit != 'true' + run: | + echo "Compiling the app with --warnings-as-errors" + mix compile --warnings-as-errors --force + - name: Run format + run: | + echo "Running format" + mix format --check-formatted --dry-run + - name: Run publish --dry-run + env: + HEX_API_KEY: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + run: | + echo "Running publish --dry-run" + mix hex.publish --dry-run + test: + name: Unit Tests (Elixir ${{ matrix.elixir }} & OTP ${{ matrix.otp }}) + runs-on: runs-on,runner=2cpu-linux-x64 + strategy: + fail-fast: false + matrix: + otp: [22.3.4.7] + elixir: [1.10.4] + runner-os: [ubuntu20] + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ matrix.runner-os }} + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + version-type: strict + - name: Get SHA sum (HASH) of relevant files + id: hash + run: | + git config --global --add safe.directory /__w/${{ env.REPOSITORY }}/${{ env.REPOSITORY }} + echo "Get SHA sum (HASH) of relevant files" + HASH="$(git ls-tree ${{ env.SHA }} -- ${{ env.RELEVANT_FILES }} | sha1sum | cut -d' ' -f1)" + echo "BUILD HASH FOR THE CODEBASE IS: $HASH" + echo "HASH=$HASH" >> $GITHUB_OUTPUT + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + - uses: runs-on/cache@v4 + id: deps-cache + with: + path: | + deps + _build/test + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-precompile-deps-test-${{ hashFiles('mix.lock') }} + - name: Install dependencies + if: steps.deps-cache.outputs.cache-hit != 'true' + env: + MIX_ENV: test + run: | + echo "Installing dependencies" + mix deps.get + mix deps.compile + - uses: runs-on/cache@v4 + id: build-cache + with: + path: '**/*' + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-compile-test-${{ steps.hash.outputs.HASH }} + - name: Compile with MIX_ENV=test + if: steps.build-cache.outputs.cache-hit != 'true' + env: + MIX_ENV: test + run: | + echo "Compiling the app with MIX_ENV=test" + mix compile --force + - name: Run tests + run: | + echo "Running tests" + mix test --cover + permit: + name: Permit Package Publishing + needs: [static, test] + runs-on: runs-on,runner=1cpu-linux-x64 + outputs: + PUBLISH: ${{ steps.version.outputs.PUBLISH }} + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + fetch-depth: 2 + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Create Approval File + shell: bash + run: | + echo "CI Checks Passed for SHA ${{ env.SHA }} and HASH ${{ needs.static.outputs.HASH }}" > approval.txt + - name: Process Package Version + shell: bash + id: version + run: | + echo "===============================================" + echo "" + git show HEAD~1:mix.exs > mix.old.exs + diff mix.old.exs mix.exs > diff.txt || true + old_version=$(grep -oP 'version: "\K[^"]+' mix.old.exs) + new_version=$(grep -oP 'version: "\K[^"]+' mix.exs) + echo "Old Version: $old_version | New Version: $new_version" + if [ "$new_version" != "$old_version" ]; then + if [ "$new_version" \> "$old_version" ]; then + echo "Version is upped - WILL publish upon merging the PR" + echo "PUBLISH=true" >> $GITHUB_OUTPUT + else + echo "Version is lower than the original version - blocking publication" + echo "PUBLISH=false" >> $GITHUB_OUTPUT + exit 1 + fi + else + echo "PUBLISH=false" >> $GITHUB_OUTPUT + echo "Version is unchanged - WONT publish upon merging the PR" + fi + echo "" + echo "===============================================" + - name: Cache Approval File + uses: runs-on/cache/save@v4 + with: + path: approval.txt + key: ${{ runner.os }}-${{ env.REPOSITORY }}-approval-${{ needs.static.outputs.HASH }} + + publish: + name: Publish Hex Package + needs: [permit] + runs-on: runs-on,runner=2cpu-linux-x64 + if: needs.permit.outputs.PUBLISH == 'true' && github.event_name == 'push' + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ env.RUNNER_OS }} + with: + elixir-version: ${{ env.ELIXIR_VERSION }} + otp-version: ${{ env.OTP_VERSION }} + version-type: strict + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + shell: bash + - name: Get dependencies + shell: bash + run: | + echo "Getting dependencies" + mix deps.get + - name: Publish dev package + shell: bash + env: + HEX_API_KEY: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + run: | + echo "Publishing package" + mix hex.publish --yes + + + check_release: + runs-on: runs-on,runner=2cpu-linux-x64 + name: Check release + container: + image: elixir:1.10-slim + steps: + - uses: actions/checkout@v4 + - name: Install Dependencies + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + - name: Build hex + run: mix hex.build + - name: Generate docs + run: mix docs diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml new file mode 100644 index 0000000..b6fa44f --- /dev/null +++ b/.github/workflows/dev-publish.yaml @@ -0,0 +1,76 @@ +name: Elixir Dev Publish + +env: + DEBIAN_FRONTEND: noninteractive + DEPENDENCY_FILE: mix.lock + ELIXIR_VERSION: 1.11.4 # Elixir version used during package publishing + JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + OTP_VERSION: 23.3.4.7 # OTP version used during package publishing + RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right + REPOSITORY: fresha_libcluster + RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 + SHA: ${{ github.sha }} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + workflow_dispatch: + inputs: {} + +jobs: + dev-publish: + name: Dev Publish + runs-on: runs-on,runner=4cpu-linux-x64 + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.sha }} + clean: false + persist-credentials: true + - name: Get SHA sum (HASH) of relevant files + id: hash + shell: bash + run: | + git config --global --add safe.directory /__w/${{ env.REPOSITORY }}/${{ env.REPOSITORY }} + echo "Get SHA sum (HASH) of relevant files" + HASH="$(git ls-tree ${{ env.SHA }} -- ${{ env.RELEVANT_FILES }} | sha1sum | cut -d' ' -f1)" + echo "BUILD HASH FOR THE CODEBASE IS: $HASH" + echo "IT WILL BE USED TO DETERMINE ELIGIBILITY OF THE CODEBASE FOR THE RELEASE" + echo "APPROVAL PRODUCED BY SUCCESSFULL CHECKS EXECUTION WILL LAND IN CACHE" + echo "HASH=$HASH" >> $GITHUB_OUTPUT + - name: Check for CI successes + uses: runs-on/cache/restore@v4 + with: + key: ${{ runner.os }}-${{ env.REPOSITORY }}-approval-${{ steps.hash.outputs.HASH }} + path: approval.txt + fail-on-cache-miss: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ env.RUNNER_OS }} + with: + elixir-version: ${{ env.ELIXIR_VERSION }} + otp-version: ${{ env.OTP_VERSION }} + version-type: strict + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + shell: bash + - name: Get dependencies + shell: bash + run: | + echo "Getting dependencies" + mix deps.get + - name: Mark package version with dev suffix + shell: bash + run: | + sed -i "s/version: \"[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/&-git-$(git rev-parse --verify --short=4 HEAD)/" mix.exs + - name: Publish dev package + shell: bash + env: + HEX_API_KEY: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + run: | + echo "Publishing dev package" + mix hex.publish --yes diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml deleted file mode 100644 index 39d5ac5..0000000 --- a/.github/workflows/elixir.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: elixir - -on: - pull_request: - push: - branches: - - main - -jobs: - test: - runs-on: ubuntu-20.04 - env: - MIX_ENV: test - strategy: - fail-fast: false - matrix: - include: - - pair: - elixir: "1.13" - otp: "22" - - pair: - elixir: "1.17" - otp: "27" - lint: lint - steps: - - uses: actions/checkout@v4 - - - uses: erlef/setup-beam@v1 - with: - otp-version: ${{matrix.pair.otp}} - elixir-version: ${{matrix.pair.elixir}} - - - uses: actions/cache@v4 - with: - path: | - deps - _build - key: ${{ runner.os }}-mix-${{matrix.pair.elixir}}-${{matrix.pair.otp}}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{matrix.pair.elixir}}-${{matrix.pair.otp}}- - - - run: mix deps.get --only test - - - run: mix format --check-formatted - if: ${{ matrix.lint }} - - - run: mix deps.get && mix deps.unlock --check-unused - if: ${{ matrix.lint }} - - - run: mix deps.compile - - # TODO: disable for now due to upstream error with ExVCR - # warning: redefining module ExVCR.Adapter.Httpc.Converter (current - # version loaded from - # _build/test/lib/exvcr/ebin/Elixir.ExVCR.Adapter.Httpc.Converter.beam) - - # - run: mix compile --warnings-as-errors - # if: ${{ matrix.lint }} - - - run: mix test diff --git a/.gitignore b/.gitignore index 832f2c9..cd1cbba 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ libcluster-*.tar # Misc. /priv/test/service_account/* !/priv/test/service_account/.gitkeep +/libcluster.iml +/.idea/ diff --git a/mix.exs b/mix.exs index ac11878..5931fbb 100644 --- a/mix.exs +++ b/mix.exs @@ -1,19 +1,19 @@ defmodule Cluster.Mixfile do use Mix.Project - @version "3.4.1" + @version "4.0.0" @source_url "https://github.com/bitwalker/libcluster" def project do [ - app: :libcluster, + app: :fresha_libcluster, version: @version, elixir: "~> 1.13", build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, description: """ - Automatic Erlang cluster formation and management for Elixir/Erlang - applications + Automatic Erlang cluster formation and management for Elixir/Erlang + applications. Fork of Bitwalker's libcluster with additional features. """, package: package(), docs: docs(), @@ -48,7 +48,7 @@ defmodule Cluster.Mixfile do defp package do [ files: ["lib", "mix.exs", "README.md", "LICENSE.md", "CHANGELOG.md"], - maintainers: ["Paul Schoenfelder"], + maintainers: ["Piotr Rybarczyk"], licenses: ["MIT"], links: %{ "Changelog" => "https://hexdocs.pm/libcluster/changelog.html", From 383ac569fa4b7c396e6cf561880476da2a854d57 Mon Sep 17 00:00:00 2001 From: Argonus <9743549+Argonus@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:26:38 +0100 Subject: [PATCH 3/6] Rename repo --- .github/workflows/ci.yaml | 2 +- .github/workflows/dev-publish.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5638675..7a40358 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,7 @@ env: JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} OTP_VERSION: 22.3.4.7 # OTP version used during package publishing RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right - REPOSITORY: fresha_libcluster + REPOSITORY: libcluster RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 SHA: ${{ github.sha }} diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml index b6fa44f..f17c6d3 100644 --- a/.github/workflows/dev-publish.yaml +++ b/.github/workflows/dev-publish.yaml @@ -7,7 +7,7 @@ env: JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} OTP_VERSION: 23.3.4.7 # OTP version used during package publishing RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right - REPOSITORY: fresha_libcluster + REPOSITORY: libcluster RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 SHA: ${{ github.sha }} From 103931ef7a3be732ba7f7a8ebfce294fd7456452 Mon Sep 17 00:00:00 2001 From: Argonus <9743549+Argonus@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:29:23 +0100 Subject: [PATCH 4/6] Fix elixir & package name --- .github/workflows/ci.yaml | 8 ++++---- .github/workflows/dev-publish.yaml | 2 +- mix.exs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7a40358..1c0c20b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,7 +3,7 @@ name: Elixir CI Checks env: DEBIAN_FRONTEND: noninteractive DEPENDENCY_FILE: mix.lock - ELIXIR_VERSION: 1.10.4 # Elixir version used during package publishing + ELIXIR_VERSION: 1.13.0 # Elixir version used during package publishing JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} OTP_VERSION: 22.3.4.7 # OTP version used during package publishing RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right @@ -35,7 +35,7 @@ jobs: fail-fast: false matrix: otp: [22.3.4.7] - elixir: [1.10.4] + elixir: [1.13.0] runner-os: [ubuntu20] steps: - name: Checkout latest codebase @@ -104,7 +104,7 @@ jobs: fail-fast: false matrix: otp: [22.3.4.7] - elixir: [1.10.4] + elixir: [1.13.0] runner-os: [ubuntu20] steps: - name: Checkout latest codebase @@ -253,7 +253,7 @@ jobs: runs-on: runs-on,runner=2cpu-linux-x64 name: Check release container: - image: elixir:1.10-slim + image: elixir:1.13-slim steps: - uses: actions/checkout@v4 - name: Install Dependencies diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml index f17c6d3..ae30386 100644 --- a/.github/workflows/dev-publish.yaml +++ b/.github/workflows/dev-publish.yaml @@ -3,7 +3,7 @@ name: Elixir Dev Publish env: DEBIAN_FRONTEND: noninteractive DEPENDENCY_FILE: mix.lock - ELIXIR_VERSION: 1.11.4 # Elixir version used during package publishing + ELIXIR_VERSION: 1.13.0 # Elixir version used during package publishing JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} OTP_VERSION: 23.3.4.7 # OTP version used during package publishing RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right diff --git a/mix.exs b/mix.exs index 5931fbb..7ae1fdc 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,7 @@ defmodule Cluster.Mixfile do def project do [ - app: :fresha_libcluster, + app: :libcluster, version: @version, elixir: "~> 1.13", build_embedded: Mix.env() == :prod, From 76dba5558e77dafcb8415a186c9f48221d7bee30 Mon Sep 17 00:00:00 2001 From: Argonus <9743549+Argonus@users.noreply.github.com> Date: Tue, 3 Dec 2024 08:18:59 +0100 Subject: [PATCH 5/6] Fix package --- mix.exs | 5 +++++ test/support/telemetry.ex | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index 7ae1fdc..731105c 100644 --- a/mix.exs +++ b/mix.exs @@ -19,6 +19,11 @@ defmodule Cluster.Mixfile do docs: docs(), deps: deps(), elixirc_paths: elixirc_paths(Mix.env()), + test_coverage: [ + summary: [ + threshold: 60 + ] + ], dialyzer: [ flags: ~w(-Wunmatched_returns -Werror_handling -Wrace_conditions -Wno_opaque -Wunderspecs) ], diff --git a/test/support/telemetry.ex b/test/support/telemetry.ex index d4ada00..f213800 100644 --- a/test/support/telemetry.ex +++ b/test/support/telemetry.ex @@ -1,8 +1,6 @@ defmodule Cluster.Telemetry do @moduledoc false - use ExUnit.Case - def setup_telemetry(event) do telemetry_handle_id = "test-telemetry-handler-#{inspect(self())}" @@ -16,7 +14,7 @@ defmodule Cluster.Telemetry do nil ) - :ok = on_exit(fn -> :telemetry.detach(telemetry_handle_id) end) + :ok = ExUnit.Callbacks.on_exit(fn -> :telemetry.detach(telemetry_handle_id) end) end defp send_to_pid(event, measurements, metadata, config) do From a64f7550013cae9f1b44dc3e079b2a40b1ff94ed Mon Sep 17 00:00:00 2001 From: Argonus <9743549+Argonus@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:56:28 +0100 Subject: [PATCH 6/6] Update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ea078c..e2a7473 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# libcluster +# libcluster - Fork of original libcluster +Used to support AWS k8s cluster cache [![Build Status](https://github.com/bitwalker/libcluster/workflows/elixir/badge.svg?branch=main)](https://github.com/bitwalker/libcluster/actions?query=workflow%3A%22elixir%22+branch%3Amain) [![Module Version](https://img.shields.io/hexpm/v/libcluster.svg)](https://hex.pm/packages/libcluster)