Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure project around different CLI library #153

Merged
merged 1 commit into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bin/
dist/
.github/release-notes.md
.github/cover.out
.github/crds.yaml
clustercode-crd*.yaml
clustercode
testbin/
Expand Down
77 changes: 46 additions & 31 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Make sure to check the documentation at http://goreleaser.com

builds:
- env:
- CGO_ENABLED=0 # this is needed otherwise the Docker image build is faulty
goarch:
- amd64
goos:
- linux
- env:
- CGO_ENABLED=0 # this is needed otherwise the Docker image build is faulty
goarch:
- amd64
- arm64
goos:
- linux
goarm:
- 8

checksum:
name_template: 'checksums.txt'
Expand All @@ -15,38 +18,50 @@ snapshot:
name_template: "{{ .Tag }}-snapshot"

signs:
- artifacts: checksum
args: ["-u", "3D25B4013DDE195CB2DF2C6569E37C3C7822E698", "--output", "${signature}", "--detach-sign", "${artifact}"]
- artifacts: checksum
args: ["-u", "3D25B4013DDE195CB2DF2C6569E37C3C7822E698", "--output", "${signature}", "--detach-sign", "${artifact}"]

nfpms:
- vendor: ccremer
homepage: https://github.com/ccremer/clustercode
maintainer: ccremer
description: Clustercode converts media files in cluster with ffmpeg
license: MIT
file_name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
formats:
- deb
- rpm
- vendor: ccremer
homepage: https://github.com/ccremer/clustercode
maintainer: ccremer
description: Clustercode converts media files in Kubernetes with ffmpeg
license: MIT
file_name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
formats:
- deb
- rpm

dockers:
- image_templates:
- "docker.io/ccremer/clustercode:v{{ .Version }}"
- "quay.io/ccremer/clustercode:v{{ .Version }}"
- goarch: amd64
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
image_templates:
- "{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:v{{ .Version }}-amd64"

# For prereleases, updating `latest` and the floating tags of the major
# version does not make sense. Only the image for the exact version should
# be pushed.
- "{{ if not .Prerelease }}docker.io/ccremer/clustercode:v{{ .Major }}{{ end }}"
- "{{ if not .Prerelease }}quay.io/ccremer/clustercode:v{{ .Major }}{{ end }}"
- goarch: arm64
use: buildx
build_flag_templates:
- "--platform=linux/arm64/v8"
image_templates:
- "{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:v{{ .Version }}-arm64"

- "{{ if not .Prerelease }}docker.io/ccremer/clustercode:latest{{ end }}"
- "{{ if not .Prerelease }}quay.io/ccremer/clustercode:latest{{ end }}"
docker_manifests:
## ghcr.io
# For prereleases, updating `latest` does not make sense.
# Only the image for the exact version should be pushed.
- name_template: "{{ if not .Prerelease }}{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest{{ end }}"
image_templates:
- "{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:v{{ .Version }}-amd64"
- "{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:v{{ .Version }}-arm64"

- name_template: "{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:v{{ .Version }}"
image_templates:
- "{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:v{{ .Version }}-amd64"
- "{{ .Env.CONTAINER_REGISTRY }}/{{ .Env.IMAGE_NAME }}:v{{ .Version }}-arm64"

release:
prerelease: auto
github:
owner: ccremer
name: clustercode
extra_files:
- glob: ./clustercode-crd*.yaml
- glob: ./.github/crds.yaml
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ deploy: generate ## Deploy controller in the configured Kubernetes cluster in ~/

