Skip to content

Commit

Permalink
Merge pull request #164 from kube-tarian/feature/store_app_deploy
Browse files Browse the repository at this point in the history
deploy store app
  • Loading branch information
vramk23 authored Aug 19, 2023
2 parents 7c1bef5 + 96ac3ac commit 51af238
Show file tree
Hide file tree
Showing 25 changed files with 1,583 additions and 501 deletions.
30 changes: 30 additions & 0 deletions capten/agent/pkg/agent/agent_climon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

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

Expand Down Expand Up @@ -36,3 +37,32 @@ func (a *Agent) ClimonAppDelete(ctx context.Context, request *agentpb.ClimonDele

return prepareJobResponse(run, worker.GetWorkflowName()), err
}

func (a *Agent) InstallApp(ctx context.Context, request *agentpb.InstallAppRequest) (*agentpb.JobResponse, error) {
a.log.Infof("Recieved App Install event %+v", request)
worker := workers.NewClimon(a.tc, a.log)

config := &model.AppConfig{
ReleaseName: request.AppConfig.ReleaseName,
AppName: request.AppConfig.AppName,
Version: request.AppConfig.Version,
Category: request.AppConfig.Category,
Description: request.AppConfig.Description,
ChartName: request.AppConfig.ChartName,
RepoName: request.AppConfig.RepoName,
RepoURL: request.AppConfig.RepoURL,
Namespace: request.AppConfig.Namespace,
CreateNamespace: request.AppConfig.CreateNamespace,
PrivilegedNamespace: request.AppConfig.PrivilegedNamespace,
Icon: string(request.AppConfig.Icon),
LaunchURL: request.AppConfig.LaunchURL,
// LaunchRedirectURL: request.AppConfig.LaunchRedirectURL,
ClusterName: "inbuilt",
}
run, err := worker.SendInstallAppEvent(ctx, "install", config)
if err != nil {
return &agentpb.JobResponse{}, err
}

return prepareJobResponse(run, worker.GetWorkflowName()), err
}
397 changes: 234 additions & 163 deletions capten/agent/pkg/agentpb/agent.pb.go

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion capten/agent/pkg/agentpb/agent_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions capten/agent/pkg/model/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,21 @@ type Request struct {
Timeout int `json:"timeout" required:"true"`
Version string `json:"version" required:"true"`
}

type AppConfig struct {
ClusterName string `json:"ClusterName,omitempty"`
AppName string `json:"AppName,omitempty"`
Version string `json:"Version,omitempty"`
Category string `json:"Category,omitempty"`
Description string `json:"Description,omitempty"`
ChartName string `json:"ChartName,omitempty"`
RepoName string `json:"RepoName,omitempty"`
ReleaseName string `json:"ReleaseName,omitempty"`
RepoURL string `json:"RepoURL,omitempty"`
Namespace string `json:"Namespace,omitempty"`
CreateNamespace bool `json:"CreateNamespace"`
PrivilegedNamespace bool `json:"PrivilegedNamespace"`
Icon string `json:"Icon,omitempty"`
LaunchURL string `json:"LaunchURL,omitempty"`
LaunchRedirectURL string `json:"LaunchRedirectURL,omitempty"`
}
32 changes: 32 additions & 0 deletions capten/agent/pkg/workers/climon.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,35 @@ func (c *Climon) getWorkflowInformation(run client.WorkflowRun) error {
c.log.Debugf("Result info: %+v", result)
return nil
}

func (c *Climon) SendInstallAppEvent(ctx context.Context, action string, payload *model.AppConfig) (client.WorkflowRun, error) {
options := client.StartWorkflowOptions{
ID: "helm-deploy-workflow",
TaskQueue: ClimonHelmTaskQueue,
}

payloadJSON, err := json.Marshal(payload)
if err != nil {
return nil, err
}

we, err := c.client.TemporalClient.ExecuteWorkflow(context.Background(), options, DeployWorkflowName, action, json.RawMessage(payloadJSON))
if err != nil {
log.Println("error starting workflow", err)
return nil, err
}

c.log.Infof("Started workflow, ID: %v, WorkflowName: %v RunID: %v", we.GetID(), DeploymentWorkerWorkflowName, we.GetRunID())

// Wait for 5mins till workflow finishes
var result model.ResponsePayload
err = we.Get(ctx, &result)
if err != nil {
c.log.Errorf("Result for workflow ID: %v, workflowName: %v, runID: %v", we.GetID(), DeploymentWorkerWorkflowName, we.GetRunID())
c.log.Errorf("Workflow result failed, %v", err)
return we, err
}
c.log.Infof("workflow finished success, %+v", result.ToString())

return we, nil
}
1 change: 1 addition & 0 deletions dockerfiles/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN CGO_ENABLED=0 go build -o ./build/server cmd/server/main.go

FROM alpine:3.16
RUN apk add --no-cache libc6-compat
COPY --from=builder ./storeconfig storeconfig
COPY --from=builder ./build/server server

USER 65532:65532
Expand Down
9 changes: 8 additions & 1 deletion proto/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ service Agent {

rpc GetClusterAppConfig (GetClusterAppConfigRequest) returns (GetClusterAppConfigResponse) {}
rpc GetClusterAppValues (GetClusterAppValuesRequest) returns (GetClusterAppValuesResponse) {}

rpc InstallApp (InstallAppRequest) returns (JobResponse) {}

}

enum StatusCode {
Expand Down Expand Up @@ -245,5 +248,9 @@ message AppLaunchConfig {
string description = 3;
bytes icon = 4;
string launchURL = 5;
string launchUIDescription = 6;
string launchRedirectURL = 6;
}

message InstallAppRequest{
AppConfig appConfig =1;
}
24 changes: 24 additions & 0 deletions proto/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ service Server {
rpc DeleteStoreApp (DeleteStoreAppRequest) returns (DeleteStoreAppResponse){}
rpc GetStoreApp (GetStoreAppRequest) returns (GetStoreAppResponse) {}
rpc GetStoreApps (GetStoreAppsRequest) returns (GetStoreAppsResponse) {}
rpc GetStoreAppValues(GetStoreAppValuesRequest) returns (GetStoreAppValuesResponse) {}
rpc DeployStoreApp(DeployStoreAppRequest) returns (DeployStoreAppResponse) {}

}

enum StatusCode {
Expand Down Expand Up @@ -209,6 +212,26 @@ message GetStoreAppsResponse {
repeated StoreAppConfig appConfigs = 3;
}

message GetStoreAppValuesRequest {
string appName = 1;
string version = 2;
}

message GetStoreAppValuesResponse{
StatusCode status = 1;
string statusMessage = 2;
StoreAppConfig appConfig = 3;
}

message DeployStoreAppRequest{
StoreAppConfig appConfig = 1;
}

message DeployStoreAppResponse{
StatusCode status = 1;
string statusMessage = 2;
}

message StoreAppConfig {
string releaseName = 1;
string appName = 2;
Expand All @@ -230,3 +253,4 @@ message StoreAppValues {
string overrideValues = 1;
string launchUIValues = 2;
}

Binary file added server/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions server/pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

const (
organizationIDAttribute = "organizationid"
clusterIDAttribute = "clusterid"
)

type Server struct {
Expand Down
Loading

0 comments on commit 51af238

Please sign in to comment.