Skip to content

Commit dfdbe1a

Browse files
committed
[AWS] Feat: Added EKS feature
1 parent 37bf24d commit dfdbe1a

File tree

16 files changed

+446
-362
lines changed

16 files changed

+446
-362
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
# tmp builds by air
1919
tmp
2020
logs
21-
config/config.yaml
21+
config/config.yaml
22+
reka-state.json

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ A Cloud Infrastructure Management Tool to stop, resume, clean and destroy resour
1111
This tool is **HIGHLY DESTRUCTIVE** and can deletes all resources! This should be used in environments with **WITH CAUTION**.
1212

1313
### TODO
14-
- [x] Bootstrap application architecture
1514
- [x] Schedule resource refreshing
16-
- [ ] Create Web Dashboard
1715
- [x] generate Sample Yaml config and load config
16+
- [ ] Create Web Dashboard
1817
- [ ] Allow users to specify tags/resources to track from reka UI with reaping Details
19-
- [ ] Support Manual Trigger of resources reaping from Dashboard/CLI
20-
- [ ] Allow authentication username and password set in config file
18+
- [ ] Persist state to remote sources (GCS, S3, if possible Databases)
19+
- [ ] Allow web authentication username and password set in config file
2120
- [ ] Create Kubernetes Manifests and Helm Charts
22-
- [ ] Create CLI
23-
- [ ] Save infra state and desired state in persistent storage
2421

2522
#### Supported Resources
2623
- AWS: https://github.com/MeNsaaH/reka/issues/1
@@ -31,10 +28,11 @@ This tool is **HIGHLY DESTRUCTIVE** and can deletes all resources! This should b
3128
Copy `config/config.example.yaml` to `config/config.yaml` and make all necessary changes
3229
```bash
3330
cp config/config.example.yaml config/config.yaml
34-
35-
# Start Web UI
36-
cd web
31+
# One time run
3732
go run main.go --config ../config/config.yaml
33+
34+
# Web Dashboard
35+
go run main.go web --config ../config/config.yaml
3836
```
3937

