Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
femrtnz authored Oct 18, 2024
2 parents 826f89d + e919a04 commit f4639a8
Show file tree
Hide file tree
Showing 46 changed files with 725 additions and 245 deletions.
5 changes: 2 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
version: 2
updates:

- package-ecosystem: "gomod"
directory: "/"
schedule:
Expand All @@ -9,7 +8,7 @@ updates:
commit-message:
prefix: "dep: Go "
reviewers:
- "stepanstipl"
- "migueldelucasdoit"
- "dark0dave"

- package-ecosystem: "docker"
Expand All @@ -20,5 +19,5 @@ updates:
commit-message:
prefix: "dep: Docker "
reviewers:
- "stepanstipl"
- "migueldelucasdoit"
- "dark0dave"
50 changes: 33 additions & 17 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-latest
Expand All @@ -21,7 +24,7 @@ jobs:
test:
name: test
runs-on: ubuntu-latest
container: golang:1.22-alpine3.19
container: golang:1.23-alpine3.20
steps:
- name: Install git
run: apk add --update --no-cache git
Expand All @@ -37,7 +40,7 @@ jobs:
build:
name: build
runs-on: ubuntu-latest
container: golang:1.22-alpine3.19
container: golang:1.23-alpine3.20
strategy:
matrix:
os: [linux, darwin, windows]
Expand All @@ -58,12 +61,11 @@ jobs:
git config --global --add safe.directory /__w/kube-no-trouble/kube-no-trouble
scripts/alpine-setup.sh
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make all
make changelog
shell: sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Archive release artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: release-artifacts-${{ matrix.os }}-${{ matrix.arch }}
path: release-artifacts
Expand Down Expand Up @@ -102,33 +104,34 @@ jobs:
"kindest/node:v1.19.16",
"kindest/node:v1.20.15",
"kindest/node:v1.21.14",
"kindest/node:v1.22.15",
"kindest/node:v1.23.13",
"kindest/node:v1.24.7",
"kindest/node:v1.25.3",
"kindest/node:v1.26.6",
"kindest/node:v1.27.3",
"kindest/node:v1.28.0"
"kindest/node:v1.22.17",
"kindest/node:v1.23.17",
"kindest/node:v1.24.17",
"kindest/node:v1.25.16",
"kindest/node:v1.26.14",
"kindest/node:v1.27.11",
"kindest/node:v1.28.7",
"kindest/node:v1.29.2"
]
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
set-safe-directory: true
- uses: actions/download-artifact@v1
- uses: actions/download-artifact@v4
with:
name: release-artifacts-linux-amd64
path: release-artifacts
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.4.0
uses: helm/kind-action@v1.10.0
with:
node_image: ${{ matrix.k8s_version }}
cluster_name: kubent-test-cluster
- name: run integration test
run: |
tar xvzf release-artifacts/kubent-*-linux-amd64.tar.gz
kubectl version --short
kubectl version
kubectl cluster-info --context kind-kubent-test-cluster
./kubent
create-release:
Expand All @@ -141,7 +144,20 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
tag_name: ${{ steps.get_tag.outputs.git_tag }}
steps:
- uses: actions/download-artifact@v1
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
set-safe-directory: true
- name: Generate a changelog
uses: orhun/git-cliff-action@v3
id: git-cliff
with:
config: cliff.toml
args: --verbose --latest
env:
OUTPUT: changelog.md
- uses: actions/download-artifact@v4
with:
name: release-artifacts-linux-amd64
path: release-artifacts
Expand All @@ -156,7 +172,7 @@ jobs:
with:
tag_name: ${{ steps.get_tag.outputs.git_tag }}
release_name: ${{ steps.get_tag.outputs.git_tag }}
body_path: ./release-artifacts/changelog.md
body_path: ${{ steps.git-cliff.outputs.changelog }}
draft: ${{ startsWith(steps.get_tag.outputs.git_tag, 'nightly') != true }}
prerelease: ${{ startsWith(steps.get_tag.outputs.git_tag, 'nightly') }}
push-image:
Expand Down Expand Up @@ -209,7 +225,7 @@ jobs:
arch: arm64
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v1
- uses: actions/download-artifact@v4
with:
name: release-artifacts-${{ matrix.os }}-${{ matrix.arch }}
path: release-artifacts
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ fmtcoverage.html
.swp
.idea
.DS_Store

