Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Replace TOML config with YAML config (#1)
Browse files Browse the repository at this point in the history
* Replace TOML config with YAML config

* Fix yaml config

* Remove unnecessary function from config.go
  • Loading branch information
iamd3vil authored and mr-karan committed Dec 30, 2019
1 parent 9ef5915 commit 5b1f739
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -18,7 +18,7 @@ vendor/
# App Specific
.kubekutr
.env
config.toml
config.yml
kubekutr

.DS_Store
2 changes: 1 addition & 1 deletion .goreleaser.yml
Expand Up @@ -20,6 +20,6 @@ builds:
archives:
- format: tar.gz
files:
- config.sample.toml
- config.sample.yml
- README.md
- LICENSE
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -46,7 +46,7 @@ GLOBAL OPTIONS:
```bash
# create a new base

$ kubekutr -c config.toml scaffold -o myapp
$ kubekutr -c config.yml scaffold -o myapp

# `myapp` is created with the GitOps structure
myapp
Expand All @@ -63,7 +63,7 @@ myapp

## Configuration

- **[deployments]**
- **deployments**

- **name**: Name of the deployment
- **replicas**: Represents the number of replicas for a `Pod`
Expand All @@ -86,7 +86,7 @@ myapp
- **volumes**: List of volumes defined for a deployment
- **name**: Name of Volume

- **[statefulsets]**
- **statefulsets**

- **name**: Name of the statefulset
- **serviceName**: serviceName is the name of the service that governs this StatefulSet
Expand All @@ -104,7 +104,7 @@ myapp
- **selectors**:
- **name**: Route service traffic to pods with label keys and values matching this selector

- **[ingresses]**
- **ingresses**

- **name**: Name of ingress
- **ingressPaths**
Expand Down
4 changes: 2 additions & 2 deletions TODO.md
Expand Up @@ -16,7 +16,7 @@

- [X] Better comments and logging

- [X] Full config.toml.sample
- [X] Full config.sample.yml

- [X] Release/Readme

Expand All @@ -26,6 +26,6 @@

- [ ] More resources and specs

- [ ] Add support for config in YAML
- [X] Add support for config in YAML

- [ ] Blogpost on a working example
16 changes: 5 additions & 11 deletions cmd/config.go
Expand Up @@ -4,14 +4,14 @@ import (
"log"

"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/toml"
"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/file"
"github.com/urfave/cli"
"zerodha.tech/kubekutr/models"
)

// initConfig initializes the app's configuration manager.
func initConfig(c *cli.Context) models.Config {
func initConfig(c *cli.Context) (models.Config, error) {
var cfg = models.Config{}
var ko = koanf.New(".")

Expand All @@ -20,17 +20,11 @@ func initConfig(c *cli.Context) models.Config {
}
for _, f := range c.GlobalStringSlice("config") {
log.Printf("reading config: %s", f)
if err := ko.Load(file.Provider(f), toml.Parser()); err != nil {
if err := ko.Load(file.Provider(f), yaml.Parser()); err != nil {
log.Fatalf("error reading config: %v", err)
}
}
// Read the configuration and load it to internal struct.
failOnReadConfigErr(ko.Unmarshal("", &cfg))
return cfg
}

func failOnReadConfigErr(err error) {
if err != nil {
log.Fatalf("error reading config: %v.", err)
}
err := ko.Unmarshal("", &cfg)
return cfg, err
}
8 changes: 7 additions & 1 deletion cmd/hub.go
@@ -1,6 +1,8 @@
package cmd

import (
"log"

"github.com/knadh/stuffbin"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -29,8 +31,12 @@ func NewHub(logger *logrus.Logger, fs stuffbin.FileSystem, buildVersion string)
// Use this middleware to perform any action before the command is run.
func (hub *Hub) initApp(fn cli.ActionFunc) cli.ActionFunc {
return func(c *cli.Context) error {
var err error
// Initialize config.
hub.Config = initConfig(c)
hub.Config, err = initConfig(c)
if err != nil {
log.Fatalf("error while reading config: %v", err)
}
return fn(c)
}
}
65 changes: 0 additions & 65 deletions config.sample.toml

This file was deleted.

63 changes: 63 additions & 0 deletions config.sample.yml
@@ -0,0 +1,63 @@
deployments:
- name: app
replicas: 3
labels:
- name: 'service: app'
- name: 'tier: frontend'
containers:
- name: app
image: 'myapp:latest'
envSecret: myapp
portInt: 3000
portName: app-port
command: '["./myapp"]'
args: '["--config", "--hello"]'
envVars:
- name: hello
value: iamsecret
volumeMounts:
- name: config-dir
mountPath: /etc/config
subPath: config.toml
volumes:
- name: config-dir

services:
- name: app
type: NodePort
port: 7000
targetPort: 8000
labels:
- name: 'service: app'
selectors:
- name: 'tier: frontend'

ingresses:
- name: app
annotations:
- name: 'alb.ingress.kubernetes.io/healthy-threshold-count: "2"'
ingressPaths:
- path: /503
service: app
port: use-annotation

statefulsets:
- name: db
serviceName: db-headless
labels:
- name: 'service: postgres'
- name: 'tier: db'
containers:
- name: postgres
image: 'postgres:latest'
envSecret: postgres
portInt: 5432
portName: db-port
envVars:
- name: POSTGRES_DB
value: sample
volumeMounts:
- name: db-dir
mount: /var/lib/postgres
volumes:
- name: db-dir
3 changes: 0 additions & 3 deletions go.mod
Expand Up @@ -3,11 +3,8 @@ module zerodha.tech/kubekutr
go 1.12

require (
github.com/c-bata/go-prompt v0.2.3
github.com/knadh/koanf v0.6.0
github.com/knadh/stuffbin v1.0.0
github.com/mattn/go-tty v0.0.3 // indirect
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.5 // indirect
github.com/urfave/cli v1.22.2
Expand Down
17 changes: 0 additions & 17 deletions go.sum
@@ -1,7 +1,5 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/c-bata/go-prompt v0.2.3 h1:jjCS+QhG/sULBhAaBdjb2PlMRVaKXQgn+4yzaauvs2s=
github.com/c-bata/go-prompt v0.2.3/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -20,21 +18,10 @@ github.com/knadh/stuffbin v1.0.0 h1:NQon6PTpLXies4bRFhS3VpLCf6y+jn6YVXU3i2wPQ+M=
github.com/knadh/stuffbin v1.0.0/go.mod h1:yVCFaWaKPubSNibBsTAJ939q2ABHudJQxRWZWV5yh+4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.4.0 h1:u3Z1r+oOXJIkxqw34zVhyPgjBsm6X2wn21NWs/HfSeg=
github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo=
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 h1:A7GG7zcGjl3jqAqGPmcNjd/D9hzL95SuoOQAaFNdLU0=
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
Expand All @@ -54,12 +41,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 h1:gSbV7h1NRL2G1xTg/owz62CST1oJBmxy4QpMMregXVQ=
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down

0 comments on commit 5b1f739

Please sign in to comment.