Skip to content

Commit

Permalink
Merge pull request #207 from kube-tarian/feature/app_deployment
Browse files Browse the repository at this point in the history
store app deployment
  • Loading branch information
vramk23 authored Aug 27, 2023
2 parents 4cbd38f + d60681c commit cb677a9
Show file tree
Hide file tree
Showing 7 changed files with 927 additions and 814 deletions.
7 changes: 4 additions & 3 deletions capten/agent/pkg/agent/agent_app_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"context"
"encoding/base64"

"github.com/kube-tarian/kad/capten/agent/pkg/agentpb"
"github.com/kube-tarian/kad/capten/agent/pkg/workers"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (a *Agent) InstallApp(ctx context.Context, request *agentpb.InstallAppReque
ReleaseName: request.AppConfig.ReleaseName,
Version: request.AppConfig.Version,
ClusterName: "capten",
ValuesYaml: string(request.OverrideValues),
ValuesYaml: base64.StdEncoding.EncodeToString(request.AppValues.OverrideValues),
Timeout: 5,
}

Expand Down Expand Up @@ -83,8 +84,8 @@ func (a *Agent) InstallApp(ctx context.Context, request *agentpb.InstallAppReque
DefualtApp: request.AppConfig.DefualtApp,
},
Values: &agentpb.AppValues{
OverrideValues: request.OverrideValues,
LaunchUIValues: request.LaunchUIValues,
OverrideValues: request.AppValues.OverrideValues,
LaunchUIValues: request.AppValues.LaunchUIValues,
},
}