# changelog
changelog.md
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-json
stages: [pre-commit]
- id: check-added-large-files
stages: [pre-commit]
- id: trailing-whitespace
stages: [pre-commit]
- id: end-of-file-fixer
stages: [pre-commit]
exclude_types: [ svg ]
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: forbid-binary
stages: [pre-commit]
exclude_types: [ png ]
- id: git-dirty
stages: [pre-commit]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.11.0
hooks:
- id: pretty-format-golang
stages: [pre-commit]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
stages: [pre-commit]
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.22-alpine3.19 AS builder
FROM --platform=$BUILDPLATFORM golang:1.23-alpine3.20 AS builder
ARG GITHUB_REF GITHUB_SHA
WORKDIR /src
COPY go.mod go.sum ./
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ the following command to install `kubent`:
brew install kubent
```

#### Scoop
`kubent` is available for [Scoop](https://scoop.sh/) as an [app](https://bjansen.github.io/scoop-apps/main/kubent/).
Install `kubent` by running:

```powershell
scoop install kubent
```

## Usage

Configure Kubectl's current context to point to your cluster, `kubent` will
Expand Down Expand Up @@ -215,7 +223,7 @@ Otherwise there's `Makefile`
```sh
$ make
make
all Cean, build and pack
all Clean, build and pack
help Prints list of tasks
build Build binary
generate Go generate
Expand Down
36 changes: 28 additions & 8 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# git-cliff ~ default configuration file
# https://git-cliff.org/docs/configuration
#
# Lines starting with "#" are comments.
# Configuration options are organized into tables and keys.
# See documentation for more information on available options.

