Skip to content

Commit

Permalink
Merge pull request #1 from ardikabs/add-ci-moving-internal-to-pkg
Browse files Browse the repository at this point in the history
feat: preparation for first release
ardikabs authored Nov 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 08d5915 + cce24c5 commit d375952
Showing 54 changed files with 357 additions and 47 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Release

on:
push:
tags:
- "v*.*.*"

permissions:
contents: write
packages: write

jobs:
test:
uses: ./.github/workflows/test.yaml

release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ^1.21.x

- name: Get Tag
id: tag
uses: devops-actions/action-get-tag@v1.0.2
with:
strip_v: true

- uses: docker/setup-qemu-action@v2

- uses: docker/setup-buildx-action@v2
with:
endpoint: builders

- name: Log in to the GitHub Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ steps.tag.outputs.tag }}
43 changes: 43 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "**/*.go"

workflow_call:

jobs:
audit:
name: Auditing the code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ^1.21.x

- name: Install make
run: |
sudo apt update -y
sudo apt install make curl git -y
- name: Run audit
run: |
make lint
make test
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
file: ./output/coverage.out
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Options for analysis running.
run:
tests: true
go: "1.20"
timeout: 5m
go: "1.21"
88 changes: 88 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: 1
before:
hooks:
- go mod tidy

builds:
- binary: helmize
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
goarm:
- "6"
- "7"
ldflags:
- -X github.com/ardikabs/helmize/cmd.Version={{.Version}}
- -X github.com/ardikabs/helmize/cmd.GitCommit={{.Commit}}
ignore:
- goos: windows
goarch: arm64

archives:
- format: binary

changelog:
filters:
exclude:
- "^Release version"
- "^Merge pull request"

checksum:
name_template: "checksums.txt"

release:
github:
owner: ardikabs
name: helmize
name_template: "Version {{.Version}}"

dockers:
- goos: linux
goarch: amd64
use: buildx
dockerfile: .goreleaser.Dockerfile
image_templates:
- "ghcr.io/ardikabs/helmize:latest-amd64"
- "ghcr.io/ardikabs/helmize:{{ .Major }}-amd64"
- "ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}-amd64"
- "ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
build_flag_templates:
- "--builder=builders"
- "--platform=linux/amd64"

- goos: linux
goarch: arm64
use: buildx
dockerfile: .goreleaser.Dockerfile
image_templates:
- "ghcr.io/ardikabs/helmize:latest-amd64"
- "ghcr.io/ardikabs/helmize:{{ .Major }}-amd64"
- "ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}-amd64"
- "ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
build_flag_templates:
- "--builder=builders"
- "--platform=linux/arm64"

docker_manifests:
- name_template: ghcr.io/ardikabs/helmize:latest
image_templates:
- ghcr.io/ardikabs/helmize:latest-amd64
- ghcr.io/ardikabs/helmize:latest-arm64
- name_template: ghcr.io/ardikabs/helmize:v{{ .Major }}
image_templates:
- ghcr.io/ardikabs/helmize:{{ .Major }}-amd64
- ghcr.io/ardikabs/helmize:{{ .Major }}-arm64
- name_template: ghcr.io/ardikabs/helmize:v{{ .Major }}.{{ .Minor }}
image_templates:
- ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}-amd64
- ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}-arm64
- name_template: ghcr.io/ardikabs/helmize:v{{ .Major }}.{{ .Minor }}.{{ .Patch }}
image_templates:
- ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64
- ghcr.io/ardikabs/helmize:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64
5 changes: 5 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ghcr.io/ardikabs/etc/shell

USER nobody
COPY helmize /usr/bin/helmize
CMD ["/usr/bin/helmize"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Ardika Bagus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 10 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ GitCommit := $(shell git rev-parse HEAD)
LDFLAGS := "-s -w -X github.com/ardikabs/helmize/cmd.Version=$(Version) -X github.com/ardikabs/helmize/cmd.GitCommit=$(GitCommit)"
OUTDIR := bin

GOLANGCI_VERSION = 1.31.0
GOLANGCI_VERSION = 1.53.3

## help: print this help message
.PHONY: help
@@ -17,43 +17,41 @@ bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}

bin/golangci-lint-${GOLANGCI_VERSION}:
@mkdir -p bin
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ./bin/ v${GOLANGCI_VERSION}
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(OUTDIR) v$(GOLANGCI_VERSION)
@mv bin/golangci-lint "$@"

## audit: tidy and vendor dependencies and format, vet, lint and test all code
## audit: format, tidying, vet, lint and test all code
.PHONY: audit
audit: fmt vendor lint vet test
audit: fmt mod lint vet test