Expand Down
495 changes: 243 additions & 252 deletions capten/agent/pkg/agentpb/agent.pb.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions proto/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ message GetClusterAppValuesResponse {

message InstallAppRequest {
AppConfig appConfig =1;
bytes overrideValues = 2;
bytes launchUIValues = 3;
AppValues appValues = 2;
}

message InstallAppResponse {
Expand Down
18 changes: 12 additions & 6 deletions proto/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ message GetStoreAppResponse {
StatusCode status = 1;
string statusMessage = 2;
StoreAppConfig appConfig = 3;
StoreAppValues appValues = 4;
}

message GetStoreAppsRequest {
Expand All @@ -208,7 +209,12 @@ message GetStoreAppsRequest {
message GetStoreAppsResponse {
StatusCode status = 1;
string statusMessage = 2;
repeated StoreAppConfig appConfigs = 3;
repeated StoreAppsData data = 3;
}

message StoreAppsData {
StoreAppConfig appConfigs = 1;
StoreAppValues appValues = 2;
}

message GetStoreAppValuesRequest {
Expand All @@ -220,12 +226,12 @@ message GetStoreAppValuesResponse {
StatusCode status = 1;
string statusMessage = 2;
StoreAppConfig appConfig = 3;
StoreAppValues appValues = 4;
}

message DeployStoreAppRequest {
StoreAppConfig appConfig = 1;
bytes overrideValues = 2;
bytes launchUIValues = 3;
StoreAppValues appValues = 2;
}

message DeployStoreAppResponse{
Expand All @@ -245,14 +251,14 @@ message StoreAppConfig {
string namespace = 9;
bool createNamespace = 10;
bool privilegedNamespace = 11;
string icon = 12;
bytes icon = 12;
string launchURL = 13;
string launchUIDescription = 14;
bool defualtApp = 15;
}

message StoreAppValues {
string overrideValues = 1;
string launchUIValues = 2;
bytes overrideValues = 1;
bytes launchUIValues = 2;
}

87 changes: 59 additions & 28 deletions server/pkg/api/store_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package api

import (
"context"
"encoding/base64"
"encoding/hex"

"github.com/kube-tarian/kad/server/pkg/pb/agentpb"
"github.com/kube-tarian/kad/server/pkg/pb/serverpb"
Expand Down Expand Up @@ -31,11 +33,11 @@ func (s *Server) AddStoreApp(ctx context.Context, request *serverpb.AddStoreAppR
Namespace: request.AppConfig.Namespace,
CreateNamespace: request.AppConfig.CreateNamespace,
PrivilegedNamespace: request.AppConfig.PrivilegedNamespace,
Icon: request.AppConfig.Icon,
Icon: hex.EncodeToString(request.AppConfig.Icon),
LaunchURL: request.AppConfig.LaunchURL,
LaunchUIDescription: request.AppConfig.LaunchUIDescription,
OverrideValues: request.AppValues.OverrideValues,
LaunchUIValues: request.AppValues.LaunchUIValues,
OverrideValues: base64.StdEncoding.EncodeToString(request.AppValues.OverrideValues),
LaunchUIValues: base64.StdEncoding.EncodeToString(request.AppValues.LaunchUIValues),
}

if err := s.serverStore.AddOrUpdateApp(config); err != nil {
Expand Down Expand Up @@ -74,11 +76,11 @@ func (s *Server) UpdateStoreApp(ctx context.Context, request *serverpb.UpdateSto
Namespace: request.AppConfig.Namespace,
CreateNamespace: request.AppConfig.CreateNamespace,
PrivilegedNamespace: request.AppConfig.PrivilegedNamespace,
Icon: request.AppConfig.Icon,
Icon: hex.EncodeToString(request.AppConfig.Icon),
LaunchURL: request.AppConfig.LaunchURL,
LaunchUIDescription: request.AppConfig.LaunchUIDescription,
OverrideValues: request.AppValues.OverrideValues,
LaunchUIValues: request.AppValues.LaunchUIValues,
OverrideValues: base64.StdEncoding.EncodeToString(request.AppValues.OverrideValues),
LaunchUIValues: base64.StdEncoding.EncodeToString(request.AppValues.LaunchUIValues),
}

if err := s.serverStore.AddOrUpdateApp(config); err != nil {
Expand Down Expand Up @@ -138,6 +140,7 @@ func (s *Server) GetStoreApp(ctx context.Context, request *serverpb.GetStoreAppR
}, nil
}

decodedIconBytes, _ := hex.DecodeString(config.Icon)
appConfig := &serverpb.StoreAppConfig{
AppName: config.Name,
Version: config.Version,
Expand All @@ -149,16 +152,24 @@ func (s *Server) GetStoreApp(ctx context.Context, request *serverpb.GetStoreAppR
Namespace: config.Namespace,
CreateNamespace: config.CreateNamespace,
PrivilegedNamespace: config.PrivilegedNamespace,
Icon: config.Icon,
Icon: decodedIconBytes,
LaunchURL: config.LaunchUIURL,
LaunchUIDescription: config.LaunchUIDescription,
ReleaseName: config.ReleaseName,
}

decodedOverrideValuesBytes, _ := base64.StdEncoding.DecodeString(config.OverrideValues)
decodedLaunchUiValuesBytes, _ := base64.StdEncoding.DecodeString(config.LaunchUIValues)
appValues := &serverpb.StoreAppValues{
OverrideValues: decodedOverrideValuesBytes,
LaunchUIValues: decodedLaunchUiValuesBytes,
}

return &serverpb.GetStoreAppResponse{
Status: serverpb.StatusCode_OK,
StatusMessage: "app config is sucessfuly fetched from store",
AppConfig: appConfig,
AppValues: appValues,
}, nil

}
Expand All @@ -175,30 +186,39 @@ func (s *Server) GetStoreApps(ctx context.Context, request *serverpb.GetStoreApp
}, nil
}

appConfigs := []*serverpb.StoreAppConfig{}
appsData := []*serverpb.StoreAppsData{}
for _, config := range *configs {
appConfigs = append(appConfigs, &serverpb.StoreAppConfig{
AppName: config.Name,
Version: config.Version,
Category: config.Category,
Description: config.Description,
ChartName: config.ChartName,
RepoName: config.RepoName,
RepoURL: config.RepoURL,
Namespace: config.Namespace,
CreateNamespace: config.CreateNamespace,
PrivilegedNamespace: config.PrivilegedNamespace,
Icon: config.Icon,
LaunchURL: config.LaunchUIURL,
LaunchUIDescription: config.LaunchUIDescription,
ReleaseName: config.ReleaseName,
decodedIconBytes, _ := hex.DecodeString(config.Icon)
decodedOverrideValuesBytes, _ := base64.StdEncoding.DecodeString(config.OverrideValues)
decodedLaunchUiValuesBytes, _ := base64.StdEncoding.DecodeString(config.LaunchUIValues)
appsData = append(appsData, &serverpb.StoreAppsData{
AppConfigs: &serverpb.StoreAppConfig{
AppName: config.Name,
Version: config.Version,
Category: config.Category,
Description: config.Description,
ChartName: config.ChartName,
RepoName: config.RepoName,
RepoURL: config.RepoURL,
Namespace: config.Namespace,
CreateNamespace: config.CreateNamespace,
PrivilegedNamespace: config.PrivilegedNamespace,
Icon: decodedIconBytes,
LaunchURL: config.LaunchUIURL,
LaunchUIDescription: config.LaunchUIDescription,
ReleaseName: config.ReleaseName,
},
AppValues: &serverpb.StoreAppValues{
OverrideValues: decodedOverrideValuesBytes,
LaunchUIValues: decodedLaunchUiValuesBytes,
},
})
}

return &serverpb.GetStoreAppsResponse{
Status: serverpb.StatusCode_OK,
StatusMessage: "app config's are sucessfuly fetched from store",
AppConfigs: appConfigs,
Data: appsData,
}, nil
}

Expand All @@ -220,6 +240,7 @@ func (s *Server) GetStoreAppValues(ctx context.Context, request *serverpb.GetSto
}, nil
}

decodedIconBytes, _ := hex.DecodeString(config.Icon)
appConfig := &serverpb.StoreAppConfig{
AppName: config.Name,
Version: config.Version,
Expand All @@ -231,16 +252,24 @@ func (s *Server) GetStoreAppValues(ctx context.Context, request *serverpb.GetSto
Namespace: config.Namespace,
CreateNamespace: config.CreateNamespace,
PrivilegedNamespace: config.PrivilegedNamespace,
Icon: config.Icon,
Icon: decodedIconBytes,
LaunchURL: config.LaunchUIURL,
LaunchUIDescription: config.LaunchUIDescription,
ReleaseName: config.ReleaseName,
}

decodedOverrideValuesBytes, _ := base64.StdEncoding.DecodeString(config.OverrideValues)
decodedLaunchUiValuesBytes, _ := base64.StdEncoding.DecodeString(config.LaunchUIValues)
appValues := &serverpb.StoreAppValues{
OverrideValues: decodedOverrideValuesBytes,
LaunchUIValues: decodedLaunchUiValuesBytes,
}

return &serverpb.GetStoreAppValuesResponse{
Status: serverpb.StatusCode_OK,
StatusMessage: "store app values sucessfuly fetched",
AppConfig: appConfig,
AppValues: appValues,
}, nil

}
Expand Down Expand Up @@ -296,13 +325,15 @@ func (s *Server) DeployStoreApp(ctx context.Context, request *serverpb.DeploySto
Namespace: request.AppConfig.Namespace,
CreateNamespace: request.AppConfig.CreateNamespace,
PrivilegedNamespace: request.AppConfig.PrivilegedNamespace,
Icon: []byte(request.AppConfig.Icon),
Icon: request.AppConfig.Icon,
LaunchURL: request.AppConfig.LaunchURL,
LaunchUIDescription: request.AppConfig.LaunchUIDescription,
DefualtApp: request.AppConfig.DefualtApp,
},
OverrideValues: request.OverrideValues,
LaunchUIValues: request.LaunchUIValues,
AppValues: &agentpb.AppValues{
OverrideValues: request.AppValues.OverrideValues,
LaunchUIValues: request.AppValues.LaunchUIValues,
},
}

_, err = agent.GetClient().InstallApp(ctx, req)
Expand Down
Loading

0 comments on commit cb677a9

Please sign in to comment.