Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cloud provider apis #261

Merged
merged 5 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions capten/agent/pkg/agent/plugin_cloud_provider_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ func (a *Agent) GetCloudProviders(ctx context.Context, request *captenpluginspb.

}

func (a *Agent) GetCloudProvidersForLabels(ctx context.Context, request *captenpluginspb.GetCloudProvidersForLabelsRequest) (
*captenpluginspb.GetCloudProvidersForLabelsResponse, error) {
func (a *Agent) GetCloudProvidersWithFilter(ctx context.Context, request *captenpluginspb.GetCloudProvidersWithFilterRequest) (
*captenpluginspb.GetCloudProvidersWithFilterResponse, error) {
if len(request.GetLabels()) == 0 {
a.log.Infof("request validation failed")
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_INVALID_ARGUMENT,
StatusMessage: "request validation failed",
}, nil
Expand All @@ -172,29 +172,38 @@ func (a *Agent) GetCloudProvidersForLabels(ctx context.Context, request *captenp
res, err := a.as.GetCloudProvidersByLabels(request.Labels)
if err != nil {
a.log.Errorf("failed to get CloudProviders for labels from db, %v", err)
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "failed to fetch cloud providers",
}, nil
}

filteredRes := make([]*captenpluginspb.CloudProvider, 0)
for _, r := range res {
if request.CloudType == "" {
filteredRes = append(filteredRes, r)
} else if request.CloudType != "" && r.CloudType == request.CloudType {
filteredRes = append(filteredRes, r)
}
}

abhi-intelops marked this conversation as resolved.
Show resolved Hide resolved
abhi-intelops marked this conversation as resolved.
Show resolved Hide resolved
for _, r := range filteredRes {
cloudAttributes, err := a.getCloudProviderCredential(ctx, r.Id)
if err != nil {
a.log.Errorf("failed to get credential, %v", err)
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "failed to fetch cloud providers",
}, nil
}
r.CloudAttributes = cloudAttributes
}

a.log.Infof("Found %d cloud providers for lables %v", len(res), request.Labels)
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
a.log.Infof("Found %d cloud providers for lables %v and cloud type %v", len(filteredRes), request.Labels, request.CloudType)
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_OK,
StatusMessage: "successful",
CloudProviders: res,
CloudProviders: filteredRes,
}, nil
}

