Skip to content

Commit

Permalink
Merge pull request #219 from bilalcaliskan/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
bilalcaliskan authored Oct 25, 2023
2 parents 486c7f5 + 5361bcd commit 98b454f
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 51 deletions.
35 changes: 19 additions & 16 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ jobs:
- name: Clean downloaded binaries
run: make -s clean

test:
tests:
strategy:
matrix:
# os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
name: test (${{ matrix.os }})
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -63,9 +65,18 @@ jobs:
exit 1
fi
shell: bash
- name: Test
- name: Run tests on ${{ matrix.os }}
run: make -s test

staticcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: dominikh/staticcheck-action@v1.3.0
with:
version: "2022.1.3"

codeql:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -97,18 +108,9 @@ jobs:
cache: true
- name: Install Nginx
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt update
sudo apt install nginx
sudo nginx
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install nginx
sudo ln -s /usr/local/etc/nginx /etc/nginx
sudo nginx
else
echo "$RUNNER_OS not supported"
exit 1
fi
sudo apt update
sudo apt install nginx
sudo nginx
shell: bash
- name: Coverage Test
run: make -s test-with-coverage
Expand All @@ -126,11 +128,12 @@ jobs:
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build:
builds:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: build (${{ matrix.os }})
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -139,5 +142,5 @@ jobs:
with:
go-version-file: "go.mod"
cache: true
- name: Test
- name: Build on ${{ matrix.os }}
run: make -s build
23 changes: 17 additions & 6 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ jobs:
- name: Clean downloaded binaries
run: make -s clean


test:
tests:
strategy:
matrix:
# os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
name: test (${{ matrix.os }})
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -67,9 +68,18 @@ jobs:
exit 1
fi
shell: bash
- name: Test
- name: Run tests on ${{ matrix.os }}
run: make -s test

staticcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: dominikh/staticcheck-action@v1.3.0
with:
version: "2022.1.3"

codeql:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -130,11 +140,12 @@ jobs:
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build:
builds:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: build (${{ matrix.os }})
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -143,12 +154,12 @@ jobs:
with:
go-version-file: "go.mod"
cache: true
- name: Build
- name: Build on ${{ matrix.os }}
run: make -s build