[remote.github]
owner = "doitintl"
repo = "kube-no-trouble"
[changelog]
# changelog header
header = ""
Expand All @@ -13,16 +11,36 @@ header = ""
body = """
**Docker Image**: {{ get_env(name='REGISTRY', default='') }}/{{ get_env(name='IMAG_NAME', default='') }}:{{ get_env(name='GITHUB_REF_NAME', default='') }}
### Changelog
### Changelog \
{% for group, commits in commits | group_by(attribute="group") %}
\n#### {{ group | striptags | trim | upper_first }}:
{% for commit in commits
| filter(attribute="group")
| sort(attribute="scope") %}
| unique(attribute="message")
| filter(attribute="merge_commit", value=false) %}
- {{commit.scope}}: \
{{ commit.message }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/doitintl/kube-no-trouble/commit/{{ commit.id }}) by [{{ commit.author.name }}](https://github.com/{{ commit.author.name }}))
{{ commit.message }}\
{% if not commit.github.pr_number %} [{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }}){%- endif %}\
{% if commit.github.username %} by @{{ commit.github.username }}\
{% else %} by [{{ commit.author.name }}](https://github.com/{{ commit.author.name }}){%- endif %}\
{%- endfor -%}
{% endfor %}
{% if version %}
{% if previous.version %}\
Full Changelog: [{{ previous.version }}...{{ version }}]({{ self::remote_url() }}/compare/{{ previous.version }}...{{ version }})\
{% endif %}\
{% else -%}\
{% raw %}\n{% endraw %}\
{% endif %}\
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
### New Contributors
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
* @{{ contributor.username }} made their first contribution in #{{ contributor.pr_number }}
{%- endfor -%}
{%- endif %}
{%- macro remote_url() -%}
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
"""
# remove the leading and trailing whitespace from the template
trim = true
Expand All @@ -42,6 +60,8 @@ split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
# { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"}, # replace issue numbers
# remove pr numbers from commits
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
# regex for parsing and grouping commits
commit_parsers = [
Expand Down
11 changes: 7 additions & 4 deletions cmd/kubent/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -96,11 +97,13 @@ func getServerVersion(cv *judge.Version, collectors []collector.Collector) (*jud
}

func main() {
ctx := context.Background()
exitCode := EXIT_CODE_FAIL_GENERIC

configureGlobalLogging()

config, err := config.NewFromFlags()
config, ctx, err := config.NewFromFlags(ctx)

if err != nil {
log.Fatal().Err(err).Msg("failed to parse config flags")
}
Expand Down Expand Up @@ -156,7 +159,7 @@ func main() {
log.Fatal().Err(err).Str("name", "Rego").Msg("Failed to filter results")
}

err = outputResults(results, config.Output, config.OutputFile)
err = outputResults(results, config.Output, config.OutputFile, ctx)
if err != nil {
log.Fatal().Err(err).Msgf("Failed to output results")
}
Expand All @@ -180,14 +183,14 @@ func configureGlobalLogging() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}

func outputResults(results []judge.Result, outputType string, outputFile string) error {
func outputResults(results []judge.Result, outputType string, outputFile string, ctx context.Context) error {
printer, err := printer.NewPrinter(outputType, outputFile)
if err != nil {
return fmt.Errorf("failed to create printer: %v", err)
}
defer printer.Close()

err = printer.Print(results)
err = printer.Print(results, ctx)
if err != nil {
return fmt.Errorf("failed to print results: %v", err)
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/kubent/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"errors"
Expand All @@ -13,6 +14,7 @@ import (

"github.com/doitintl/kube-no-trouble/pkg/collector"
"github.com/doitintl/kube-no-trouble/pkg/config"
ctxKey "github.com/doitintl/kube-no-trouble/pkg/context"
"github.com/doitintl/kube-no-trouble/pkg/judge"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -108,6 +110,7 @@ func TestMainExitCodes(t *testing.T) {
defer os.RemoveAll(tmpDir)

expectedJsonOutput, _ := os.ReadFile(filepath.Join(FIXTURES_DIR, "expected-json-output.json"))
expectedJsonOutputLabels, _ := os.ReadFile(filepath.Join(FIXTURES_DIR, "expected-json-output-labels.json"))
helm3FlagDisabled := "--helm3=false"
clusterFlagDisabled := "--cluster=false"
testCases := []struct {
Expand All @@ -121,6 +124,7 @@ func TestMainExitCodes(t *testing.T) {
{"success", []string{clusterFlagDisabled, helm3FlagDisabled}, 0, "", "", false},
{"errorBadFlag", []string{"-c=not-boolean"}, 2, "", "", false},
{"successFound", []string{"-o=json", clusterFlagDisabled, helm3FlagDisabled, "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1.yaml")}, 0, string(expectedJsonOutput), "", false},
{"successFoundWithLabels", []string{"--labels=true", "-o=json", clusterFlagDisabled, helm3FlagDisabled, "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1-labels.yaml")}, 0, string(expectedJsonOutputLabels), "", false},
{"exitErrorFlagNone", []string{clusterFlagDisabled, helm3FlagDisabled, "-e"}, 0, "", "", false},
{"exitErrorFlagFound", []string{clusterFlagDisabled, helm3FlagDisabled, "-e", "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1.yaml")}, 200, "", "", false},
{"version short flag set", []string{"-v"}, 0, "", "", false},
Expand All @@ -131,6 +135,7 @@ func TestMainExitCodes(t *testing.T) {
{"json-file", []string{"-o=json", clusterFlagDisabled, helm3FlagDisabled, "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1.yaml")}, 0, "", filepath.Join(tmpDir, "json-file.out"), false},
{"text-file", []string{"-o=text", clusterFlagDisabled, helm3FlagDisabled, "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1.yaml")}, 0, "", filepath.Join(tmpDir, "text-file.out"), false},
{"json-stdout", []string{"-o=json", clusterFlagDisabled, helm3FlagDisabled, "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1.yaml")}, 0, string(expectedJsonOutput), "-", false},
{"json-stdout-with-labels", []string{"--labels=true", "-o=json", clusterFlagDisabled, helm3FlagDisabled, "-f=" + filepath.Join(FIXTURES_DIR, "deployment-v1beta1-labels.yaml")}, 0, string(expectedJsonOutputLabels), "-", false},
{"error-bad-file", []string{clusterFlagDisabled, helm3FlagDisabled}, 1, "", "/this/dir/is/unlikely/to/exist", false},
{"no-3rdparty-output", []string{clusterFlagDisabled, helm3FlagDisabled, "-l=disabled"}, 0, "", "", true},
}
Expand Down Expand Up @@ -286,9 +291,12 @@ func Test_outputResults(t *testing.T) {
{"bad-new-printer-file", args{testResults, "text", "/unlikely/to/exist/dir"}, true},
}

labelsFlag := false
ctx := context.WithValue(context.Background(), ctxKey.LABELS_CTX_KEY, &labelsFlag)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResults(tt.args.results, tt.args.outputType, tt.args.outputFile); (err != nil) != tt.wantErr {
if err := outputResults(tt.args.results, tt.args.outputType, tt.args.outputFile, ctx); (err != nil) != tt.wantErr {
t.Errorf("unexpected error - got: %v, wantErr: %v", err, tt.wantErr)
}
})
Expand Down
Loading

0 comments on commit f4639a8

Please sign in to comment.