├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── codeql.yml │ ├── merge.yml │ └── release.yml ├── .gitignore ├── .goreleaser.yml ├── .vscode ├── extensions.json └── settings.json ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets └── grafana-dashboard.json ├── build └── package │ └── Dockerfile ├── cmd └── root.go ├── go.mod ├── go.sum ├── internal ├── api │ ├── api.go │ └── health.go ├── ingress │ └── ingress.go ├── k8s │ ├── handlers.go │ └── k8s.go ├── metrics │ └── metrics.go ├── proto │ ├── read.go │ ├── read_test.go │ └── types.go └── routing │ ├── route.go │ └── router.go ├── main.go └── pkg ├── build └── version.go └── config ├── api.go ├── cli.go ├── ingress.go └── k8s.go /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/go/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Go version: 1, 1.16, 1.15 4 | ARG VARIANT="1.16" 5 | FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT} 6 | 7 | # [Option] Install Node.js 8 | ARG INSTALL_NODE="true" 9 | ARG NODE_VERSION="lts/*" 10 | RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 11 | 12 | # [Optional] Uncomment this section to install additional OS packages. 13 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 14 | # && apt-get -y install --no-install-recommends 15 | 16 | # [Optional] Uncomment the next line to use go get to install anything else you need 17 | # RUN go get -x 18 | 19 | # [Optional] Uncomment this line to install global node packages. 20 | # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/go 3 | { 4 | "name": "Go", 5 | "build": { 6 | "dockerfile": "Dockerfile", 7 | "args": { 8 | // Update the VARIANT arg to pick a version of Go: 1, 1.16, 1.15 9 | "VARIANT": "1.16", 10 | // Options 11 | "INSTALL_NODE": "false", 12 | "NODE_VERSION": "lts/*" 13 | } 14 | }, 15 | "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], 16 | 17 | // Set *default* container specific settings.json values on container create. 18 | "settings": { 19 | "go.toolsManagement.checkForUpdates": "local", 20 | "go.useLanguageServer": true, 21 | "go.gopath": "/go", 22 | "go.goroot": "/usr/local/go" 23 | }, 24 | 25 | // Add the IDs of extensions you want installed when the container is created. 26 | "extensions": [ 27 | "golang.Go" 28 | ], 29 | 30 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 31 | // "forwardPorts": [], 32 | 33 | // Use 'postCreateCommand' to run commands after the container is created. 34 | // "postCreateCommand": "go version", 35 | 36 | // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 37 | "remoteUser": "vscode" 38 | } 39 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @0skillallluck 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Pull Request 3 | about: Create a Pull Request 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Issue** 11 | Fixes #{ issue number } 12 | 13 | **What this PR Includes** 14 | A short description of what this PR does. 15 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: docker 4 | directory: "/build/package/" 5 | schedule: 6 | interval: daily 7 | time: "04:00" 8 | open-pull-requests-limit: 10 9 | - package-ecosystem: github-actions 10 | directory: "/" 11 | schedule: 12 | interval: daily 13 | time: "04:00" 14 | open-pull-requests-limit: 10 15 | - package-ecosystem: gomod 16 | directory: "/" 17 | schedule: 18 | interval: daily 19 | time: "04:00" 20 | open-pull-requests-limit: 10 21 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - release-* 8 | pull_request: 9 | branches: 10 | - master 11 | - release-* 12 | schedule: 13 | - cron: '15 16 * * 1' 14 | 15 | jobs: 16 | analyze: 17 | name: Analyze 18 | runs-on: ubuntu-latest 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | language: [ 'go' ] 24 | 25 | steps: 26 | - name: Checkout repository 27 | uses: actions/checkout@v4 28 | 29 | - name: Initialize CodeQL 30 | uses: github/codeql-action/init@v3 31 | with: 32 | languages: ${{ matrix.language }} 33 | 34 | - name: Autobuild 35 | uses: github/codeql-action/autobuild@v3 36 | 37 | - name: Perform CodeQL Analysis 38 | uses: github/codeql-action/analyze@v3 -------------------------------------------------------------------------------- /.github/workflows/merge.yml: -------------------------------------------------------------------------------- 1 | name: Merge 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | check_for_merge_commit: 8 | name: mergeable 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Run git checkout 12 | uses: actions/checkout@v4 13 | with: 14 | fetch-depth: 0 15 | 16 | - name: Check if PR has Merge Commits 17 | run: | 18 | merge=$(git log ${{github.event.pull_request.base.sha}}..${{github.event.pull_request.head.sha}} --oneline --merges) 19 | if [[ ! -z ${merge} ]]; then 20 | # PR contains merge commits 21 | echo "merge commit detected in pull request!" 22 | exit 1 23 | fi -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | goreleaser: 10 | runs-on: ubuntu-latest 11 | env: 12 | DOCKER_CLI_EXPERIMENTAL: "enabled" 13 | DOCKER_BUILDKIT: "1" 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | - name: Unshallow 18 | run: git fetch --prune --unshallow 19 | 20 | - name: Allow Docker ARM builds # https://github.com/linuxkit/linuxkit/tree/master/pkg/binfmt 21 | run: sudo docker run --privileged linuxkit/binfmt:v0.8 22 | 23 | - name: Docker Login 24 | uses: docker/login-action@v3.4.0 25 | with: 26 | registry: docker.io 27 | username: ${{ secrets.DOCKER_USERNAME }} 28 | password: ${{ secrets.DOCKER_PASSWORD }} 29 | 30 | - name: Set up Go 31 | uses: actions/setup-go@v5 32 | with: 33 | go-version: 1.19.x 34 | 35 | - name: GoReleaser 36 | uses: goreleaser/goreleaser-action@v6.3.0 37 | with: 38 | version: latest 39 | args: release --rm-dist 40 | env: 41 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 42 | DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} 43 | DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} 44 | 45 | - name: Cleanup 46 | run: rm -rf ${HOME}/.docker -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | /vendor/ 16 | /dist/ 17 | /ingress-controller 18 | /ingress-controller.exe -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | project_name: ingress-controller 2 | release: 3 | github: 4 | owner: qumine 5 | name: ingress-controller 6 | prerelease: auto 7 | before: 8 | hooks: 9 | - go mod download 10 | builds: 11 | - goos: 12 | - linux 13 | goarch: 14 | - amd64 15 | - arm64 16 | goarm: 17 | - 6 18 | - 7 19 | binary: ingress-controller 20 | env: 21 | - CGO_ENABLED=0 22 | ldflags: 23 | - -s 24 | - -w 25 | - -X github.com/qumine/ingress-controller/pkg/build.version={{ .Version }} 26 | - -X github.com/qumine/ingress-controller/pkg/build.commit={{ .FullCommit }} 27 | - -X github.com/qumine/ingress-controller/pkg/build.date={{ .Date }} 28 | archives: 29 | - id: tar_gz 30 | format: tar.gz 31 | format_overrides: 32 | - goos: windows 33 | format: zip 34 | name_template: '{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' 35 | files: 36 | - LICENSE* 37 | - README* 38 | snapshot: 39 | name_template: SNAPSHOT-{{ .Commit }} 40 | dockers: 41 | - dockerfile: build/package/Dockerfile 42 | image_templates: 43 | - "qumine/ingress-controller:latest-amd64" 44 | - "qumine/ingress-controller:{{.Tag}}-amd64" 45 | goos: linux 46 | goarch: amd64 47 | ids: 48 | - ingress-controller 49 | build_flag_templates: 50 | - "--build-arg=ARCH=amd64/" 51 | - "--label=org.opencontainers.image.title={{ .ProjectName }}" 52 | - "--label=org.opencontainers.image.description={{ .ProjectName }}" 53 | - "--label=org.opencontainers.image.url=https://github.com/qumine/ingress-controller" 54 | - "--label=org.opencontainers.image.source=https://github.com/qumine/ingress-controller" 55 | - "--label=org.opencontainers.image.version={{ .Version }}" 56 | - "--label=org.opencontainers.image.created={{ .Date }}" 57 | - "--label=org.opencontainers.image.revision={{ .FullCommit }}" 58 | - "--label=org.opencontainers.image.licenses=AGPL-3.0" 59 | - dockerfile: build/package/Dockerfile 60 | image_templates: 61 | - "qumine/ingress-controller:latest-arm64v8" 62 | - "qumine/ingress-controller:{{.Tag}}-arm64v8" 63 | goos: linux 64 | goarch: arm64 65 | ids: 66 | - ingress-controller 67 | build_flag_templates: 68 | - "--build-arg=ARCH=arm64v8/" 69 | - "--label=org.opencontainers.image.title={{ .ProjectName }}" 70 | - "--label=org.opencontainers.image.description={{ .ProjectName }}" 71 | - "--label=org.opencontainers.image.url=https://github.com/qumine/ingress-controller" 72 | - "--label=org.opencontainers.image.source=https://github.com/qumine/ingress-controller" 73 | - "--label=org.opencontainers.image.version={{ .Version }}" 74 | - "--label=org.opencontainers.image.created={{ .Date }}" 75 | - "--label=org.opencontainers.image.revision={{ .FullCommit }}" 76 | - "--label=org.opencontainers.image.licenses=AGPL-3.0" 77 | docker_manifests: 78 | - name_template: qumine/ingress-controller:latest 79 | image_templates: 80 | - qumine/ingress-controller:latest-amd64 81 | - qumine/ingress-controller:latest-arm64v8 82 | - name_template: qumine/ingress-controller:{{.Tag}} 83 | image_templates: 84 | - qumine/ingress-controller:{{.Tag}}-amd64 85 | - qumine/ingress-controller:{{.Tag}}-arm64v8 86 | changelog: 87 | filters: 88 | exclude: 89 | - '^ci:' 90 | - '^docs:' 91 | - '^misc:' 92 | - '^test:' 93 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "golang.Go" 4 | ] 5 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "go.toolsManagement.checkForUpdates": "local", 3 | "go.useLanguageServer": true 4 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | dev@qumine.io. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, you can first discuss the change you wish to make via issue, 4 | email, or any other method with the maintainers of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | QuMine - Ingress 2 | --- 3 | ![GitHub Release](https://img.shields.io/github/v/release/qumine/ingress-controller) 4 | ![GitHub Workflow](https://img.shields.io/github/workflow/status/qumine/ingress-controller/release) 5 | [![GoDoc](https://godoc.org/github.com/qumine/ingress-controller?status.svg)](https://godoc.org/github.com/qumine/ingress-controller) 6 | [![Go Report Card](https://goreportcard.com/badge/github.com/qumine/ingress-controller)](https://goreportcard.com/report/github.com/qumine/ingress-controller) 7 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=qumine_minecraft-server&metric=alert_status)](https://sonarcloud.io/dashboard?id=qumine_ingress-controller) 8 | 9 | Kubernetes ingress controller for routing Minecraft connections based on the requested hostname 10 | 11 | # Usage 12 | 13 | ## Kubernetes 14 | 15 | *HELM Charts can be found here: [qumine/charts](https://github.com/qumine/charts)* 16 | 17 | ### Ingress 18 | 19 | *The ingress should be run as a daemonset on all of your outwards facing nodes.* 20 | 21 | By default the ingress should run fine without customization, but if you need to the behaviour of the ingress can be customized by setting a couple of arguments. Here is the full list of available arguments. 22 | 23 | ``` 24 | Usage: 25 | ingress-controller [flags] 26 | 27 | Flags: 28 | --api-host string Host for the API server to listen on (default "0.0.0.0") 29 | --api-port int Port for the API server to listen on (default 8080) 30 | -d, --debug Debug logging 31 | -h, --help help for ingress-controller 32 | --host string Host for the API server to listen on (default "0.0.0.0") 33 | --kube-config string KubeConfig path 34 | --port int Port for the API server to listen on (default 25565) 35 | --trace Trace logging 36 | -v, --version version for ingress-controller 37 | ``` 38 | 39 | **All configuration options can also be set via environment variables** 40 | 41 | ### Upstream Services 42 | 43 | To enable a service to be discovered by the ingress it needs to have the ```ingress.qumine.io/hostname``` annotations. 44 | Optionaly you can set the ```ingress.qumine.io/portname``` annotation to define which port will be used for the minecraft connection. 45 | 46 | ```yaml 47 | apiVersion: v1 48 | kind: Service 49 | metadata: 50 | name: example 51 | annotations: 52 | ingress.qumine.io/hostname: "example" 53 | ingress.qumine.io/portname: "minecraft" 54 | spec: 55 | ports: 56 | - port: 25565 57 | name: minecraft 58 | selector: 59 | app: example 60 | ``` 61 | 62 | ## Outside of Kubernetes 63 | 64 | If you want to run the ingress outside of kubernetes you can do so by providing the ```--kube-config``` flag or environment variable. Keep in mind tho that the routing towards the internal kubernetes services needs to be configured. 65 | 66 | ``` 67 | ./ingress-controller --kube-config ~/.kube/config 68 | ``` 69 | 70 | # Development 71 | 72 | ## Perfrom a Snapshot release locally 73 | 74 | ``` 75 | docker run -it --rm \ 76 | -v ${PWD}:/build -w /build \ 77 | -v /var/run/docker.sock:/var/run/docker.sock \ 78 | goreleaser/goreleaser \ 79 | release --snapshot --rm-dist 80 | ``` -------------------------------------------------------------------------------- /assets/grafana-dashboard.json: -------------------------------------------------------------------------------- 1 | { 2 | "__requires": [ 3 | { 4 | "type": "grafana", 5 | "id": "grafana", 6 | "name": "Grafana", 7 | "version": "7.4.5" 8 | }, 9 | { 10 | "type": "panel", 11 | "id": "graph", 12 | "name": "Graph", 13 | "version": "" 14 | }, 15 | { 16 | "type": "datasource", 17 | "id": "prometheus", 18 | "name": "Prometheus", 19 | "version": "1.0.0" 20 | }, 21 | { 22 | "type": "panel", 23 | "id": "stat", 24 | "name": "Stat", 25 | "version": "" 26 | } 27 | ], 28 | "annotations": { 29 | "list": [] 30 | }, 31 | "editable": true, 32 | "gnetId": null, 33 | "graphTooltip": 0, 34 | "id": null, 35 | "iteration": 1627078452841, 36 | "links": [], 37 | "panels": [ 38 | { 39 | "cacheTimeout": null, 40 | "datasource": "${datasource}", 41 | "fieldConfig": { 42 | "defaults": { 43 | "color": { 44 | "mode": "thresholds" 45 | }, 46 | "custom": {}, 47 | "links": [], 48 | "mappings": [], 49 | "thresholds": { 50 | "mode": "absolute", 51 | "steps": [ 52 | { 53 | "color": "green", 54 | "value": null 55 | }, 56 | { 57 | "color": "red", 58 | "value": 80 59 | } 60 | ] 61 | } 62 | }, 63 | "overrides": [] 64 | }, 65 | "gridPos": { 66 | "h": 7, 67 | "w": 8, 68 | "x": 0, 69 | "y": 0 70 | }, 71 | "id": 15, 72 | "links": [], 73 | "options": { 74 | "colorMode": "value", 75 | "graphMode": "area", 76 | "justifyMode": "auto", 77 | "orientation": "auto", 78 | "reduceOptions": { 79 | "calcs": [ 80 | "lastNotNull" 81 | ], 82 | "fields": "", 83 | "values": false 84 | }, 85 | "text": {}, 86 | "textMode": "auto" 87 | }, 88 | "pluginVersion": "7.4.5", 89 | "targets": [ 90 | { 91 | "expr": "avg(qumine_ingress_routes{namespace=\"$namespace\"})", 92 | "instant": true, 93 | "interval": "", 94 | "legendFormat": "Total", 95 | "refId": "A" 96 | } 97 | ], 98 | "timeFrom": null, 99 | "timeShift": null, 100 | "title": "Registered Routes", 101 | "type": "stat" 102 | }, 103 | { 104 | "aliasColors": {}, 105 | "bars": false, 106 | "cacheTimeout": null, 107 | "dashLength": 10, 108 | "dashes": false, 109 | "datasource": "${datasource}", 110 | "fieldConfig": { 111 | "defaults": { 112 | "custom": {}, 113 | "links": [] 114 | }, 115 | "overrides": [] 116 | }, 117 | "fill": 1, 118 | "fillGradient": 0, 119 | "gridPos": { 120 | "h": 7, 121 | "w": 16, 122 | "x": 8, 123 | "y": 0 124 | }, 125 | "hiddenSeries": false, 126 | "id": 2, 127 | "legend": { 128 | "avg": false, 129 | "current": false, 130 | "max": false, 131 | "min": false, 132 | "show": true, 133 | "total": false, 134 | "values": false 135 | }, 136 | "lines": true, 137 | "linewidth": 1, 138 | "links": [], 139 | "nullPointMode": "null", 140 | "options": { 141 | "alertThreshold": true 142 | }, 143 | "percentage": false, 144 | "pluginVersion": "7.4.5", 145 | "pointradius": 2, 146 | "points": false, 147 | "renderer": "flot", 148 | "seriesOverrides": [], 149 | "spaceLength": 10, 150 | "stack": false, 151 | "steppedLine": false, 152 | "targets": [ 153 | { 154 | "expr": "qumine_ingress_routes{namespace=\"$namespace\"}", 155 | "instant": false, 156 | "interval": "", 157 | "legendFormat": "{{pod}}", 158 | "refId": "A" 159 | } 160 | ], 161 | "thresholds": [], 162 | "timeFrom": null, 163 | "timeRegions": [], 164 | "timeShift": null, 165 | "title": "Registered Routes", 166 | "tooltip": { 167 | "shared": true, 168 | "sort": 0, 169 | "value_type": "individual" 170 | }, 171 | "type": "graph", 172 | "xaxis": { 173 | "buckets": null, 174 | "mode": "time", 175 | "name": null, 176 | "show": true, 177 | "values": [] 178 | }, 179 | "yaxes": [ 180 | { 181 | "format": "short", 182 | "label": null, 183 | "logBase": 1, 184 | "max": null, 185 | "min": null, 186 | "show": true 187 | }, 188 | { 189 | "format": "short", 190 | "label": null, 191 | "logBase": 1, 192 | "max": null, 193 | "min": null, 194 | "show": true 195 | } 196 | ], 197 | "yaxis": { 198 | "align": false, 199 | "alignLevel": null 200 | } 201 | }, 202 | { 203 | "cacheTimeout": null, 204 | "datasource": "${datasource}", 205 | "fieldConfig": { 206 | "defaults": { 207 | "color": { 208 | "mode": "thresholds" 209 | }, 210 | "custom": {}, 211 | "links": [], 212 | "mappings": [], 213 | "thresholds": { 214 | "mode": "absolute", 215 | "steps": [ 216 | { 217 | "color": "green", 218 | "value": null 219 | }, 220 | { 221 | "color": "red", 222 | "value": 80 223 | } 224 | ] 225 | } 226 | }, 227 | "overrides": [] 228 | }, 229 | "gridPos": { 230 | "h": 7, 231 | "w": 8, 232 | "x": 0, 233 | "y": 7 234 | }, 235 | "id": 11, 236 | "links": [], 237 | "options": { 238 | "colorMode": "value", 239 | "graphMode": "area", 240 | "justifyMode": "auto", 241 | "orientation": "auto", 242 | "reduceOptions": { 243 | "calcs": [ 244 | "lastNotNull" 245 | ], 246 | "fields": "", 247 | "values": false 248 | }, 249 | "text": {}, 250 | "textMode": "auto" 251 | }, 252 | "pluginVersion": "7.4.5", 253 | "targets": [ 254 | { 255 | "expr": "sum(qumine_ingress_connections{namespace=\"$namespace\"})", 256 | "interval": "", 257 | "legendFormat": "Total", 258 | "refId": "A" 259 | } 260 | ], 261 | "timeFrom": null, 262 | "timeShift": null, 263 | "title": "Connections", 264 | "type": "stat" 265 | }, 266 | { 267 | "aliasColors": {}, 268 | "bars": false, 269 | "cacheTimeout": null, 270 | "dashLength": 10, 271 | "dashes": false, 272 | "datasource": "${datasource}", 273 | "fieldConfig": { 274 | "defaults": { 275 | "custom": {}, 276 | "links": [] 277 | }, 278 | "overrides": [] 279 | }, 280 | "fill": 1, 281 | "fillGradient": 0, 282 | "gridPos": { 283 | "h": 7, 284 | "w": 16, 285 | "x": 8, 286 | "y": 7 287 | }, 288 | "hiddenSeries": false, 289 | "id": 16, 290 | "legend": { 291 | "alignAsTable": false, 292 | "avg": false, 293 | "current": false, 294 | "max": false, 295 | "min": false, 296 | "show": true, 297 | "total": false, 298 | "values": false 299 | }, 300 | "lines": true, 301 | "linewidth": 1, 302 | "links": [], 303 | "nullPointMode": "null", 304 | "options": { 305 | "alertThreshold": true 306 | }, 307 | "percentage": false, 308 | "pluginVersion": "7.4.5", 309 | "pointradius": 2, 310 | "points": false, 311 | "renderer": "flot", 312 | "seriesOverrides": [], 313 | "spaceLength": 10, 314 | "stack": false, 315 | "steppedLine": false, 316 | "targets": [ 317 | { 318 | "expr": "sum(qumine_ingress_connections{namespace=\"$namespace\"})", 319 | "interval": "", 320 | "legendFormat": "Total", 321 | "refId": "A" 322 | }, 323 | { 324 | "expr": "sum(qumine_ingress_connections{namespace=\"$namespace\"}) by (pod)", 325 | "interval": "", 326 | "legendFormat": "{{pod}}", 327 | "refId": "B" 328 | } 329 | ], 330 | "thresholds": [], 331 | "timeFrom": null, 332 | "timeRegions": [], 333 | "timeShift": null, 334 | "title": "Connections", 335 | "tooltip": { 336 | "shared": true, 337 | "sort": 0, 338 | "value_type": "individual" 339 | }, 340 | "type": "graph", 341 | "xaxis": { 342 | "buckets": null, 343 | "mode": "time", 344 | "name": null, 345 | "show": true, 346 | "values": [] 347 | }, 348 | "yaxes": [ 349 | { 350 | "format": "short", 351 | "label": null, 352 | "logBase": 1, 353 | "max": null, 354 | "min": "0", 355 | "show": true 356 | }, 357 | { 358 | "format": "short", 359 | "label": null, 360 | "logBase": 1, 361 | "max": null, 362 | "min": null, 363 | "show": true 364 | } 365 | ], 366 | "yaxis": { 367 | "align": false, 368 | "alignLevel": null 369 | } 370 | }, 371 | { 372 | "datasource": "${datasource}", 373 | "fieldConfig": { 374 | "defaults": { 375 | "color": { 376 | "mode": "thresholds" 377 | }, 378 | "custom": {}, 379 | "links": [], 380 | "mappings": [], 381 | "thresholds": { 382 | "mode": "absolute", 383 | "steps": [ 384 | { 385 | "color": "green", 386 | "value": null 387 | }, 388 | { 389 | "color": "red", 390 | "value": 80 391 | } 392 | ] 393 | } 394 | }, 395 | "overrides": [] 396 | }, 397 | "gridPos": { 398 | "h": 7, 399 | "w": 8, 400 | "x": 0, 401 | "y": 14 402 | }, 403 | "id": 12, 404 | "options": { 405 | "colorMode": "value", 406 | "graphMode": "area", 407 | "justifyMode": "auto", 408 | "orientation": "auto", 409 | "reduceOptions": { 410 | "calcs": [ 411 | "lastNotNull" 412 | ], 413 | "fields": "", 414 | "values": false 415 | }, 416 | "text": {}, 417 | "textMode": "auto" 418 | }, 419 | "pluginVersion": "7.4.5", 420 | "targets": [ 421 | { 422 | "expr": "sum(rate(qumine_ingress_errors_total{namespace=\"$namespace\"}[$interval]))", 423 | "instant": false, 424 | "interval": "", 425 | "legendFormat": "Total", 426 | "refId": "A" 427 | } 428 | ], 429 | "timeFrom": null, 430 | "timeShift": null, 431 | "title": "Error Rate", 432 | "type": "stat" 433 | }, 434 | { 435 | "aliasColors": {}, 436 | "bars": false, 437 | "dashLength": 10, 438 | "dashes": false, 439 | "datasource": "${datasource}", 440 | "fieldConfig": { 441 | "defaults": { 442 | "custom": {}, 443 | "links": [] 444 | }, 445 | "overrides": [] 446 | }, 447 | "fill": 1, 448 | "fillGradient": 0, 449 | "gridPos": { 450 | "h": 7, 451 | "w": 16, 452 | "x": 8, 453 | "y": 14 454 | }, 455 | "hiddenSeries": false, 456 | "id": 17, 457 | "legend": { 458 | "alignAsTable": false, 459 | "avg": false, 460 | "current": false, 461 | "max": false, 462 | "min": false, 463 | "show": true, 464 | "total": false, 465 | "values": false 466 | }, 467 | "lines": true, 468 | "linewidth": 1, 469 | "nullPointMode": "null", 470 | "options": { 471 | "alertThreshold": true 472 | }, 473 | "percentage": false, 474 | "pluginVersion": "7.4.5", 475 | "pointradius": 2, 476 | "points": false, 477 | "renderer": "flot", 478 | "seriesOverrides": [], 479 | "spaceLength": 10, 480 | "stack": false, 481 | "steppedLine": false, 482 | "targets": [ 483 | { 484 | "expr": "sum(rate(qumine_ingress_errors_total{namespace=\"$namespace\"}[$interval])) by (error)", 485 | "interval": "", 486 | "legendFormat": "{{error}}", 487 | "refId": "A" 488 | } 489 | ], 490 | "thresholds": [], 491 | "timeFrom": null, 492 | "timeRegions": [], 493 | "timeShift": null, 494 | "title": "Error Rate", 495 | "tooltip": { 496 | "shared": true, 497 | "sort": 0, 498 | "value_type": "individual" 499 | }, 500 | "type": "graph", 501 | "xaxis": { 502 | "buckets": null, 503 | "mode": "time", 504 | "name": null, 505 | "show": true, 506 | "values": [] 507 | }, 508 | "yaxes": [ 509 | { 510 | "format": "short", 511 | "label": null, 512 | "logBase": 1, 513 | "max": null, 514 | "min": "0", 515 | "show": true 516 | }, 517 | { 518 | "format": "short", 519 | "label": null, 520 | "logBase": 1, 521 | "max": null, 522 | "min": null, 523 | "show": true 524 | } 525 | ], 526 | "yaxis": { 527 | "align": false, 528 | "alignLevel": null 529 | } 530 | }, 531 | { 532 | "aliasColors": {}, 533 | "bars": false, 534 | "dashLength": 10, 535 | "dashes": false, 536 | "datasource": "${datasource}", 537 | "fieldConfig": { 538 | "defaults": { 539 | "custom": {}, 540 | "links": [] 541 | }, 542 | "overrides": [] 543 | }, 544 | "fill": 1, 545 | "fillGradient": 0, 546 | "gridPos": { 547 | "h": 8, 548 | "w": 12, 549 | "x": 0, 550 | "y": 21 551 | }, 552 | "hiddenSeries": false, 553 | "id": 8, 554 | "legend": { 555 | "alignAsTable": false, 556 | "avg": false, 557 | "current": false, 558 | "max": false, 559 | "min": false, 560 | "rightSide": false, 561 | "show": true, 562 | "sideWidth": 350, 563 | "total": false, 564 | "values": false 565 | }, 566 | "lines": true, 567 | "linewidth": 1, 568 | "nullPointMode": "null", 569 | "options": { 570 | "alertThreshold": true 571 | }, 572 | "percentage": false, 573 | "pluginVersion": "7.4.5", 574 | "pointradius": 2, 575 | "points": false, 576 | "renderer": "flot", 577 | "seriesOverrides": [], 578 | "spaceLength": 10, 579 | "stack": false, 580 | "steppedLine": false, 581 | "targets": [ 582 | { 583 | "expr": "sum(rate(container_cpu_usage_seconds_total{namespace=\"$namespace\", container=~\".*ingress-controller.*\", pod=~\".*ingress-controller.*\"}[$interval])) by (pod)", 584 | "interval": "", 585 | "legendFormat": "{{pod}}", 586 | "refId": "A" 587 | } 588 | ], 589 | "thresholds": [], 590 | "timeFrom": null, 591 | "timeRegions": [], 592 | "timeShift": null, 593 | "title": "CPU Usage", 594 | "tooltip": { 595 | "shared": true, 596 | "sort": 0, 597 | "value_type": "individual" 598 | }, 599 | "type": "graph", 600 | "xaxis": { 601 | "buckets": null, 602 | "mode": "time", 603 | "name": null, 604 | "show": true, 605 | "values": [] 606 | }, 607 | "yaxes": [ 608 | { 609 | "format": "short", 610 | "label": "", 611 | "logBase": 1, 612 | "max": null, 613 | "min": "0", 614 | "show": true 615 | }, 616 | { 617 | "format": "short", 618 | "label": null, 619 | "logBase": 1, 620 | "max": null, 621 | "min": null, 622 | "show": true 623 | } 624 | ], 625 | "yaxis": { 626 | "align": false, 627 | "alignLevel": null 628 | } 629 | }, 630 | { 631 | "aliasColors": {}, 632 | "bars": false, 633 | "dashLength": 10, 634 | "dashes": false, 635 | "datasource": "${datasource}", 636 | "fieldConfig": { 637 | "defaults": { 638 | "custom": {}, 639 | "links": [] 640 | }, 641 | "overrides": [] 642 | }, 643 | "fill": 1, 644 | "fillGradient": 0, 645 | "gridPos": { 646 | "h": 8, 647 | "w": 12, 648 | "x": 12, 649 | "y": 21 650 | }, 651 | "hiddenSeries": false, 652 | "id": 6, 653 | "legend": { 654 | "alignAsTable": false, 655 | "avg": false, 656 | "current": false, 657 | "max": false, 658 | "min": false, 659 | "rightSide": false, 660 | "show": true, 661 | "sideWidth": 350, 662 | "total": false, 663 | "values": false 664 | }, 665 | "lines": true, 666 | "linewidth": 1, 667 | "nullPointMode": "null", 668 | "options": { 669 | "alertThreshold": true 670 | }, 671 | "percentage": false, 672 | "pluginVersion": "7.4.5", 673 | "pointradius": 2, 674 | "points": false, 675 | "renderer": "flot", 676 | "seriesOverrides": [], 677 | "spaceLength": 10, 678 | "stack": false, 679 | "steppedLine": false, 680 | "targets": [ 681 | { 682 | "expr": "sum(container_memory_usage_bytes{namespace=\"$namespace\"}) by (pod)", 683 | "interval": "", 684 | "legendFormat": "{{pod}}", 685 | "refId": "A" 686 | } 687 | ], 688 | "thresholds": [], 689 | "timeFrom": null, 690 | "timeRegions": [], 691 | "timeShift": null, 692 | "title": "Memory Usage", 693 | "tooltip": { 694 | "shared": true, 695 | "sort": 0, 696 | "value_type": "individual" 697 | }, 698 | "type": "graph", 699 | "xaxis": { 700 | "buckets": null, 701 | "mode": "time", 702 | "name": null, 703 | "show": true, 704 | "values": [] 705 | }, 706 | "yaxes": [ 707 | { 708 | "format": "decbytes", 709 | "label": null, 710 | "logBase": 1, 711 | "max": null, 712 | "min": "0", 713 | "show": true 714 | }, 715 | { 716 | "format": "short", 717 | "label": null, 718 | "logBase": 1, 719 | "max": null, 720 | "min": null, 721 | "show": true 722 | } 723 | ], 724 | "yaxis": { 725 | "align": false, 726 | "alignLevel": null 727 | } 728 | } 729 | ], 730 | "refresh": "1m", 731 | "schemaVersion": 27, 732 | "style": "dark", 733 | "tags": [], 734 | "templating": { 735 | "list": [ 736 | { 737 | "current": { 738 | "selected": false, 739 | "text": "default", 740 | "value": "default" 741 | }, 742 | "description": null, 743 | "error": null, 744 | "hide": 0, 745 | "includeAll": false, 746 | "label": "Datasource", 747 | "multi": false, 748 | "name": "datasource", 749 | "options": [], 750 | "query": "prometheus", 751 | "queryValue": "", 752 | "refresh": 1, 753 | "regex": "", 754 | "skipUrlSync": false, 755 | "type": "datasource" 756 | }, 757 | { 758 | "allValue": null, 759 | "current": {}, 760 | "datasource": "${datasource}", 761 | "definition": "label_values(container_memory_usage_bytes, namespace)", 762 | "description": null, 763 | "error": null, 764 | "hide": 0, 765 | "includeAll": false, 766 | "label": "Namespace", 767 | "multi": false, 768 | "name": "namespace", 769 | "options": [], 770 | "query": { 771 | "query": "label_values(container_memory_usage_bytes, namespace)", 772 | "refId": "StandardVariableQuery" 773 | }, 774 | "refresh": 2, 775 | "regex": "qumine-system.*", 776 | "skipUrlSync": false, 777 | "sort": 0, 778 | "tagValuesQuery": "", 779 | "tags": [], 780 | "tagsQuery": "", 781 | "type": "query", 782 | "useTags": false 783 | }, 784 | { 785 | "allValue": null, 786 | "current": { 787 | "selected": false, 788 | "text": "5m", 789 | "value": "5m" 790 | }, 791 | "description": null, 792 | "error": null, 793 | "hide": 0, 794 | "includeAll": false, 795 | "label": "Interval", 796 | "multi": false, 797 | "name": "interval", 798 | "options": [ 799 | { 800 | "selected": false, 801 | "text": "1m", 802 | "value": "1m" 803 | }, 804 | { 805 | "selected": false, 806 | "text": "2m", 807 | "value": "2m" 808 | }, 809 | { 810 | "selected": true, 811 | "text": "5m", 812 | "value": "5m" 813 | }, 814 | { 815 | "selected": false, 816 | "text": "10m", 817 | "value": "10m" 818 | }, 819 | { 820 | "selected": false, 821 | "text": "15m", 822 | "value": "15m" 823 | } 824 | ], 825 | "query": "1m,2m,5m,10m,15m", 826 | "queryValue": "", 827 | "skipUrlSync": false, 828 | "type": "custom" 829 | } 830 | ] 831 | }, 832 | "time": { 833 | "from": "now-30m", 834 | "to": "now" 835 | }, 836 | "timepicker": { 837 | "refresh_intervals": [ 838 | "10s", 839 | "30s", 840 | "1m", 841 | "5m", 842 | "15m", 843 | "30m", 844 | "1h", 845 | "2h", 846 | "1d" 847 | ] 848 | }, 849 | "timezone": "", 850 | "title": "QuMine Ingress", 851 | "uid": "", 852 | "version": 1 853 | } -------------------------------------------------------------------------------- /build/package/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG ARCH= 2 | FROM ${ARCH}alpine 3 | 4 | EXPOSE 80 5 | EXPOSE 25565 6 | 7 | COPY ingress-controller ingress-controller 8 | USER nobody 9 | 10 | ENTRYPOINT [ "./ingress-controller" ] -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os" 7 | "os/signal" 8 | "strings" 9 | "sync" 10 | "syscall" 11 | 12 | "github.com/qumine/ingress-controller/internal/api" 13 | "github.com/qumine/ingress-controller/internal/ingress" 14 | "github.com/qumine/ingress-controller/internal/k8s" 15 | "github.com/qumine/ingress-controller/pkg/build" 16 | "github.com/qumine/ingress-controller/pkg/config" 17 | "github.com/sirupsen/logrus" 18 | "github.com/spf13/cobra" 19 | "github.com/spf13/pflag" 20 | "github.com/spf13/viper" 21 | ) 22 | 23 | func Execute() { 24 | err := NewRootCmd().Execute() 25 | if err != nil { 26 | logrus.Fatal(err) 27 | } 28 | } 29 | 30 | func NewRootCmd() *cobra.Command { 31 | rootCmd := &cobra.Command{ 32 | Use: "ingress-controller", 33 | Short: "A Kubernetes ingress controller for minecraft servers", 34 | Long: "A Kubernetes ingress controller for minecraft servers", 35 | Version: build.GetVersion(), 36 | PersistentPreRun: func(cmd *cobra.Command, args []string) { 37 | viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) 38 | viper.AutomaticEnv() 39 | cmd.Flags().VisitAll(func(f *pflag.Flag) { 40 | if !f.Changed && viper.IsSet(f.Name) { 41 | val := viper.Get(f.Name) 42 | cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)) 43 | } 44 | }) 45 | 46 | cliOptions := config.GetCliOptions() 47 | logrus.SetLevel(cliOptions.LogLevel) 48 | }, 49 | Run: func(cmd *cobra.Command, args []string) { 50 | interrupt := make(chan os.Signal, 1) 51 | signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) 52 | ctx, cancel := context.WithCancel(context.Background()) 53 | wg := &sync.WaitGroup{} 54 | 55 | k8s := k8s.NewK8S(config.GetK8SOptions()) 56 | ing := ingress.NewIngress(config.GetIngressOptions()) 57 | api := api.NewAPI(config.GetAPIOptions(), k8s, ing) 58 | 59 | go k8s.Start(ctx, wg) 60 | go ing.Start(ctx, wg) 61 | go api.Start(ctx, wg) 62 | 63 | <-interrupt 64 | logrus.Info("Interrupted, stopping") 65 | 66 | cancel() 67 | wg.Wait() 68 | }, 69 | } 70 | rootCmd.PersistentFlags().AddFlagSet(config.GetCliFlagSet()) 71 | rootCmd.PersistentFlags().AddFlagSet(config.GetK8SFlagSet()) 72 | rootCmd.PersistentFlags().AddFlagSet(config.GetAPIFlagSet()) 73 | rootCmd.PersistentFlags().AddFlagSet(config.GetIngressFlagSet()) 74 | return rootCmd 75 | } 76 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/qumine/ingress-controller 2 | 3 | go 1.19 4 | toolchain go1.24.1 5 | 6 | require ( 7 | github.com/pkg/errors v0.9.1 8 | github.com/prometheus/client_golang v1.21.1 9 | github.com/sirupsen/logrus v1.9.3 10 | github.com/spf13/cobra v1.9.1 11 | github.com/spf13/pflag v1.0.6 12 | github.com/spf13/viper v1.20.1 13 | github.com/stretchr/testify v1.10.0 14 | golang.org/x/text v0.23.0 15 | k8s.io/api v0.32.3 16 | k8s.io/apimachinery v0.32.3 17 | k8s.io/client-go v0.32.3 18 | ) 19 | 20 | require ( 21 | github.com/beorn7/perks v1.0.1 // indirect 22 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 23 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect 24 | github.com/emicklei/go-restful/v3 v3.11.0 // indirect 25 | github.com/fsnotify/fsnotify v1.8.0 // indirect 26 | github.com/fxamacker/cbor/v2 v2.7.0 // indirect 27 | github.com/go-logr/logr v1.4.2 // indirect 28 | github.com/go-openapi/jsonpointer v0.21.0 // indirect 29 | github.com/go-openapi/jsonreference v0.20.2 // indirect 30 | github.com/go-openapi/swag v0.23.0 // indirect 31 | github.com/go-viper/mapstructure/v2 v2.2.1 // indirect 32 | github.com/gogo/protobuf v1.3.2 // indirect 33 | github.com/golang/protobuf v1.5.4 // indirect 34 | github.com/google/gnostic-models v0.6.8 // indirect 35 | github.com/google/go-cmp v0.6.0 // indirect 36 | github.com/google/gofuzz v1.2.0 // indirect 37 | github.com/google/uuid v1.6.0 // indirect 38 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 39 | github.com/josharian/intern v1.0.0 // indirect 40 | github.com/json-iterator/go v1.1.12 // indirect 41 | github.com/klauspost/compress v1.17.11 // indirect 42 | github.com/mailru/easyjson v0.7.7 // indirect 43 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 44 | github.com/modern-go/reflect2 v1.0.2 // indirect 45 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 46 | github.com/pelletier/go-toml/v2 v2.2.3 // indirect 47 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect 48 | github.com/prometheus/client_model v0.6.1 // indirect 49 | github.com/prometheus/common v0.62.0 // indirect 50 | github.com/prometheus/procfs v0.15.1 // indirect 51 | github.com/sagikazarmark/locafero v0.7.0 // indirect 52 | github.com/sourcegraph/conc v0.3.0 // indirect 53 | github.com/spf13/afero v1.12.0 // indirect 54 | github.com/spf13/cast v1.7.1 // indirect 55 | github.com/subosito/gotenv v1.6.0 // indirect 56 | github.com/x448/float16 v0.8.4 // indirect 57 | go.uber.org/atomic v1.9.0 // indirect 58 | go.uber.org/multierr v1.9.0 // indirect 59 | golang.org/x/net v0.36.0 // indirect 60 | golang.org/x/oauth2 v0.25.0 // indirect 61 | golang.org/x/sys v0.30.0 // indirect 62 | golang.org/x/term v0.29.0 // indirect 63 | golang.org/x/time v0.8.0 // indirect 64 | google.golang.org/protobuf v1.36.1 // indirect 65 | gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect 66 | gopkg.in/inf.v0 v0.9.1 // indirect 67 | gopkg.in/yaml.v3 v3.0.1 // indirect 68 | k8s.io/klog/v2 v2.130.1 // indirect 69 | k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect 70 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect 71 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect 72 | sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect 73 | sigs.k8s.io/yaml v1.4.0 // indirect 74 | ) 75 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 2 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 3 | github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= 4 | github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 5 | github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= 6 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 9 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= 10 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 11 | github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= 12 | github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= 13 | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 14 | github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= 15 | github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= 16 | github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= 17 | github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= 18 | github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= 19 | github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= 20 | github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 21 | github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= 22 | github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= 23 | github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= 24 | github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= 25 | github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= 26 | github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= 27 | github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= 28 | github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= 29 | github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= 30 | github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= 31 | github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= 32 | github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= 33 | github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= 34 | github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= 35 | github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= 36 | github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= 37 | github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= 38 | github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= 39 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 40 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 41 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 42 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 43 | github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= 44 | github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 45 | github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo= 46 | github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= 47 | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 48 | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 49 | github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= 50 | github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 51 | github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= 52 | github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= 53 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 54 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 55 | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 56 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 57 | github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= 58 | github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= 59 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 60 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 61 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 62 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 63 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 64 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 65 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 66 | github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= 67 | github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 68 | github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= 69 | github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= 70 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 71 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 72 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 73 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 74 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 75 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= 76 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 77 | github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= 78 | github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= 79 | github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4= 80 | github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= 81 | github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= 82 | github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= 83 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 84 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 85 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 86 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= 87 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 88 | github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk= 89 | github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg= 90 | github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= 91 | github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= 92 | github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io= 93 | github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I= 94 | github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= 95 | github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= 96 | github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= 97 | github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= 98 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 99 | github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo= 100 | github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k= 101 | github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 102 | github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 103 | github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= 104 | github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= 105 | github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs= 106 | github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4= 107 | github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= 108 | github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= 109 | github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= 110 | github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= 111 | github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= 112 | github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 113 | github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= 114 | github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4= 115 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 116 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 117 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 118 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 119 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 120 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 121 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 122 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 123 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 124 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 125 | github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= 126 | github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= 127 | github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= 128 | github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= 129 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 130 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 131 | go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= 132 | go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 133 | go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= 134 | go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= 135 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 136 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 137 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 138 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 139 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 140 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 141 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 142 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 143 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 144 | golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= 145 | golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= 146 | golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70= 147 | golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= 148 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 149 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 150 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 151 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 152 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 153 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 154 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 155 | golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 156 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 157 | golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= 158 | golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= 159 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 160 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 161 | golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= 162 | golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= 163 | golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= 164 | golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= 165 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 166 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 167 | golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 168 | golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 169 | golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= 170 | golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= 171 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 172 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 173 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 174 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 175 | google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= 176 | google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 177 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 178 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 179 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 180 | gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= 181 | gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= 182 | gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= 183 | gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= 184 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 185 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 186 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 187 | k8s.io/api v0.32.3 h1:Hw7KqxRusq+6QSplE3NYG4MBxZw1BZnq4aP4cJVINls= 188 | k8s.io/api v0.32.3/go.mod h1:2wEDTXADtm/HA7CCMD8D8bK4yuBUptzaRhYcYEEYA3k= 189 | k8s.io/apimachinery v0.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U= 190 | k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE= 191 | k8s.io/client-go v0.32.3 h1:RKPVltzopkSgHS7aS98QdscAgtgah/+zmpAogooIqVU= 192 | k8s.io/client-go v0.32.3/go.mod h1:3v0+3k4IcT9bXTc4V2rt+d2ZPPG700Xy6Oi0Gdl2PaY= 193 | k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= 194 | k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= 195 | k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y= 196 | k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4= 197 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro= 198 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= 199 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8= 200 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo= 201 | sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA= 202 | sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= 203 | sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= 204 | sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= 205 | -------------------------------------------------------------------------------- /internal/api/api.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "sync" 7 | 8 | "github.com/prometheus/client_golang/prometheus/promhttp" 9 | "github.com/qumine/ingress-controller/internal/ingress" 10 | "github.com/qumine/ingress-controller/internal/k8s" 11 | "github.com/qumine/ingress-controller/pkg/config" 12 | "github.com/sirupsen/logrus" 13 | ) 14 | 15 | // API represents the api server 16 | type API struct { 17 | k8s *k8s.K8S 18 | ing *ingress.Ingress 19 | 20 | httpServer *http.Server 21 | } 22 | 23 | // NewAPI creates a new api instance with the given host and port 24 | func NewAPI(apiOptions config.APIOptions, k8s *k8s.K8S, ing *ingress.Ingress) *API { 25 | r := http.NewServeMux() 26 | api := &API{ 27 | k8s: k8s, 28 | ing: ing, 29 | 30 | httpServer: &http.Server{ 31 | Addr: apiOptions.GetAddress(), 32 | Handler: r, 33 | }, 34 | } 35 | r.Handle("/metrics", promhttp.Handler()) 36 | r.HandleFunc("/health/live", api.healthLive) 37 | r.HandleFunc("/health/ready", api.healthReady) 38 | 39 | return api 40 | } 41 | 42 | // Start the Api 43 | func (api *API) Start(context context.Context, wg *sync.WaitGroup) { 44 | defer api.Stop(wg) 45 | logrus.WithFields(logrus.Fields{ 46 | "addr": api.httpServer.Addr, 47 | }).Debug("Starting API") 48 | 49 | wg.Add(1) 50 | go func() { 51 | if err := api.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { 52 | logrus.WithFields(logrus.Fields{ 53 | "addr": api.httpServer.Addr, 54 | }).Fatal("Failed to start API") 55 | } 56 | }() 57 | 58 | logrus.WithFields(logrus.Fields{ 59 | "addr": api.httpServer.Addr, 60 | }).Info("Started API") 61 | for { 62 | <-context.Done() 63 | return 64 | } 65 | } 66 | 67 | // Stop the api 68 | func (a *API) Stop(wg *sync.WaitGroup) { 69 | logrus.WithFields(logrus.Fields{ 70 | "addr": a.httpServer.Addr, 71 | }).Debug("Stopping API") 72 | 73 | if err := a.httpServer.Close(); err != nil { 74 | logrus.WithFields(logrus.Fields{ 75 | "addr": a.httpServer.Addr, 76 | }).Error("Failed to stop API") 77 | } 78 | 79 | wg.Done() 80 | logrus.WithFields(logrus.Fields{ 81 | "addr": a.httpServer.Addr, 82 | }).Info("Stopped API") 83 | } 84 | -------------------------------------------------------------------------------- /internal/api/health.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import "net/http" 4 | 5 | func (api *API) healthLive(writer http.ResponseWriter, request *http.Request) { 6 | writer.WriteHeader(http.StatusOK) 7 | writer.Write([]byte{}) 8 | } 9 | 10 | func (api *API) healthReady(writer http.ResponseWriter, request *http.Request) { 11 | details := make(map[string]string) 12 | details["k8s"] = api.k8s.Status 13 | details["server"] = api.ing.Status 14 | 15 | if api.k8s.Status == "up" && api.ing.Status == "up" { 16 | writer.WriteHeader(http.StatusOK) 17 | writer.Write([]byte{}) 18 | } else { 19 | writer.WriteHeader(http.StatusServiceUnavailable) 20 | writer.Write([]byte{}) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /internal/ingress/ingress.go: -------------------------------------------------------------------------------- 1 | package ingress 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "io" 7 | "net" 8 | "sync" 9 | "time" 10 | 11 | "github.com/prometheus/client_golang/prometheus" 12 | "github.com/qumine/ingress-controller/internal/metrics" 13 | "github.com/qumine/ingress-controller/internal/proto" 14 | "github.com/qumine/ingress-controller/internal/routing" 15 | "github.com/qumine/ingress-controller/pkg/config" 16 | "github.com/sirupsen/logrus" 17 | ) 18 | 19 | const ( 20 | handshakeTimeout = 5 * time.Second 21 | ) 22 | 23 | var ( 24 | noDeadline time.Time 25 | ) 26 | 27 | // Ingress represents the server 28 | type Ingress struct { 29 | // Status is the current status of the server. 30 | Status string 31 | 32 | addr string 33 | state proto.State 34 | 35 | listener net.Listener 36 | } 37 | 38 | // NewIngress creates a new ingress instance with the options 39 | func NewIngress(ingressOptions config.IngressOptions) *Ingress { 40 | return &Ingress{ 41 | addr: ingressOptions.GetAddress(), 42 | } 43 | } 44 | 45 | // Start the server 46 | func (ing *Ingress) Start(context context.Context, wg *sync.WaitGroup) { 47 | defer ing.Stop(wg) 48 | 49 | logrus.WithFields(logrus.Fields{ 50 | "addr": ing.addr, 51 | }).Debug("Starting ingress") 52 | 53 | listener, err := net.Listen("tcp", ing.addr) 54 | if err != nil { 55 | logrus.WithError(err).WithFields(logrus.Fields{ 56 | "addr": ing.addr, 57 | }).Fatal("Failed to start ingress") 58 | } 59 | ing.listener = listener 60 | 61 | logrus.WithFields(logrus.Fields{ 62 | "addr": ing.addr, 63 | }).Info("Started ingress") 64 | ing.acceptConnections(context, wg, listener) 65 | } 66 | 67 | // Stop the ingress 68 | func (ing *Ingress) Stop(wg *sync.WaitGroup) { 69 | logrus.WithFields(logrus.Fields{ 70 | "addr": ing.addr, 71 | }).Info("Stopping ingress") 72 | 73 | if err := ing.listener.Close(); err != nil { 74 | logrus.WithFields(logrus.Fields{ 75 | "addr": ing.addr, 76 | }).Error("Failed to stop ingress") 77 | } 78 | 79 | ing.Status = "down" 80 | wg.Done() 81 | logrus.WithFields(logrus.Fields{ 82 | "addr": ing.addr, 83 | }).Info("Stopped ingress") 84 | } 85 | 86 | func (ing *Ingress) acceptConnections(context context.Context, wg *sync.WaitGroup, listener net.Listener) { 87 | ing.Status = "up" 88 | wg.Add(1) 89 | 90 | go func() { 91 | for ing.Status == "up" { 92 | connection, err := listener.Accept() 93 | if err != nil { 94 | logrus.WithError(err).WithFields(logrus.Fields{ 95 | "addr": ing.addr, 96 | }).Error("Failed to accept connection") 97 | } else { 98 | go ing.handleConnection(context, connection) 99 | } 100 | } 101 | }() 102 | 103 | for { 104 | select { 105 | case <-context.Done(): 106 | return 107 | } 108 | } 109 | } 110 | 111 | func (ing *Ingress) handleConnection(context context.Context, client net.Conn) { 112 | defer client.Close() 113 | defer logrus.WithField("client", client.RemoteAddr()).Info("closed client connection") 114 | logrus.WithField("client", client.RemoteAddr()).Info("inbound client connection") 115 | 116 | buffer := new(bytes.Buffer) 117 | reader := io.TeeReader(client, buffer) 118 | 119 | if err := client.SetReadDeadline(time.Now().Add(handshakeTimeout)); err != nil { 120 | logrus.WithError(err).WithField("client", client.RemoteAddr()).Error("setting deadline failed") 121 | return 122 | } 123 | packet, err := proto.ReadPacket(reader, client.RemoteAddr(), ing.state) 124 | if err != nil { 125 | logrus.WithError(err).WithField("client", client.RemoteAddr()).Error("reading packet failed") 126 | return 127 | } 128 | logrus.WithFields(logrus.Fields{ 129 | "client": client.RemoteAddr(), 130 | "packetLength": packet.Length, 131 | "packetID": packet.PacketID, 132 | }).Debug("received packet") 133 | 134 | if packet.PacketID == proto.HandshakeID { 135 | handshake, err := proto.ReadHandshake(packet.Data) 136 | if err != nil { 137 | logrus.WithError(err).WithField("client", client.RemoteAddr()).Error("decoding handshake packet failed") 138 | metrics.ErrorsTotal.With(prometheus.Labels{"error": "DecodeHandshakeFailed"}).Inc() 139 | return 140 | } 141 | logrus.WithFields(logrus.Fields{ 142 | "client": client.RemoteAddr(), 143 | "handshake": handshake, 144 | }).Debug("decoded handshake") 145 | 146 | hostname := handshake.ServerAddress 147 | ing.findAndConnectBackend(context, client, buffer, hostname, "handshake") 148 | } else if packet.PacketID == proto.LegacyServerListPingID { 149 | handshake, ok := packet.Data.(*proto.LegacyServerListPing) 150 | if !ok { 151 | logrus.WithError(err).WithField("client", client.RemoteAddr()).Error("decoding legacyServerListPing packet failed") 152 | metrics.ErrorsTotal.With(prometheus.Labels{"error": "DecodeLegacyServerListPingFailed"}).Inc() 153 | return 154 | } 155 | logrus.WithFields(logrus.Fields{ 156 | "client": client.RemoteAddr(), 157 | "handshake": handshake.ServerAddress, 158 | }).Debug("decoded legacyServerListPing") 159 | 160 | hostname := handshake.ServerAddress 161 | ing.findAndConnectBackend(context, client, buffer, hostname, "legacyServerListPing") 162 | } else { 163 | logrus.WithFields(logrus.Fields{ 164 | "client": client.RemoteAddr(), 165 | "packetID": packet.PacketID, 166 | }).Error("received unexpected packet, expected handshake or legacyServerListPing") 167 | return 168 | } 169 | } 170 | 171 | func (ing *Ingress) findAndConnectBackend(context context.Context, client net.Conn, preReadContent io.Reader, hostname string, packet string) { 172 | route, err := routing.FindBackend(hostname) 173 | if err != nil { 174 | logrus.WithError(err).Warn("no matching route found") 175 | metrics.ErrorsTotal.With(prometheus.Labels{"error": "NotFound"}).Inc() 176 | return 177 | } 178 | logrus.WithFields(logrus.Fields{ 179 | "client": client.RemoteAddr(), 180 | "route": route, 181 | }).Debug("found matching route") 182 | 183 | upstream, err := net.Dial("tcp", route) 184 | if err != nil { 185 | logrus.WithFields(logrus.Fields{ 186 | "client": client.RemoteAddr(), 187 | "route": route, 188 | }).Error("connecting to upstream failed") 189 | metrics.ErrorsTotal.With(prometheus.Labels{"error": "UpstreamConnectionFailed"}).Inc() 190 | return 191 | } 192 | defer metrics.Connections.With(prometheus.Labels{"route": route}).Dec() 193 | metrics.Connections.With(prometheus.Labels{"route": route}).Inc() 194 | logrus.WithFields(logrus.Fields{ 195 | "client": client.RemoteAddr(), 196 | "upstream": upstream.RemoteAddr(), 197 | }).Info("connected to upstream") 198 | 199 | amount, err := io.Copy(upstream, preReadContent) 200 | if err != nil { 201 | logrus.WithFields(logrus.Fields{ 202 | "client": client.RemoteAddr(), 203 | "upstream": upstream.RemoteAddr(), 204 | }).Error("failed to relay packet to upstream") 205 | return 206 | } 207 | logrus.WithFields(logrus.Fields{ 208 | "client": client.RemoteAddr(), 209 | "upstream": upstream.RemoteAddr(), 210 | "amount": amount, 211 | }).Debugf("relayed %s to upstream", packet) 212 | 213 | if err = client.SetReadDeadline(noDeadline); err != nil { 214 | logrus.WithError(err).WithFields(logrus.Fields{ 215 | "client": client.RemoteAddr(), 216 | "upstream": upstream.RemoteAddr(), 217 | }).Error("clearing deadline failed") 218 | return 219 | } 220 | ing.relayConnections(context, route, client, upstream) 221 | return 222 | } 223 | 224 | func (ing *Ingress) relayConnections(context context.Context, route string, client net.Conn, upstream net.Conn) { 225 | defer upstream.Close() 226 | defer logrus.WithFields(logrus.Fields{ 227 | "client": client.RemoteAddr(), 228 | "upstream": upstream.RemoteAddr(), 229 | }).Info("stopped relaying connections") 230 | logrus.WithFields(logrus.Fields{ 231 | "client": client.RemoteAddr(), 232 | "upstream": upstream.RemoteAddr(), 233 | }).Debug("relaying connections") 234 | 235 | errors := make(chan error, 2) 236 | go ing.relay(upstream, client, errors, "upstream", route) 237 | go ing.relay(client, upstream, errors, "downstream", route) 238 | 239 | select { 240 | case err := <-errors: 241 | if err != io.EOF { 242 | logrus.WithError(err).WithFields(logrus.Fields{ 243 | "client": client.RemoteAddr(), 244 | "upstream": upstream.RemoteAddr(), 245 | }).Error("clearing deadline failed") 246 | } 247 | 248 | case <-context.Done(): 249 | return 250 | } 251 | } 252 | 253 | func (ing *Ingress) relay(dst net.Conn, src net.Conn, errors chan<- error, direction string, route string) { 254 | logrus.WithFields(logrus.Fields{ 255 | "dst": dst.RemoteAddr(), 256 | "src": src.RemoteAddr(), 257 | "direction": direction, 258 | }).Debug("relaying connection") 259 | 260 | bytes, err := io.Copy(dst, src) 261 | logrus.WithFields(logrus.Fields{ 262 | "dst": dst.RemoteAddr(), 263 | "src": src.RemoteAddr(), 264 | "direction": direction, 265 | "bytes": bytes, 266 | }).Debug("stopped relaying connectioxn") 267 | 268 | if err != nil { 269 | errors <- err 270 | } else { 271 | errors <- io.EOF 272 | } 273 | } 274 | -------------------------------------------------------------------------------- /internal/k8s/handlers.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | import ( 4 | "net" 5 | "strconv" 6 | 7 | "github.com/prometheus/client_golang/prometheus" 8 | "github.com/qumine/ingress-controller/internal/metrics" 9 | "github.com/qumine/ingress-controller/internal/routing" 10 | "github.com/sirupsen/logrus" 11 | v1 "k8s.io/api/core/v1" 12 | ) 13 | 14 | func onAdd(obj interface{}) { 15 | service, ok := obj.(*v1.Service) 16 | if !ok { 17 | metrics.ErrorsTotal.With(prometheus.Labels{"error": "InternalError"}).Inc() 18 | return 19 | } 20 | 21 | hostname := "localhost" 22 | if h, exists := service.Annotations[AnnotationHostname]; exists { 23 | hostname = h 24 | } else { 25 | logrus.WithFields(logrus.Fields{ 26 | "service": service, 27 | }).Tracef("Adding service skipped, %s annotation not present", AnnotationHostname) 28 | return 29 | } 30 | 31 | portname := "minecraft" 32 | if p, exists := service.Annotations[AnnotationPortname]; exists { 33 | portname = p 34 | } 35 | logrus.WithFields(logrus.Fields{ 36 | "hostname": hostname, 37 | "portname": portname, 38 | }).Debug("Adding route") 39 | 40 | for _, p := range service.Spec.Ports { 41 | if p.Name == portname { 42 | routing.Add(string(service.UID), routing.NewRoute(hostname, net.JoinHostPort(service.Spec.ClusterIP, strconv.Itoa(int(p.Port))))) 43 | return 44 | } 45 | } 46 | metrics.ErrorsTotal.With(prometheus.Labels{"error": "NoMatchingPort"}).Inc() 47 | } 48 | 49 | func onDelete(obj interface{}) { 50 | service, ok := obj.(*v1.Service) 51 | if !ok { 52 | metrics.ErrorsTotal.With(prometheus.Labels{"error": "InternalError"}).Inc() 53 | return 54 | } 55 | 56 | if _, exists := service.Annotations[AnnotationHostname]; !exists { 57 | logrus.WithFields(logrus.Fields{ 58 | "service": service, 59 | }).Tracef("Deleting service skipped, %s annotation not present", AnnotationHostname) 60 | return 61 | } 62 | 63 | routing.Remove(string(service.UID)) 64 | } 65 | 66 | func onUpdate(oldObj interface{}, newObj interface{}) { 67 | onDelete(oldObj) 68 | onAdd(newObj) 69 | } 70 | -------------------------------------------------------------------------------- /internal/k8s/k8s.go: -------------------------------------------------------------------------------- 1 | package k8s 2 | 3 | import ( 4 | "context" 5 | "sync" 6 | 7 | "github.com/qumine/ingress-controller/pkg/config" 8 | "github.com/sirupsen/logrus" 9 | v1 "k8s.io/api/core/v1" 10 | "k8s.io/apimachinery/pkg/fields" 11 | "k8s.io/client-go/kubernetes" 12 | "k8s.io/client-go/tools/cache" 13 | "k8s.io/client-go/tools/clientcmd" 14 | ) 15 | 16 | const ( 17 | // AnnotationHostname is the kubernetes annotation for the hostname to use for the ingress 18 | AnnotationHostname = "ingress.qumine.io/hostname" 19 | // AnnotationPortname is the kubernetes annotation for the name of the port to use 20 | AnnotationPortname = "ingress.qumine.io/portname" 21 | ) 22 | 23 | // K8S is a watcher for kubernetes 24 | type K8S struct { 25 | // Status is the current status of the K8S watcher. 26 | Status string 27 | 28 | kubeconfig string 29 | stop chan struct{} 30 | } 31 | 32 | // NewK8S creates a new k8s instance 33 | func NewK8S(k8sOptions config.K8SOptions) *K8S { 34 | return &K8S{ 35 | kubeconfig: k8sOptions.KubeConfig, 36 | stop: make(chan struct{}, 1), 37 | } 38 | } 39 | 40 | // Start the K8S 41 | func (k8s *K8S) Start(context context.Context, wg *sync.WaitGroup) { 42 | defer k8s.Stop(wg) 43 | logrus.WithFields(logrus.Fields{ 44 | "kubeconfig": k8s.kubeconfig, 45 | }).Debug("Starting K8S") 46 | 47 | config, err := clientcmd.BuildConfigFromFlags("", k8s.kubeconfig) 48 | if err != nil { 49 | logrus.WithError(err).WithFields(logrus.Fields{ 50 | "kubeconfig": k8s.kubeconfig, 51 | }).Fatal("Failed to start K8S") 52 | } 53 | 54 | clientset, err := kubernetes.NewForConfig(config) 55 | if err != nil { 56 | logrus.WithError(err).WithFields(logrus.Fields{ 57 | "kubeconfig": k8s.kubeconfig, 58 | }).Fatal("Failed to start K8S") 59 | } 60 | 61 | watchlist := cache.NewListWatchFromClient( 62 | clientset.CoreV1().RESTClient(), 63 | string(v1.ResourceServices), 64 | v1.NamespaceAll, 65 | fields.Everything(), 66 | ) 67 | 68 | _, controller := cache.NewInformer( 69 | watchlist, 70 | &v1.Service{}, 71 | 0, 72 | cache.ResourceEventHandlerFuncs{ 73 | AddFunc: onAdd, 74 | DeleteFunc: onDelete, 75 | UpdateFunc: onUpdate, 76 | }, 77 | ) 78 | 79 | go controller.Run(k8s.stop) 80 | k8s.Status = "up" 81 | wg.Add(1) 82 | 83 | logrus.WithFields(logrus.Fields{ 84 | "kubeconfig": k8s.kubeconfig, 85 | }).Info("Started K8S") 86 | for { 87 | select { 88 | case <-context.Done(): 89 | k8s.Status = "down" 90 | return 91 | } 92 | } 93 | } 94 | 95 | // Stop the K8S 96 | func (k8s *K8S) Stop(wg *sync.WaitGroup) { 97 | logrus.WithFields(logrus.Fields{ 98 | "kubeconfig": k8s.kubeconfig, 99 | }).Info("Stopping K8S") 100 | 101 | k8s.stop <- struct{}{} 102 | 103 | k8s.Status = "down" 104 | wg.Done() 105 | logrus.WithFields(logrus.Fields{ 106 | "kubeconfig": k8s.kubeconfig, 107 | }).Info("Stopped K8S") 108 | } 109 | -------------------------------------------------------------------------------- /internal/metrics/metrics.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "github.com/prometheus/client_golang/prometheus" 5 | ) 6 | 7 | var ( 8 | // Routes represents the metrics for the amount of registered routes 9 | Routes = prometheus.NewGauge( 10 | prometheus.GaugeOpts{ 11 | Name: "qumine_ingress_routes", 12 | Help: "The amount of registered routes", 13 | }, 14 | ) 15 | // Connections represents the metrics for the amount of active connections 16 | Connections = prometheus.NewGaugeVec( 17 | prometheus.GaugeOpts{ 18 | Name: "qumine_ingress_connections", 19 | Help: "The amount of active connections", 20 | }, 21 | []string{"route"}, 22 | ) 23 | // ErrorsTotal represents the metrics for the amount of total errors 24 | ErrorsTotal = prometheus.NewCounterVec( 25 | prometheus.CounterOpts{ 26 | Name: "qumine_ingress_errors_total", 27 | Help: "The total error count", 28 | }, 29 | []string{"error"}, 30 | ) 31 | // BytesTotal represents the metrics for the amount of total bytes transmitted 32 | BytesTotal = prometheus.NewCounterVec( 33 | prometheus.CounterOpts{ 34 | Name: "qumine_ingress_bytes_total", 35 | Help: "The total bytes transmitted", 36 | }, 37 | []string{"direction", "route"}, 38 | ) 39 | ) 40 | 41 | func init() { 42 | prometheus.MustRegister(Routes) 43 | prometheus.MustRegister(Connections) 44 | prometheus.MustRegister(ErrorsTotal) 45 | prometheus.MustRegister(BytesTotal) 46 | } 47 | -------------------------------------------------------------------------------- /internal/proto/read.go: -------------------------------------------------------------------------------- 1 | package proto 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "encoding/binary" 7 | "io" 8 | "net" 9 | "strings" 10 | "time" 11 | 12 | "github.com/pkg/errors" 13 | "github.com/sirupsen/logrus" 14 | "golang.org/x/text/encoding/unicode" 15 | "golang.org/x/text/transform" 16 | ) 17 | 18 | // ReadPacket reads a single packet from the given reader. 19 | func ReadPacket(reader io.Reader, addr net.Addr, state State) (*Packet, error) { 20 | if state == StateHandshaking { 21 | bufReader := bufio.NewReader(reader) 22 | data, err := bufReader.Peek(1) 23 | if err != nil { 24 | return nil, err 25 | } 26 | 27 | if data[0] == LegacyServerListPingID { 28 | return readLegacyServerListPing(bufReader, addr) 29 | } 30 | reader = bufReader 31 | } 32 | 33 | frame, err := readFrame(reader, addr) 34 | if err != nil { 35 | return nil, err 36 | } 37 | 38 | packet := &Packet{Length: frame.length} 39 | 40 | remainder := bytes.NewBuffer(frame.payload) 41 | 42 | packet.PacketID, err = readVarInt(remainder) 43 | if err != nil { 44 | return nil, err 45 | } 46 | packet.Data = remainder.Bytes() 47 | logrus.WithFields(logrus.Fields{ 48 | "client": addr, 49 | "packet": packet, 50 | }).Trace("read packet") 51 | 52 | return packet, nil 53 | } 54 | 55 | func readLegacyServerListPing(reader *bufio.Reader, addr net.Addr) (*Packet, error) { 56 | _, err := reader.ReadByte() 57 | if err != nil { 58 | return nil, err 59 | } 60 | 61 | _, err = reader.ReadByte() 62 | if err != nil { 63 | return nil, err 64 | } 65 | 66 | _, err = reader.ReadByte() 67 | if err != nil { 68 | return nil, err 69 | } 70 | 71 | messageNameLength, err := readUnsignedShort(reader) 72 | if err != nil { 73 | return nil, err 74 | } 75 | 76 | _, err = readUTF16BEString(reader, messageNameLength) 77 | if err != nil { 78 | return nil, err 79 | } 80 | 81 | remainingLength, err := readUnsignedShort(reader) 82 | if err != nil { 83 | return nil, err 84 | } 85 | remainingReader := io.LimitReader(reader, int64(remainingLength)) 86 | 87 | protocolVersion, err := readByte(remainingReader) 88 | if err != nil { 89 | return nil, err 90 | } 91 | 92 | hostnameLength, err := readUnsignedShort(remainingReader) 93 | if err != nil { 94 | return nil, err 95 | } 96 | hostname, err := readUTF16BEString(remainingReader, hostnameLength) 97 | if err != nil { 98 | return nil, err 99 | } 100 | 101 | port, err := readUnsignedInt(remainingReader) 102 | if err != nil { 103 | return nil, err 104 | } 105 | 106 | return &Packet{ 107 | PacketID: LegacyServerListPingID, 108 | Length: 0, 109 | Data: &LegacyServerListPing{ 110 | ProtocolVersion: int(protocolVersion), 111 | ServerAddress: hostname, 112 | ServerPort: uint16(port), 113 | }, 114 | }, nil 115 | } 116 | 117 | func readUTF16BEString(reader io.Reader, symbolLen uint16) (string, error) { 118 | bsUtf16be := make([]byte, symbolLen*2) 119 | 120 | _, err := io.ReadFull(reader, bsUtf16be) 121 | if err != nil { 122 | return "", err 123 | } 124 | 125 | result, _, err := transform.Bytes(unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewDecoder(), bsUtf16be) 126 | if err != nil { 127 | return "", err 128 | } 129 | 130 | return string(result), nil 131 | } 132 | 133 | func readFrame(reader io.Reader, addr net.Addr) (*Frame, error) { 134 | var err error 135 | frame := &Frame{} 136 | 137 | frame.length, err = readVarInt(reader) 138 | if err != nil { 139 | return nil, err 140 | } 141 | logrus.WithFields(logrus.Fields{ 142 | "client": addr, 143 | "length": frame.length, 144 | }).Trace("read frame length") 145 | 146 | frame.payload = make([]byte, frame.length) 147 | total := 0 148 | for total < frame.length { 149 | readIntoThis := frame.payload[total:] 150 | n, err := reader.Read(readIntoThis) 151 | if err != nil { 152 | if err != io.EOF { 153 | return nil, err 154 | } 155 | } 156 | total += n 157 | logrus.WithFields(logrus.Fields{ 158 | "client": addr, 159 | "total": total, 160 | }).Trace("read frame content") 161 | 162 | if n == 0 { 163 | time.Sleep(100 * time.Millisecond) 164 | } 165 | } 166 | 167 | logrus.WithFields(logrus.Fields{ 168 | "client": addr, 169 | "frame": frame, 170 | }).Trace("read frame") 171 | return frame, nil 172 | } 173 | 174 | func readVarInt(reader io.Reader) (int, error) { 175 | b := make([]byte, 1) 176 | var numRead uint 177 | result := 0 178 | for numRead <= 5 { 179 | n, err := reader.Read(b) 180 | if err != nil { 181 | return 0, err 182 | } 183 | if n == 0 { 184 | continue 185 | } 186 | value := b[0] & 0x7F 187 | result |= int(value) << (7 * numRead) 188 | 189 | numRead++ 190 | 191 | if b[0]&0x80 == 0 { 192 | return result, nil 193 | } 194 | } 195 | 196 | return 0, errors.New("VarInt is too big") 197 | } 198 | 199 | func readString(reader io.Reader) (string, error) { 200 | length, err := readVarInt(reader) 201 | if err != nil { 202 | return "", err 203 | } 204 | 205 | b := make([]byte, 1) 206 | var strBuilder strings.Builder 207 | for i := 0; i < length; i++ { 208 | n, err := reader.Read(b) 209 | if err != nil { 210 | return "", err 211 | } 212 | if n == 0 { 213 | continue 214 | } 215 | strBuilder.WriteByte(b[0]) 216 | } 217 | 218 | return strBuilder.String(), nil 219 | } 220 | 221 | func readByte(reader io.Reader) (byte, error) { 222 | buf := make([]byte, 1) 223 | _, err := reader.Read(buf) 224 | if err != nil { 225 | return 0, err 226 | } 227 | return buf[0], nil 228 | } 229 | 230 | func readUnsignedShort(reader io.Reader) (uint16, error) { 231 | var value uint16 232 | err := binary.Read(reader, binary.BigEndian, &value) 233 | if err != nil { 234 | return 0, err 235 | } 236 | return value, nil 237 | } 238 | 239 | func readUnsignedInt(reader io.Reader) (uint32, error) { 240 | var value uint32 241 | err := binary.Read(reader, binary.BigEndian, &value) 242 | if err != nil { 243 | return 0, err 244 | } 245 | return value, nil 246 | } 247 | 248 | // ReadHandshake reads a Handshake packet from the given data. 249 | func ReadHandshake(data interface{}) (*Handshake, error) { 250 | 251 | dataBytes, ok := data.([]byte) 252 | if !ok { 253 | return nil, errors.New("data is not expected byte slice") 254 | } 255 | 256 | handshake := &Handshake{} 257 | buffer := bytes.NewBuffer(dataBytes) 258 | var err error 259 | 260 | handshake.ProtocolVersion, err = readVarInt(buffer) 261 | if err != nil { 262 | return nil, err 263 | } 264 | 265 | handshake.ServerAddress, err = readString(buffer) 266 | if err != nil { 267 | return nil, err 268 | } 269 | 270 | handshake.ServerPort, err = readUnsignedShort(buffer) 271 | if err != nil { 272 | return nil, err 273 | } 274 | 275 | nextState, err := readVarInt(buffer) 276 | if err != nil { 277 | return nil, err 278 | } 279 | handshake.NextState = nextState 280 | return handshake, nil 281 | } 282 | -------------------------------------------------------------------------------- /internal/proto/read_test.go: -------------------------------------------------------------------------------- 1 | package proto 2 | 3 | import ( 4 | "bytes" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestReadVarInt(t *testing.T) { 12 | tests := []struct { 13 | Name string 14 | Input []byte 15 | Expected int 16 | }{ 17 | { 18 | Name: "Single byte", 19 | Input: []byte{0xFA, 0x00}, 20 | Expected: 0x7A, 21 | }, 22 | { 23 | Name: "Two byte", 24 | Input: []byte{0x81, 0x04}, 25 | Expected: 0x0201, 26 | }, 27 | } 28 | 29 | for _, tt := range tests { 30 | t.Run(tt.Name, func(t *testing.T) { 31 | result, err := readVarInt(bytes.NewBuffer(tt.Input)) 32 | require.NoError(t, err) 33 | 34 | assert.Equal(t, tt.Expected, result) 35 | }) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /internal/proto/types.go: -------------------------------------------------------------------------------- 1 | package proto 2 | 3 | import "fmt" 4 | 5 | // Frame represents a single frame in the communication. 6 | type Frame struct { 7 | length int 8 | payload []byte 9 | } 10 | 11 | // State represents the state a minecraft connection is in. 12 | type State int 13 | 14 | const ( 15 | // StateHandshaking is the initial state of a minecraft connection. 16 | StateHandshaking = iota 17 | ) 18 | 19 | var trimLimit = 64 20 | 21 | func trimBytes(data []byte) ([]byte, string) { 22 | if len(data) < trimLimit { 23 | return data, "" 24 | } 25 | return data[:trimLimit], "..." 26 | } 27 | 28 | func (f *Frame) String() string { 29 | trimmed, cont := trimBytes(f.payload) 30 | return fmt.Sprintf("Frame:[len=%d, payload=%#X%s]", f.length, trimmed, cont) 31 | } 32 | 33 | // Packet represents a single packet in the minecraft communication. 34 | type Packet struct { 35 | // Length is the length of the packet. 36 | Length int 37 | // PacketID is the ID of the packet. 38 | PacketID int 39 | // Data is either a byte slice of raw content or a parsed message 40 | Data interface{} 41 | } 42 | 43 | func (p *Packet) String() string { 44 | if dataBytes, ok := p.Data.([]byte); ok { 45 | trimmed, cont := trimBytes(dataBytes) 46 | return fmt.Sprintf("Frame:[len=%d, packetId=%d, data=%#X%s]", p.Length, p.PacketID, trimmed, cont) 47 | } 48 | return fmt.Sprintf("Frame:[len=%d, packetId=%d, data=%+v]", p.Length, p.PacketID, p.Data) 49 | 50 | } 51 | 52 | const ( 53 | // HandshakeID is the ID of the Handshake packet. 54 | HandshakeID = 0x00 55 | // LegacyServerListPingID is the ID of the LegacyServerListPing packet. 56 | LegacyServerListPingID = 0xFE 57 | ) 58 | 59 | // Handshake is the first packet in the minecraft protocol send by the client. 60 | type Handshake struct { 61 | ProtocolVersion int 62 | ServerAddress string 63 | ServerPort uint16 64 | NextState int 65 | } 66 | 67 | // LegacyServerListPing is send by legacy minecraft client. 68 | type LegacyServerListPing struct { 69 | ProtocolVersion int 70 | ServerAddress string 71 | ServerPort uint16 72 | } 73 | 74 | type byteReader interface { 75 | ReadByte() (byte, error) 76 | } 77 | -------------------------------------------------------------------------------- /internal/routing/route.go: -------------------------------------------------------------------------------- 1 | package routing 2 | 3 | // Route represents the route between a frontend and a backend. 4 | type Route struct { 5 | Frontend string 6 | Backend string 7 | } 8 | 9 | // NewRoute creates a new route. 10 | func NewRoute(frontend string, backend string) Route { 11 | return Route{ 12 | Frontend: frontend, 13 | Backend: backend, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /internal/routing/router.go: -------------------------------------------------------------------------------- 1 | package routing 2 | 3 | import ( 4 | "errors" 5 | "strings" 6 | 7 | "github.com/qumine/ingress-controller/internal/metrics" 8 | "github.com/sirupsen/logrus" 9 | ) 10 | 11 | var routes = make(map[string]Route) 12 | 13 | // Add a new route to the router. 14 | func Add(uid string, route Route) { 15 | if _, ok := routes[uid]; !ok { 16 | routes[uid] = route 17 | logrus.WithField("uid", uid).WithField("frontend", route.Frontend).WithField("backend", route.Backend).Info("route created") 18 | metrics.Routes.Inc() 19 | } else { 20 | logrus.WithField("uid", uid).Warn("route already created") 21 | } 22 | } 23 | 24 | // Update an existing route from the router. 25 | func Update(uid string, route Route) { 26 | if _, ok := routes[uid]; ok { 27 | routes[uid] = route 28 | logrus.WithField("uid", uid).WithField("frontend", route.Frontend).WithField("backend", route.Backend).Info("route updated") 29 | } 30 | } 31 | 32 | // Remove an existing route from the router. 33 | func Remove(uid string) { 34 | if _, ok := routes[uid]; ok { 35 | delete(routes, uid) 36 | logrus.WithField("uid", uid).Info("route deleted") 37 | metrics.Routes.Dec() 38 | } 39 | } 40 | 41 | // FindBackend finds a route by its frontend and returns the backend or throws an error. 42 | func FindBackend(frontend string) (string, error) { 43 | frontendParts := strings.Split(frontend, "\x00") 44 | frontend = strings.ToLower(frontendParts[0]) 45 | 46 | for _, route := range routes { 47 | if route.Frontend == frontend { 48 | return route.Backend, nil 49 | } 50 | } 51 | return "", errors.New("route not found") 52 | } 53 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/qumine/ingress-controller/cmd" 7 | "github.com/sirupsen/logrus" 8 | ) 9 | 10 | // nolint: gochecknoglobals 11 | var ( 12 | version = "dev" 13 | commit = "" 14 | date = "" 15 | builtBy = "" 16 | ) 17 | 18 | //go:generate make generate-bindata 19 | func init() { 20 | // Set 21 | logrus.SetOutput(os.Stdout) 22 | logrus.SetLevel(logrus.InfoLevel) 23 | } 24 | 25 | func main() { 26 | cmd.Execute() 27 | } 28 | -------------------------------------------------------------------------------- /pkg/build/version.go: -------------------------------------------------------------------------------- 1 | package build 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // nolint: gochecknoglobals 8 | var ( 9 | version = "dev" 10 | commit = "" 11 | date = "" 12 | ) 13 | 14 | func GetVersion() string { 15 | result := version 16 | if commit != "" { 17 | result = fmt.Sprintf("%s, commit: %s", result, commit) 18 | } 19 | if date != "" { 20 | result = fmt.Sprintf("%s, built at: %s", result, date) 21 | } 22 | return result 23 | } 24 | -------------------------------------------------------------------------------- /pkg/config/api.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "net" 5 | "strconv" 6 | 7 | "github.com/spf13/pflag" 8 | ) 9 | 10 | var apiOptions APIOptions 11 | 12 | type APIOptions struct { 13 | Host string 14 | Port int 15 | } 16 | 17 | func GetAPIFlagSet() *pflag.FlagSet { 18 | flagSet := &pflag.FlagSet{} 19 | flagSet.StringVar(&apiOptions.Host, "api-host", "0.0.0.0", "Host for the API server to listen on") 20 | flagSet.IntVar(&apiOptions.Port, "api-port", 8080, "Port for the API server to listen on") 21 | return flagSet 22 | } 23 | 24 | func GetAPIOptions() APIOptions { 25 | return apiOptions 26 | } 27 | 28 | func (aiOptions *APIOptions) GetAddress() string { 29 | return net.JoinHostPort(aiOptions.Host, strconv.Itoa(apiOptions.Port)) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/config/cli.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "github.com/sirupsen/logrus" 5 | "github.com/spf13/pflag" 6 | ) 7 | 8 | var ( 9 | debug bool 10 | trace bool 11 | ) 12 | 13 | type CliOptions struct { 14 | LogLevel logrus.Level 15 | } 16 | 17 | func GetCliFlagSet() *pflag.FlagSet { 18 | flagSet := &pflag.FlagSet{} 19 | flagSet.BoolVarP(&debug, "debug", "d", false, "Debug logging") 20 | flagSet.BoolVar(&trace, "trace", false, "Trace logging") 21 | return flagSet 22 | } 23 | 24 | func GetCliOptions() CliOptions { 25 | logLevel := logrus.InfoLevel 26 | if debug { 27 | logLevel = logrus.DebugLevel 28 | } 29 | if trace { 30 | logLevel = logrus.TraceLevel 31 | } 32 | 33 | return CliOptions{ 34 | LogLevel: logLevel, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pkg/config/ingress.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "net" 5 | "strconv" 6 | 7 | "github.com/spf13/pflag" 8 | ) 9 | 10 | var ingressOptions IngressOptions 11 | 12 | type IngressOptions struct { 13 | Host string 14 | Port int 15 | } 16 | 17 | func GetIngressFlagSet() *pflag.FlagSet { 18 | flagSet := &pflag.FlagSet{} 19 | flagSet.StringVar(&ingressOptions.Host, "host", "0.0.0.0", "Host for the API server to listen on") 20 | flagSet.IntVar(&ingressOptions.Port, "port", 25565, "Port for the API server to listen on") 21 | return flagSet 22 | } 23 | 24 | func GetIngressOptions() IngressOptions { 25 | return ingressOptions 26 | } 27 | 28 | func (ingressOptions *IngressOptions) GetAddress() string { 29 | return net.JoinHostPort(ingressOptions.Host, strconv.Itoa(ingressOptions.Port)) 30 | } 31 | -------------------------------------------------------------------------------- /pkg/config/k8s.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import "github.com/spf13/pflag" 4 | 5 | var k8sOptions K8SOptions 6 | 7 | type K8SOptions struct { 8 | KubeConfig string 9 | } 10 | 11 | func GetK8SFlagSet() *pflag.FlagSet { 12 | flagSet := &pflag.FlagSet{} 13 | flagSet.StringVar(&k8sOptions.KubeConfig, "kube-config", "", "KubeConfig path") 14 | return flagSet 15 | } 16 | 17 | func GetK8SOptions() K8SOptions { 18 | return k8sOptions 19 | } 20 | --------------------------------------------------------------------------------