4038
using [air](https://github.com/cosmtrek/air) with autoreload UI features

config/aws.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package config
22

33
import (
4+
"context"
5+
46
"github.com/aws/aws-sdk-go-v2/aws"
57
awsCfg "github.com/aws/aws-sdk-go-v2/config"
68

@@ -13,17 +15,18 @@ func loadAwsConfig(accessKeyID, secretAccessKey, defaultRegion string) aws.Confi
1315
err error
1416
cfg aws.Config
1517
)
18+
ctx := context.TODO()
1619

1720
if accessKeyID != "" && secretAccessKey != "" {
18-
cfg, err = awsCfg.LoadDefaultConfig(
21+
cfg, err = awsCfg.LoadDefaultConfig(ctx,
1922
awsCfg.WithCredentialsProvider(credentials.StaticCredentialsProvider{
2023
Value: aws.Credentials{
2124
AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey,
2225
Source: "Reka Variables",
2326
},
2427
}), awsCfg.WithRegion(defaultRegion))
2528
} else {
26-
cfg, err = awsCfg.LoadDefaultConfig(awsCfg.WithRegion(defaultRegion))
29+
cfg, err = awsCfg.LoadDefaultConfig(ctx, awsCfg.WithRegion(defaultRegion))
2730
}
2831

2932
if err != nil {

config/config.example.yaml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@ name: reka
99
# Providers to be enabled for reka
1010
providers:
1111
- aws
12-
# logPath: logs/
13-
refreshInterval: 1
14-
# auth:
15-
# username: blank # Can
16-
# password: blank
17-
database:
18-
type: sqlite
12+
# logPath: /path/to/logs/dir/
1913

20-
aws:
21-
# Env: AWS_SECRET_ACCESS_KEY
22-
secretAccessKey: blank
23-
# ENV: AWS_ACCESS_KEY_ID
24-
accessKeyID: blank
25-
# ENV: AWS_REGION
26-
defaultRegion: us-east-2
14+
# Time to refresh resources in hours
15+
refreshInterval: 4
16+
17+
# web
18+
# auth:
19+
# username: blank # Can
20+
# password: blank
21+
22+
# If not set defaults to $(pwd)/reka-state.json
23+
StateBackend:
24+
type: local
25+
path: /path/to/local/store/state
26+
27+
# aws:
28+
# # Env: AWS_SECRET_ACCESS_KEY
29+
# secretAccessKey: blank
30+
# # ENV: AWS_ACCESS_KEY_ID
31+
# accessKeyID: blank
32+
# # ENV: AWS_REGION
33+
# defaultRegion: us-east-2
2734

2835
exclude:
2936
- name: Exclude resources with prod tags in us-east-2
@@ -52,7 +59,8 @@ rules:
5259
env: test
5360
ci: true
5461
condition:
55-
terminationPolicy: older than 24hrs
62+
terminationPolicy:
63+
- older than 24hrs
5664
- name: Nuke all project A instances after Demo october 9th (staging)
5765
tags:
5866
env: staging
@@ -66,7 +74,6 @@ rules:
6674
condition:
6775
terminationPolicy:
6876
- unused
69-
- older than 48hrs
7077
action: terminate
7178

7279

config/config.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,34 @@ type Config struct {
3131

3232
Database *DatabaseConfig
3333

34-
// Authentication Details to login to Reka
35-
Auth struct {
36-
Username string
37-
Password string
34+
Web struct {
35+
// Authentication Details to login to Reka
36+
Auth struct {
37+
Username string
38+
Password string
39+
}
3840
}
3941

4042
staticPath string // Path to Static File
41-
Exclude []struct {
43+
44+
// Exclude block prevents certain resources from been tracked or affected by reka.
45+
Exclude []struct {
4246
Name string
4347
Region string
4448
Tags map[string]string
4549
Resources []string
4650
}
4751

52+
// StateBackend is how state is stored (read & write)
53+
// State files contain details used for infrastructure resumption and history of
54+
// infrastructural management
55+
StateBackend struct {
56+
Type string
57+
Path string
58+
}
59+
60+
// Rules block define how reka should behave given certain resources. These rules
61+
// usually target resources based on tags/labels which are attached to the resources
4862
Rules []struct {
4963
Name string
5064
Condition struct {
@@ -77,6 +91,8 @@ func LoadConfig() *Config {
7791
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
7892
// Defaults
7993
viper.SetDefault("StaticPath", "web/static")
94+
viper.SetDefault("StateBackend.Type", "local")
95+
viper.SetDefault("StateBackend.Path", path.Join(workingDir, "reka-state.json"))
8096
// viper.SetDefault("DbType", "sqlite") // Default Database type is sqlite
8197
viper.SetDefault("LogPath", path.Join(workingDir, "logs"))
8298
viper.SetDefault("RefreshInterval", 4) // interval between running refresh and checking for resources to updates

go.mod

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@ module github.com/mensaah/reka
33
go 1.14
44

55
require (
6-
github.com/aws/aws-sdk-go-v2 v0.29.0
7-
github.com/aws/aws-sdk-go-v2/config v0.2.2
8-
github.com/aws/aws-sdk-go-v2/credentials v0.1.4
9-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v0.1.2
10-
github.com/aws/aws-sdk-go-v2/service/ec2 v0.29.0
11-
github.com/aws/aws-sdk-go-v2/service/s3 v0.29.0
6+
github.com/alvaroloes/enumer v1.1.2 // indirect
7+
github.com/aws/aws-sdk-go-v2 v0.31.0
8+
github.com/aws/aws-sdk-go-v2/config v0.4.0
9+
github.com/aws/aws-sdk-go-v2/credentials v0.2.0
10+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v0.2.0
11+
github.com/aws/aws-sdk-go-v2/service/ec2 v0.31.0
12+
github.com/aws/aws-sdk-go-v2/service/eks v0.31.0
13+
github.com/aws/aws-sdk-go-v2/service/s3 v0.31.0
1214
github.com/gin-gonic/gin v1.6.3
13-
github.com/go-co-op/gocron v0.3.2
15+
github.com/go-co-op/gocron v0.5.0
1416
github.com/jinzhu/now v1.1.1
1517
github.com/labstack/gommon v0.3.0
1618
github.com/mitchellh/go-homedir v1.1.0
19+
github.com/rs/zerolog v1.15.0
1720
github.com/sirupsen/logrus v1.7.0
1821
github.com/spf13/cobra v1.1.1
19-
github.com/spf13/pflag v1.0.5
2022
github.com/spf13/viper v1.7.1
21-
gorm.io/driver/postgres v1.0.5
22-
gorm.io/driver/sqlite v1.1.3
23-
gorm.io/gorm v1.20.5
23+
google.golang.org/appengine v1.6.1
24+
gorm.io/driver/postgres v1.0.6
25+
gorm.io/driver/sqlite v1.1.4
26+
gorm.io/gorm v1.20.9
2427
)

0 commit comments

Comments
 (0)