Skip to content

Commit

Permalink
merged with main
Browse files Browse the repository at this point in the history
  • Loading branch information
sol-dev-abhi committed Aug 8, 2023
2 parents 7491919 + 96f31f1 commit 4861a48
Show file tree
Hide file tree
Showing 93 changed files with 4,736 additions and 4,249 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/helm_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
git config user.email "$GITHUB_ACTOR@@gmail.com"
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.1.0
uses: helm/chart-releaser-action@v1.5.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_SKIP_EXISTING: true
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<p align="center"><img src="kad-logo1.png" width="300"></p>
<p align="center"><b>Extensible open-source framework that Integrates & Scales your DevSecOps and MLOps stacks as you need</b></p>

# Kad
Universal **Integrator** - Framework to easily integrate with other tools/platforms to use their APIs, gRPC, DB, Workflows, etc. and also to develop workflows around them. This framework development is based on Temporal and NATS.
> name -Kad is Haitian Creole word, translates to framework.
# Kad

Universal **Integrator** - Framework to easily integrate with other tools/platforms to use their APIs, gRPC, DB, Workflows, etc. and also to develop workflows around them. This framework development is based on Temporal and NATS.

> name -Kad is Haitian Creole word, translates to framework.
12 changes: 12 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Security Policy

## Supported Versions

| Version | Supported |
| ------- | ------------------ |
| 1.x.x | :white_check_mark: |


## Reporting a Vulnerability

Please report security issues using our [Security Form](https://intelops.ai/opensource-security-reporting-form/)
26 changes: 20 additions & 6 deletions capten/agent/cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
"github.com/intelops/go-common/logging"
"github.com/kube-tarian/kad/capten/agent/pkg/agent"
"github.com/kube-tarian/kad/capten/agent/pkg/agentpb"
captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store"
"github.com/kube-tarian/kad/capten/agent/pkg/config"
"github.com/kube-tarian/kad/capten/agent/pkg/util"
dbinit "github.com/kube-tarian/kad/capten/common-pkg/cassandra/db-init"
dbmigrate "github.com/kube-tarian/kad/capten/common-pkg/cassandra/db-migrate"
"github.com/pkg/errors"
"google.golang.org/grpc/reflection"
)

Expand All @@ -27,11 +30,11 @@ func main() {
log.Fatalf("service config reading failed, %v", err)
}