## fmt: formatting the code
fmt:
@echo 'Formatting code...'
@go fmt $(shell go list ./... | grep -v /vendor/|xargs echo)

## vendor: tidy and vendor dependencies
.PHONY: vendor
vendor:
## mod: tidying module dependencies
.PHONY: mod
mod:
@echo 'Tidying and verifying module dependencies...'
@go mod tidy
@go mod verify
@echo 'Vendoring dependencies...'
@go mod vendor

## lint: linting the code
.PHONY: lint
lint: bin/golangci-lint
@echo 'Linting code...'
bin/golangci-lint run

## test: run unit test
## test: running unit test
.PHONY: test
test:
@echo 'Running tests...'
@mkdir -p output
@go test $(shell go list ./... | grep -v /vendor/|xargs echo) -cover -coverprofile=./output/coverage.out -race && \
@go test $(shell go list ./... | grep -v /vendor/|xargs echo) -v -covermode=atomic -cover -coverprofile=./output/coverage.out -race && \
go tool cover -html=./output/coverage.out -o ./output/coverage.html && \
go tool cover -func=./output/coverage.out

## vet: run vetting the code
## vet: vetting the code
.PHONY: vet
vet:
@echo 'Vetting code...'
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Helmize

[![Go Reference](https://pkg.go.dev/badge/github.com/ardikabs/helmize.svg)](https://pkg.go.dev/github.com/ardikabs/helmize)
[![Go Report Card](https://goreportcard.com/badge/github.com/ardikabs/helmize)](https://goreportcard.com/report/github.com/ardikabs/helmize)
[![Test Status](https://github.com/ardikabs/helmize/actions/workflows/test.yml/badge.svg?branch=main)]
[![Codecov](https://codecov.io/gh/ardikabs/helmize/branch/main/graph/badge.svg)](https://codecov.io/gh/ardikabs/helmize)

> A KRM function to enable Helm on Kustomize with Glob support
The motivation for this project is quite simple. While [Helm integration](https://kubectl.docs.kubernetes.io/references/kustomize/builtins/#_helmchartinflationgenerator_) in Kustomize is already available, it falls short in scenarios where dynamic use of Glob is required to fetch all necessary values.yaml files. In such cases, it lacks support.
57 changes: 48 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -4,40 +4,79 @@ import (
"os"

"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
"github.com/ardikabs/helmize/internal/krm"
"github.com/ardikabs/helmize/pkg/processor"
"github.com/lithammer/dedent"
"github.com/spf13/cobra"
)

var files []string

func MakeRoot() *cobra.Command {
var cmd = &cobra.Command{
Use: "helmize",
Short: "helmize is a KRM Function to enable Helm on Kustomize with Glob support",
Example: dedent.Dedent(`
Helmize is intended to be used as KRM function only,
thus a standalone usage is not supported.
Initially Helmize used as KRM function only, but it also support for direct use through flag.
> KRM usage:
Within "generators" fields through annotations [config.kubernetes.io/function]
annotations:
config.kubernetes.io/function: |
exec:
path: helmize
KRM usage:
$ kustomize build --enable-alpha-plugins --enable-exec /path/to/kustomization_dir
$ kustomize build --enable-alpha-plugins --enable-exec .
> Direct usage:
$ helmize [-f HELM_RELEASE_FILE]
`),
}

cmd.Args = cobra.MaximumNArgs(0)
cmd.RunE = run

cmd.Flags().StringArrayVarP(&files, "file", "f", []string{}, "specify HelmRelease in a YAML file (can specify multiple times)")
return cmd
}

func run(cmd *cobra.Command, args []string) error {
stdinStat, _ := os.Stdin.Stat()
// Direct usage
if len(files) > 0 {
var generatedObjects fn.KubeObjects
for _, file := range files {

raw, err := os.ReadFile(file)
if err != nil {
return err
}

kubeObjects, err := fn.ParseKubeObjects(raw)
if err != nil {
return err
}

generated, err := processor.ProcessKubeObjects(kubeObjects)
if err != nil {
return err
}
generatedObjects = append(generatedObjects, generated...)
}

os.Stdout.Write([]byte(generatedObjects.String()))
return nil
}

// KRM usage
stdinStat, _ := os.Stdin.Stat()
// Check the StdIn content.
if (stdinStat.Mode() & os.ModeCharDevice) != 0 {
cmd.Help()
os.Exit(1)
return cmd.Help()
}

if err := fn.AsMain(fn.ResourceListProcessorFunc(krm.Process)); err != nil {
if err := fn.AsMain(fn.ResourceListProcessorFunc(processor.ProcessResourceList)); err != nil {
os.Exit(1)
}

Loading

0 comments on commit d375952

Please sign in to comment.