-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ravi Hari <ravireliable@gmail.com>
- Loading branch information
Showing
66 changed files
with
4,012 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Project specific | ||
release | ||
coverage.* | ||
|
||
# Created by .ignore support plugin (hsz.mobi) | ||
### macOS template | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Go template | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# CMake | ||
cmake-build-*/ | ||
|
||
# File-based project format | ||
*.iws | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
.idea | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
BINARY := manny | ||
PKGS := $(shell go list ./... | grep -v /vendor) | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
.PHONY: all build clean spotless test cover release artifactory-upload ${GOBIN}/${BINARY} | ||
|
||
all: vendor test build | ||
|
||
build: ${GOBIN}/${BINARY} | ||
|
||
${GOBIN}/${BINARY}: | ||
go build -o $@ main.go | ||
|
||
clean: | ||
@echo "Removing package object files..." | ||
@go clean ${PKGS} | ||
@echo "Removing cache test results..." | ||
@go clean -testcache | ||
|
||
spotless: clean | ||
@echo "Removing vendor directory..." | ||
@-rm -rf vendor | ||
|
||
vendor: spotless | ||
@echo "Refreshing dependencies..." | ||
@go mod tidy && go mod vendor | ||
|
||
test: | ||
go test ${PKGS} ${TESTARGS} | ||
|
||
cover: TESTARGS=-coverprofile=coverage.out | ||
cover: test | ||
go tool cover -func=coverage.out -o coverage.txt | ||
go tool cover -html=coverage.out -o coverage.html | ||
@cat coverage.txt | ||
@echo "Run 'open coverage.html' to view coverage report." | ||
|
||
VERSION ?= vlatest | ||
PLATFORMS := windows linux darwin | ||
os = $(word 1, $@) | ||
|
||
.PHONY: $(PLATFORMS) | ||
$(PLATFORMS): | ||
mkdir -p release | ||
GOOS=$(os) GOARCH=amd64 go build -o release/$(BINARY)-$(VERSION)-$(os)-amd64 | ||
|
||
release: windows linux darwin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,61 @@ | ||
# manny | ||
|
||
[![Build Status][BuildStatusImg]][BuildMasterURL] | ||
[![Code Coverage][CodecovImg]][CodecovURL] | ||
|
||
Argo CD tool to generate K8s manifests from GitOps repo | ||
|
||
## Installation | ||
|
||
This process for adding additional custom tools to Argo CD is documented here: | ||
|
||
* https://argoproj.github.io/argo-cd/operator-manual/custom_tools/ | ||
|
||
The ArgoCD repo-server deployment must be updated to include an init container that downloads and installed manny. | ||
|
||
``` yaml | ||
spec: | ||
template: | ||
spec: | ||
volumes: | ||
- name: custom-tools | ||
emptyDir: {} | ||
initContainers: | ||
- name: download-tools | ||
image: alpine:3.8 | ||
command: [sh, -c] | ||
args: | ||
- wget -q -O manny.gz https://github.com/keikoproj/manny/manny-vlatest-linux-amd64.gz && | ||
gunzip manny.gz && | ||
chmod +x manny && | ||
mv manny /custom-tools/manny | ||
volumeMounts: | ||
- mountPath: /custom-tools | ||
name: custom-tools | ||
containers: | ||
- name: argocd-repo-server | ||
volumeMounts: | ||
- mountPath: /usr/local/bin/manny | ||
name: custom-tools | ||
subPath: manny | ||
``` | ||
The Argo CD configmap must be updated to install manny as a plugin. | ||
``` yaml | ||
data: | ||
configManagementPlugins: | | ||
- name: manny | ||
generate: | ||
command: [sh, -c] | ||
args: ["manny build ."] | ||
``` | ||
Also, for each Argo CD app that intends to use manny, the Application must be updated to reference the manny plugin. | ||
``` yaml | ||
spec: | ||
source: | ||
plugin: | ||
name: manny | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/go-git/go-git/v5" | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
|
||
"github.com/keikoproj/manny/configurator" | ||
"github.com/keikoproj/manny/utils" | ||
) | ||
|
||
var ( | ||
buildCmd = &cobra.Command{ | ||
Use: "build path/to/stacks", | ||
Short: "Builds a manny deployment", | ||
Long: "Builds a manny deployment", | ||
Example: "manny build usw2", | ||
RunE: buildConfig, | ||
} | ||
) | ||
|
||
func buildConfig(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return errors.New(ErrMissingArg) | ||
} | ||
|
||
path := args[0] | ||
|
||
Logger.Debug("Git repository path", zap.String("repo-path", filepath.Join(path, git.GitDirName))) | ||
|
||
gitURL, err := utils.GitRepoRemote(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// create a new configurator with defaults | ||
config := configurator.New(configurator.Config{ | ||
Path: path, | ||
Logger: Logger, | ||
GitURL: gitURL, | ||
}) | ||
|
||
deployments, err := config.CreateDeployments() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
Logger.Debug("Deployments created", zap.Any("CloudResourceDeployments", len(deployments))) | ||
|
||
if validate { | ||
if err := deployments.Validate(); err != nil { | ||
Logger.Error("Validation failed", zap.Error(err)) | ||
return err | ||
} | ||
} | ||
|
||
// early return for dry run | ||
if dryRun { | ||
return nil | ||
} | ||
|
||
// render the manifest in a given format | ||
bytes, err := deployments.Render(format) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// output to location | ||
if output != "stdout" { | ||
// File location validation | ||
ok, err := utils.ValidateAndWrite(output, bytes) | ||
if !ok { | ||
return err | ||
} | ||
|
||
// early return | ||
return nil | ||
} | ||
|
||
// write to stdout | ||
fmt.Printf("%s", bytes) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
const ( | ||
ErrMissingArg = "missing argument" | ||
ConfigDebug = "debug" | ||
ConfigFormat = "format" | ||
OutputFormat = "output" | ||
ConfigValidate = "validate" | ||
ConfigDryRun = "dry-run" | ||
) | ||
|
||
var ( | ||
Logger *zap.Logger | ||
|
||
// flag storage | ||
debug bool | ||
format string | ||
output string | ||
dryRun bool | ||
validate bool | ||
|
||
// Commands | ||
rootCmd = &cobra.Command{ | ||
Use: "manny", | ||
Short: "Argo CD tool to generate K8s manifests from GitOps repo", | ||
Long: `Argo CD tool to generate K8s manifests from GitOps repo`, | ||
} | ||
) | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initLogger) | ||
|
||
rootCmd.AddCommand(buildCmd) | ||
|
||
rootCmd.PersistentFlags().BoolVarP(&debug, ConfigDebug, "D", false, "sets debug mode") | ||
buildCmd.PersistentFlags().StringVarP(&format, ConfigFormat, "f", "yaml", "sets output format") | ||
buildCmd.PersistentFlags().StringVarP(&output, OutputFormat, "o", "stdout", "sets file location") | ||
buildCmd.PersistentFlags().BoolVarP(&validate, ConfigValidate, "", true, "validates the CloudFormation output") | ||
buildCmd.PersistentFlags().BoolVarP(&dryRun, ConfigDryRun, "", false, "does not output a CloudResource") | ||
} | ||
|
||
// initLogger reads in config file and ENV variables if set. | ||
func initLogger() { | ||
cfg := zap.Config{ | ||
Encoding: "console", | ||
OutputPaths: []string{"stderr"}, | ||
ErrorOutputPaths: []string{"stderr"}, | ||
Level: zap.NewAtomicLevelAt(zapcore.InfoLevel), | ||
EncoderConfig: zapcore.EncoderConfig{ | ||
MessageKey: "message", | ||
|
||
LevelKey: "level", | ||
EncodeLevel: zapcore.CapitalLevelEncoder, | ||
|
||
TimeKey: "time", | ||
EncodeTime: zapcore.ISO8601TimeEncoder, | ||
|
||
CallerKey: "caller", | ||
EncodeCaller: zapcore.ShortCallerEncoder, | ||
}, | ||
} | ||
|
||
if debug { | ||
cfg.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel) | ||
} | ||
|
||
l, err := cfg.Build() | ||
if err != nil { | ||
fmt.Printf("Error setting up logger: %s", err) | ||
} | ||
|
||
Logger = l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ignore: | ||
- cmd |
Oops, something went wrong.