if err := runAllMigrations(log); err != nil {
log.Fatalf("Error while running migrations: %v", err)
if err := configureDB(); err != nil {
log.Fatalf("%v", err)
}

s, err := agent.NewAgent(log)
s, err := agent.NewAgent(log, cfg)
if err != nil {
log.Fatalf("Agent initialization failed, %v", err)
}
Expand Down Expand Up @@ -60,6 +63,17 @@ func main() {
log.Debugf("Exiting Agent")
}

func runAllMigrations(log logging.Logger) error {
return captenstore.Migrate(log)
func configureDB() error {
if err := util.SyncCassandraAdminSecret(log); err != nil {
return errors.WithMessage(err, "error in update cassandra secret to vault")
}

if err := dbinit.CreatedDatabase(log); err != nil {
return errors.WithMessage(err, "error creating database")
}

if err := dbmigrate.RunMigrations(log, dbmigrate.UP); err != nil {
return errors.WithMessage(err, "error in migrating cassandra DB")
}
return nil
}
16 changes: 11 additions & 5 deletions capten/agent/pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package agent
import (
"context"
"fmt"
"os"

"github.com/intelops/go-common/logging"
"github.com/kube-tarian/kad/capten/agent/pkg/agentpb"
captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store"
"github.com/kube-tarian/kad/capten/agent/pkg/config"
"github.com/kube-tarian/kad/capten/agent/pkg/temporalclient"
"github.com/kube-tarian/kad/capten/agent/pkg/workers"

Expand All @@ -23,21 +23,22 @@ type Agent struct {
log logging.Logger
}

func NewAgent(log logging.Logger) (*Agent, error) {
func NewAgent(log logging.Logger, cfg *config.SericeConfig) (*Agent, error) {
var tc *temporalclient.Client
var err error

if os.Getenv("ENV") != "LOCAL" {
if cfg.Mode == "local" {
tc, err = temporalclient.NewClient(log)
if err != nil {
return nil, err
}
}
// Note how lack of dependecy injection leads to codesmell

as, err := captenstore.NewStore(log)
if err != nil {
return nil, err
// ignoring store failure until DB user creation working
// return nil, err
log.Errorf("failed to initialize store, %v", err)
}

agent := &Agent{
Expand All @@ -48,6 +49,11 @@ func NewAgent(log logging.Logger) (*Agent, error) {
return agent, nil
}

func (a *Agent) Ping(ctx context.Context, request *agentpb.PingRequest) (*agentpb.PingResponse, error) {
a.log.Infof("Ping request received")
return &agentpb.PingResponse{Status: agentpb.StatusCode_OK}, nil
}

func (a *Agent) SubmitJob(ctx context.Context, request *agentpb.JobRequest) (*agentpb.JobResponse, error) {
a.log.Infof("Recieved event %+v", request)
worker, err := a.getWorker(request.Operation)
Expand Down
99 changes: 55 additions & 44 deletions capten/agent/pkg/agent/agent_cluster_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,41 @@ package agent

import (
"context"
"fmt"

"github.com/kube-tarian/kad/capten/agent/pkg/agentpb"
)

func (a *Agent) SyncApp(ctx context.Context, request *agentpb.SyncAppRequest) (*agentpb.SyncAppResponse, error) {
if request == nil {
return nil, fmt.Errorf("nil agentpb.SyncAppRequest")
func (a *Agent) SyncApp(ctx context.Context, request *agentpb.SyncAppRequest) (
*agentpb.SyncAppResponse, error) {
if request.Data == nil {
return &agentpb.SyncAppResponse{
Status: agentpb.StatusCode_INVALID_ARGUMENT,
StatusMessage: "invalid data passed",
}, nil
}
if err := a.as.UpsertAppConfig(request.GetData()); err != nil {
return nil, err

if err := a.as.UpsertAppConfig(request.Data); err != nil {
a.log.Errorf("failed to update sync app config, %v", err)
return &agentpb.SyncAppResponse{
Status: agentpb.StatusCode_INTERNRAL_ERROR,
StatusMessage: "failed to sync app config",
}, nil
}

a.log.Infof("Sync app [%s] successful", request.Data.Config.ReleaseName)
return &agentpb.SyncAppResponse{
Status: agentpb.StatusCode_OK,
StatusMessage: agentpb.StatusCode_name[int32(agentpb.StatusCode_OK)],
StatusMessage: "successful",
}, nil
}

func (a *Agent) GetClusterApps(ctx context.Context, request *agentpb.GetClusterAppsRequest) (*agentpb.GetClusterAppsResponse, error) {
if request == nil {
return nil, fmt.Errorf("nil agentpb.GetClusterAppsRequest")
}
func (a *Agent) GetClusterApps(ctx context.Context, request *agentpb.GetClusterAppsRequest) (
*agentpb.GetClusterAppsResponse, error) {
res, err := a.as.GetAllApps()
if err != nil {
return nil, err
}

if len(res) == 0 {
return &agentpb.GetClusterAppsResponse{
Status: agentpb.StatusCode_NOT_FOUND,
StatusMessage: agentpb.StatusCode_name[int32(agentpb.StatusCode_NOT_FOUND)],
Status: agentpb.StatusCode_INTERNRAL_ERROR,
StatusMessage: "failed to fetch cluster app configs",
}, nil
}

Expand All @@ -44,63 +47,68 @@ func (a *Agent) GetClusterApps(ctx context.Context, request *agentpb.GetClusterA
})
}

a.log.Infof("Found %d apps", len(appData))
return &agentpb.GetClusterAppsResponse{
Status: agentpb.StatusCode_OK,
StatusMessage: agentpb.StatusCode_name[int32(agentpb.StatusCode_OK)],
StatusMessage: "successful",
AppData: appData,
}, nil

}

func (a *Agent) GetClusterAppLaunches(ctx context.Context, request *agentpb.GetClusterAppLaunchesRequest) (*agentpb.GetClusterAppLaunchesResponse, error) {

res, err := a.GetClusterApps(context.TODO(), &agentpb.GetClusterAppsRequest{})
func (a *Agent) GetClusterAppLaunches(ctx context.Context, request *agentpb.GetClusterAppLaunchesRequest) (
*agentpb.GetClusterAppLaunchesResponse, error) {
res, err := a.as.GetAllApps()
if err != nil {
return nil, err
}

if len(res.GetAppData()) == 0 {
return &agentpb.GetClusterAppLaunchesResponse{
Status: agentpb.StatusCode_NOT_FOUND,
StatusMessage: agentpb.StatusCode_name[int32(agentpb.StatusCode_NOT_FOUND)],
Status: agentpb.StatusCode_INTERNRAL_ERROR,
StatusMessage: "failed to fetch cluster app configs",
}, nil
}

cfgs := make([]*agentpb.AppLaunchConfig, 0)
for _, r := range res.GetAppData() {
cfg := &agentpb.AppLaunchConfig{
for _, r := range res {
appConfig := r.GetConfig()
if len(appConfig.LaunchURL) == 0 {
continue
}

cfgs = append(cfgs, &agentpb.AppLaunchConfig{
ReleaseName: r.GetConfig().GetReleaseName(),
Category: r.GetConfig().GetCategory(),
Description: r.GetConfig().GetDescription(),
Icon: r.GetConfig().GetIcon(),
LaunchURL: r.GetConfig().GetLaunchURL(),
LaunchRedirectURL: r.GetConfig().GetLaunchRedirectURL(),
}
cfgs = append(cfgs, cfg)
})
}

a.log.Infof("Found %d apps with launch configs", len(cfgs))
return &agentpb.GetClusterAppLaunchesResponse{
LaunchConfigList: cfgs,
Status: agentpb.StatusCode_OK,
StatusMessage: agentpb.StatusCode_name[int32(agentpb.StatusCode_OK)],
StatusMessage: "successful",
}, nil
}

func (a *Agent) GetClusterAppConfig(ctx context.Context, request *agentpb.GetClusterAppConfigRequest) (*agentpb.GetClusterAppConfigResponse, error) {

res, err := a.as.GetAppConfig("release_name", request.GetReleaseName())

func (a *Agent) GetClusterAppConfig(ctx context.Context, request *agentpb.GetClusterAppConfigRequest) (
*agentpb.GetClusterAppConfigResponse, error) {
res, err := a.as.GetAppConfig(request.ReleaseName)
if err != nil && err.Error() == "not found" {
return &agentpb.GetClusterAppConfigResponse{
Status: agentpb.StatusCode_NOT_FOUND,
StatusMessage: agentpb.StatusCode_name[int32(agentpb.StatusCode_NOT_FOUND)],
StatusMessage: "app not found",
}, nil
}

if err != nil {
return nil, err
return &agentpb.GetClusterAppConfigResponse{
Status: agentpb.StatusCode_INTERNRAL_ERROR,
StatusMessage: "failed to fetch app config",
}, nil
}

a.log.Infof("Fetched app config for app [%s]", request.ReleaseName)
return &agentpb.GetClusterAppConfigResponse{
AppConfig: res.GetConfig(),
Status: agentpb.StatusCode_OK,
Expand All @@ -109,21 +117,24 @@ func (a *Agent) GetClusterAppConfig(ctx context.Context, request *agentpb.GetClu

}

func (a *Agent) GetClusterAppValues(ctx context.Context, request *agentpb.GetClusterAppValuesRequest) (*agentpb.GetClusterAppValuesResponse, error) {

res, err := a.as.GetAppConfig("release_name", request.GetReleaseName())

func (a *Agent) GetClusterAppValues(ctx context.Context, request *agentpb.GetClusterAppValuesRequest) (
*agentpb.GetClusterAppValuesResponse, error) {
res, err := a.as.GetAppConfig(request.ReleaseName)
if err != nil && err.Error() == "not found" {
return &agentpb.GetClusterAppValuesResponse{
Status: agentpb.StatusCode_NOT_FOUND,
StatusMessage: agentpb.StatusCode_name[int32(agentpb.StatusCode_NOT_FOUND)],
StatusMessage: "app not found",
}, nil
}

if err != nil {
return nil, err
return &agentpb.GetClusterAppValuesResponse{
Status: agentpb.StatusCode_INTERNRAL_ERROR,
StatusMessage: "failed to fetch app config",
}, nil
}

a.log.Infof("Fetched app values for app [%s]", request.ReleaseName)
return &agentpb.GetClusterAppValuesResponse{
Values: res.GetValues(),
Status: agentpb.StatusCode_OK,
Expand Down
14 changes: 7 additions & 7 deletions capten/agent/pkg/agent/agent_cluster_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/kube-tarian/kad/capten/agent/pkg/agentpb"
captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store"
"github.com/kube-tarian/kad/capten/agent/pkg/config"
"github.com/kube-tarian/kad/integrator/common-pkg/logging"
"github.com/stretchr/testify/suite"
"gopkg.in/yaml.v2"
Expand All @@ -23,11 +23,11 @@ func TestAgentTestSuite(t *testing.T) {
agentSuite := new(AgentTestSuite)
agentSuite.logger = logging.NewLogger()

if err := captenstore.Migrate(agentSuite.logger); err != nil {
/*if err := captenstore.Migrate(agentSuite.logger); err != nil {
t.Fatal(err)
}
}*/

agent, err := NewAgent(agentSuite.logger)
agent, err := NewAgent(agentSuite.logger, &config.SericeConfig{})
if err != nil {
t.Fatal(err)
}
Expand All @@ -40,9 +40,9 @@ func (suite *AgentTestSuite) SetupSuite() {
}

func (suite *AgentTestSuite) TearDownSuite() {
if err := captenstore.MigratePurge(suite.logger); err != nil {
/*if err := captenstore.MigratePurge(suite.logger); err != nil {
suite.logger.Error(err.Error())
}
}*/
}

func (suite *AgentTestSuite) Test_1_SyncApp() {
Expand Down Expand Up @@ -141,7 +141,7 @@ func setEnvVars() {

os.Setenv("DB_ADDRESSES", "localhost:9042")
os.Setenv("DB_ENTITY_NAME", "TEST_ENTITY")
os.Setenv("CASSANDRA_DB_NAME", "apps")
os.Setenv("DB_NAME", "apps")
os.Setenv("DB_NAME", "apps")
os.Setenv("DB_SERVICE_USERNAME", "apps_user")
os.Setenv("DB_SERVICE_PASSWD", "apps_password")
Expand Down
Loading

0 comments on commit 4861a48

Please sign in to comment.