tag:
runs-on: ubuntu-latest
needs: [lint, fmt, test, codeql, sonarcloud, build]
needs: [lint, fmt, tests, staticcheck, codeql, sonarcloud, builds]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_nginx-conf-generator&metric=coverage)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_nginx-conf-generator)
[![Release](https://img.shields.io/github/release/bilalcaliskan/nginx-conf-generator.svg)](https://github.com/bilalcaliskan/nginx-conf-generator/releases/latest)
[![Go version](https://img.shields.io/github/go-mod/go-version/bilalcaliskan/nginx-conf-generator)](https://github.com/bilalcaliskan/nginx-conf-generator)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

That tool uses [client-go](https://github.com/kubernetes/client-go) to communicate with multi Kubernetes clusters and
Expand All @@ -28,33 +29,33 @@ Usage:
nginx-conf-generator [flags]
Flags:
--customAnnotation string annotation to specify selectable services (default "nginx-conf-generator/enabled")
-h, --help help for nginx-conf-generator
--kubeConfigPaths string comma separated list of kubeconfig file paths to access with the cluster (default "/home/joshsagredo/.kube/config")
--metricsEndpoint string endpoint to provide prometheus metrics (default "/metrics")
--metricsPort int port of the metrics server (default 5000)
--templateInputFile string path of the template input file to be able to render and print to --templateOutputFile (default "resources/ncg.conf.tmpl")
--templateOutputFile string path of the template output file which is a valid Nginx conf file (default "/etc/nginx/conf.d/ncg.conf")
-v, --verbose verbose output of the logging library (default false)
--version version for nginx-conf-generator
--workerNodeLabel string label to specify worker nodes (default "worker")
--custom-annotation string annotation to specify selectable services (default "nginx-conf-generator/enabled")
-h, --help help for nginx-conf-generator
--kubeconfig-paths string comma separated list of kubeconfig file paths to access with the cluster (default "/home/joshsagredo/.kube/config")
--metrics-endpoint string endpoint to provide prometheus metrics (default "/metrics")
--metrics-port int port of the metrics server (default 5000)
--template-input-file string path of the template input file to be able to render and print to --template-output-file (default "resources/ncg.conf.tmpl")
--template-output-file string rendered output file path which is a valid Nginx conf file (default "/etc/nginx/conf.d/ncg.conf")
-v, --verbose verbose output of the logging library (default false)
--version version for nginx-conf-generator
--worker-node-label string label to specify worker nodes (default "worker")
```

> That tool should be run on a Linux host and the user who runs the binary file nginx-conf-generator
should have permissions to edit **--templateOutputFile** file and reload nginx process using below command:
should have permissions to edit **--template-output-file** file and reload nginx process using below command:
> ```shell
> $ nginx -s reload
> ```
> If you want to cover multiple kubernetes clusters, add comma seperated list of kubeconfig paths with **--kubeConfigPaths** argument.
> If you want to cover multiple kubernetes clusters, add comma seperated list of kubeconfig paths with **--kubeconfig-paths** argument.
## Installation
### Binary
Binary can be downloaded from [Releases](https://github.com/bilalcaliskan/nginx-conf-generator/releases) page.
After then, you can simply run binary by providing required command line arguments:
```shell
$ ./nginx-conf-generator --kubeConfigPaths ~/.kube/config1,~/.kube/config2 --customAnnotation nginx-conf-generator/enabled
$ ./nginx-conf-generator --kubeconfig-paths=~/.kube/config1,~/.kube/config2 --custom-annotation nginx-conf-generator/enabled
```
### Homebrew
Expand All @@ -66,7 +67,7 @@ brew install bilalcaliskan/tap/nginx-conf-generator

## Development
This project requires below tools while developing:
- [Golang 1.19](https://golang.org/doc/go1.19)
- [Golang 1.20](https://golang.org/doc/go1.20)
- [pre-commit](https://pre-commit.com/)
- [golangci-lint](https://golangci-lint.run/usage/install/) - required by [pre-commit](https://pre-commit.com/)
- [gocyclo](https://github.com/fzipp/gocyclo) - required by [pre-commit](https://pre-commit.com/)
Expand Down
2 changes: 1 addition & 1 deletion build/ci/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ repos:
args: [-over=30]
- id: no-go-testing
- id: golangci-lint
# - id: go-unit-tests
- id: go-unit-tests
- id: go-build
24 changes: 12 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ var (
func init() {
opts = options.GetNginxConfGeneratorOptions()

rootCmd.Flags().StringVarP(&opts.KubeConfigPaths, "kubeConfigPaths", "", filepath.Join(os.Getenv("HOME"), ".kube", "config"),
rootCmd.Flags().StringVarP(&opts.KubeConfigPaths, "kubeconfig-paths", "", filepath.Join(os.Getenv("HOME"), ".kube", "config"),
"comma separated list of kubeconfig file paths to access with the cluster")
rootCmd.Flags().StringVarP(&opts.WorkerNodeLabel, "workerNodeLabel", "", "worker",
rootCmd.Flags().StringVarP(&opts.WorkerNodeLabel, "worker-node-label", "", "worker",
"label to specify worker nodes")
rootCmd.Flags().StringVarP(&opts.CustomAnnotation, "customAnnotation", "", "nginx-conf-generator/enabled",
rootCmd.Flags().StringVarP(&opts.CustomAnnotation, "custom-annotation", "", "nginx-conf-generator/enabled",
"annotation to specify selectable services")
rootCmd.Flags().StringVarP(&opts.TemplateInputFile, "templateInputFile", "", "resources/ncg.conf.tmpl",
"path of the template input file to be able to render and print to --templateOutputFile")
rootCmd.Flags().StringVarP(&opts.TemplateOutputFile, "templateOutputFile", "", "/etc/nginx/conf.d/ncg.conf",
"path of the template output file which is a valid Nginx conf file")
rootCmd.Flags().IntVarP(&opts.MetricsPort, "metricsPort", "", 5000,
rootCmd.Flags().StringVarP(&opts.TemplateInputFile, "template-input-file", "", "resources/ncg.conf.tmpl",
"path of the template input file to be able to render and print to --template-output-file")
rootCmd.Flags().StringVarP(&opts.TemplateOutputFile, "template-output-file", "", "/etc/nginx/conf.d/ncg.conf",
"rendered output file path which is a valid Nginx conf file")
rootCmd.Flags().IntVarP(&opts.MetricsPort, "metrics-port", "", 5000,
"port of the metrics server")
rootCmd.Flags().StringVarP(&opts.BannerFilePath, "bannerFilePath", "", "build/ci/banner.txt",
"relative path of the banner file")
rootCmd.Flags().StringVarP(&opts.MetricsEndpoint, "metricsEndpoint", "", "/metrics",
rootCmd.Flags().StringVarP(&opts.MetricsEndpoint, "metrics-endpoint", "", "/metrics",
"endpoint to provide prometheus metrics")
rootCmd.Flags().StringVarP(&opts.BannerFilePath, "banner-file-path", "", "build/ci/banner.txt",
"relative path of the banner file")
rootCmd.Flags().BoolVarP(&opts.VerboseLog, "verbose", "v", false, "verbose output of the logging library (default false)")

if err := rootCmd.Flags().MarkHidden("bannerFilePath"); err != nil {
if err := rootCmd.Flags().MarkHidden("banner-file-path"); err != nil {
panic("fatal error occured while hiding flag")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/k8s/informers/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

func TestGetClientSet(t *testing.T) {
restConfig, err := GetConfig("../../../mock/kubeconfig")
restConfig, err := GetConfig("../../../test/kubeconfig")
assert.Nil(t, err)
assert.NotNil(t, restConfig)

clientSet, err := GetClientSet(restConfig)
assert.Nil(t, err)
assert.NotNil(t, clientSet)

restConfig, err = GetConfig("../../../mock/broken_kubeconfig")
restConfig, err = GetConfig("../../../test/broken_kubeconfig")
assert.NotNil(t, err)
assert.Nil(t, restConfig)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 98b454f

Please sign in to comment.