.PHONY: generate
generate: ## Generate manifests e.g. CRD, RBAC etc.
@CRD_ROOT_DIR="$(CRD_ROOT_DIR)" CRD_DOCS_REF_PATH="$(CRD_DOCS_REF_PATH)" go generate -tags=generate generate.go
@rm kustomize/*.yaml || true
@go generate -tags=generate ./...

.PHONY: crd
crd: generate ## Generate CRD to file
Expand Down
13 changes: 1 addition & 12 deletions Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ IMG_TAG ?= latest
BIN_FILENAME ?= $(PROJECT_ROOT_DIR)/clustercode
TESTBIN_DIR ?= $(PROJECT_ROOT_DIR)/testbin/bin

CRD_FILE ?= clustercode-crd.yaml
CRD_ROOT_DIR ?= kustomize/crd
CRD_SPEC_VERSION ?= v1

CRD_DOCS_REF_PATH ?= docs/modules/ROOT/pages/references/api-reference.adoc

# See https://storage.googleapis.com/kubebuilder-tools/ for list of supported K8s versions
INTEGRATIONTEST_K8S_VERSION ?= 1.20.2

KIND_VERSION ?= 0.9.0
KIND_NODE_VERSION ?= v1.20.0
KIND ?= $(TESTBIN_DIR)/kind

ENABLE_LEADER_ELECTION ?= false

KIND_KUBECONFIG ?= $(TESTBIN_DIR)/kind-kubeconfig-$(KIND_NODE_VERSION)
KIND_CLUSTER ?= clustercode-$(KIND_NODE_VERSION)
KIND_KUBECTL_ARGS ?= --validate=true
Expand All @@ -27,11 +19,8 @@ E2E_REPO ?= local.dev/clustercode/e2e
E2E_IMG = $(E2E_REPO):$(E2E_TAG)
OPERATOR_NAMESPACE ?= clustercode-system

KUSTOMIZE ?= go run sigs.k8s.io/kustomize/kustomize/v3

# Image URL to use all building/pushing image targets
DOCKER_IMG ?= docker.io/ccremer/clustercode:$(IMG_TAG)
QUAY_IMG ?= quay.io/ccremer/clustercode:$(IMG_TAG)
CONTAINER_IMG ?= ghcr.io/ccremer/clustercode:$(IMG_TAG)
FFMPEG_IMG ?= docker.io/jrottenberg/ffmpeg:4.1-alpine

testbin_created = $(TESTBIN_DIR)/.created
4 changes: 0 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ endif::[]

image:https://img.shields.io/github/workflow/status/ccremer/clustercode/Test[Test,link=https://github.com/ccremer/clustercode/actions?query=workflow%3ATest]
image:https://img.shields.io/github/go-mod/go-version/ccremer/clustercode[Go version]
image:https://img.shields.io/badge/k8s-v1.20-blue[Kubernetes version]
image:https://img.shields.io/github/v/release/ccremer/clustercode?include_prereleases[Version,link=https://github.com/ccremer/clustercode/releases]
image:https://img.shields.io/codeclimate/maintainability/ccremer/clustercode[Maintainability,link=https://codeclimate.com/github/ccremer/clustercode]
image:https://img.shields.io/codeclimate/coverage/ccremer/clustercode[Code Coverage,link=https://codeclimate.com/github/ccremer/clustercode]
image:https://img.shields.io/github/downloads/ccremer/clustercode/total[GitHub downloads,link=https://img.shields.io/docker/pulls/ccremer/clustercode]
image:https://img.shields.io/docker/pulls/ccremer/clustercode[Docker Hub,link=https://hub.docker.com/r/ccremer/clustercode]
image:https://img.shields.io/github/license/ccremer/clustercode[License,link=https://github.com/ccremer/clustercode/blob/master/LICENSE]

Automatically convert your movies and TV shows from one file format to another using ffmpeg in a cluster.
It's like an Ffmpeg operator!
Expand Down
12 changes: 12 additions & 0 deletions api/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build generate

// Remove existing manifests
//go:generate rm -rf ../package/crds ../package/webhook ../package/rbac

// Generate deepcopy methodsets and CRD manifests
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=../.github/boilerplate.go.txt paths=./... crd:crdVersions=v1 output:artifacts:config=../package/crds

// Generate webhook manifests
//go:generate go run -tags generate sigs.k8s.io/controller-tools/cmd/controller-gen webhook paths=./... output:artifacts:config=../package/webhook

package api
22 changes: 22 additions & 0 deletions api/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Package api contains Kubernetes API for the Template provider.
package api

import (
"github.com/ccremer/clustercode/api/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
)

// AddToSchemes may be used to add all resources defined in the project to a Scheme
var AddToSchemes runtime.SchemeBuilder

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes,
v1alpha1.AddToScheme,
)
}

// AddToScheme adds all Resources to the Scheme
func AddToScheme(s *runtime.Scheme) error {
return AddToSchemes.AddToScheme(s)
}
44 changes: 44 additions & 0 deletions base_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"context"

"github.com/ccremer/clustercode/api/v1alpha1"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type commandContext struct {
context.Context

kubeconfig *rest.Config
kube client.Client
scheme *runtime.Scheme
}

var createClientFn = func(ctx *commandContext) error {
kube, err := client.New(ctx.kubeconfig, client.Options{Scheme: ctx.scheme})
ctx.kube = kube
return err
}

var registerSchemesFn = func(ctx *commandContext) error {
ctx.scheme = runtime.NewScheme()
b := &runtime.SchemeBuilder{}
b.Register(
clientgoscheme.AddToScheme,
batchv1.AddToScheme,
v1alpha1.AddToScheme,
)
return b.AddToScheme(ctx.scheme)
}

var loadKubeConfigFn = func(ctx *commandContext) error {
clientConfig, err := ctrl.GetConfig()
ctx.kubeconfig = clientConfig
return err
}
8 changes: 0 additions & 8 deletions builder/builder.go

This file was deleted.

100 changes: 0 additions & 100 deletions builder/container.go

This file was deleted.

Loading