Expand Down
10 changes: 6 additions & 4 deletions capten/agent/pkg/capten-store/cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const (

func (a *Store) UpsertCloudProvider(config *captenpluginspb.CloudProvider) error {
config.LastUpdateTime = time.Now().Format(time.RFC3339)
kvPairs, isEmptyUpdate := formUpdateKvPairsForCloudProvider(config)
kvPairs, _ := formUpdateKvPairsForCloudProvider(config)
batch := a.client.Session().NewBatch(gocql.LoggedBatch)
batch.Query(fmt.Sprintf(insertCloudProviderId, a.keyspace), config.Id)
if !isEmptyUpdate {
batch.Query(fmt.Sprintf(insertCloudProvider, a.keyspace), config.Id, config.CloudType, config.Labels, config.LastUpdateTime)
err := a.client.Session().ExecuteBatch(batch)
if err != nil {
batch.Query(fmt.Sprintf(updateCloudProviderById, a.keyspace, kvPairs), config.Id)
err = a.client.Session().ExecuteBatch(batch)
}
return a.client.Session().ExecuteBatch(batch)
return err
}

func (a *Store) DeleteCloudProviderById(id string) error {
Expand Down
6 changes: 4 additions & 2 deletions capten/agent/pkg/capten-store/git_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ func (a *Store) UpsertGitProject(config *captenpluginspb.GitProject) error {
config.LastUpdateTime = time.Now().Format(time.RFC3339)
kvPairs, isEmptyUpdate := formUpdateKvPairsForGitProject(config)
batch := a.client.Session().NewBatch(gocql.LoggedBatch)
batch.Query(fmt.Sprintf(insertGitProjectId, a.keyspace), config.Id)
batch.Query(fmt.Sprintf(insertGitProject, a.keyspace), config.Id, config.ProjectUrl, config.Labels, config.LastUpdateTime)
err := a.client.Session().ExecuteBatch(batch)
if !isEmptyUpdate {
abhi-intelops marked this conversation as resolved.
Show resolved Hide resolved
batch.Query(fmt.Sprintf(updateGitProjectById, a.keyspace, kvPairs), config.Id)
err = a.client.Session().ExecuteBatch(batch)
}
return a.client.Session().ExecuteBatch(batch)
return err
}

func (a *Store) DeleteGitProjectById(id string) error {
Expand Down
584 changes: 350 additions & 234 deletions capten/agent/pkg/pb/captenpluginspb/capten_plugins.pb.go

Large diffs are not rendered by default.

67 changes: 37 additions & 30 deletions capten/agent/pkg/pb/captenpluginspb/capten_plugins_grpc.pb.go

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

7 changes: 4 additions & 3 deletions proto/capten_plugins.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ service capten_plugins {
rpc UpdateCloudProvider(UpdateCloudProviderRequest) returns (UpdateCloudProviderResponse) {}
rpc DeleteCloudProvider(DeleteCloudProviderRequest) returns (DeleteCloudProviderResponse) {}
rpc GetCloudProviders(GetCloudProvidersRequest) returns (GetCloudProvidersResponse) {}
rpc GetCloudProvidersForLabels(GetCloudProvidersForLabelsRequest) returns (GetCloudProvidersForLabelsResponse) {}
rpc GetCloudProvidersWithFilter(GetCloudProvidersWithFilterRequest) returns (GetCloudProvidersWithFilterResponse) {}

rpc RegisterArgoCDProject(RegisterArgoCDProjectRequest) returns (RegisterArgoCDProjectResponse) {}
rpc GetArgoCDProjects(GetArgoCDProjectsRequest) returns (GetArgoCDProjectsResponse) {}
Expand Down Expand Up @@ -191,11 +191,12 @@ message GetCloudProvidersResponse {
string statusMessage = 3;
}

message GetCloudProvidersForLabelsRequest {
message GetCloudProvidersWithFilterRequest {
repeated string labels = 1;
string cloudType = 2;
}

message GetCloudProvidersForLabelsResponse {
message GetCloudProvidersWithFilterResponse {
repeated CloudProvider cloudProviders = 1;
StatusCode status = 2;
string statusMessage = 3;
Expand Down
16 changes: 8 additions & 8 deletions server/pkg/api/plugin_cloud_provider_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ func (s *Server) GetCloudProviders(ctx context.Context, request *captenpluginspb
}, nil
}

func (s *Server) GetCloudProvidersForLabels(ctx context.Context, request *captenpluginspb.GetCloudProvidersForLabelsRequest) (
*captenpluginspb.GetCloudProvidersForLabelsResponse, error) {
func (s *Server) GetCloudProvidersForLabels(ctx context.Context, request *captenpluginspb.GetCloudProvidersWithFilterRequest) (
*captenpluginspb.GetCloudProvidersWithFilterResponse, error) {
orgId, clusterId, err := validateOrgClusterWithArgs(ctx)
if err != nil {
s.log.Infof("request validation failed", err)
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_INVALID_ARGUMENT,
StatusMessage: "request validation failed",
}, nil
Expand All @@ -214,32 +214,32 @@ func (s *Server) GetCloudProvidersForLabels(ctx context.Context, request *capten
agent, err := s.agentHandeler.GetAgent(orgId, clusterId)
if err != nil {
s.log.Errorf("failed to initialize agent, %v", err)
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "failed to get the Cluster CloudProvider",
}, nil
}

response, err := agent.GetCaptenPluginsClient().GetCloudProvidersForLabels(context.Background(), request)
response, err := agent.GetCaptenPluginsClient().GetCloudProvidersWithFilter(context.Background(), request)
if err != nil {
s.log.Errorf("failed to get the Cluster CloudProvider with lables, %v", err)
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "failed to get the Cluster CloudProvider",
}, nil
}

if response.Status != captenpluginspb.StatusCode_OK {
s.log.Errorf("failed to get the ClusterProject with lables")
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "failed to get the Cluster CloudProvider",
}, nil
}

s.log.Infof("Fetched %d Cloud Providers request with lables %v for cluster %s recieved, [org: %s]",
request.Labels, len(response.GetCloudProviders()), clusterId, orgId)
return &captenpluginspb.GetCloudProvidersForLabelsResponse{
return &captenpluginspb.GetCloudProvidersWithFilterResponse{
CloudProviders: response.GetCloudProviders(),
Status: captenpluginspb.StatusCode_OK,
StatusMessage: "ok",
Expand Down
Loading
Loading