Refactorings for simplify readability (#35)

This commit is contained in:
Fedor Korotkov
2023-03-17 06:11:28 -04:00
committed by GitHub
parent 3ecf98c039
commit fb3056d3ae
21 changed files with 360 additions and 876 deletions
+3 -7
View File
@@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"github.com/cirruslabs/orchard/internal/config"
"github.com/cirruslabs/orchard/rpc"
"golang.org/x/net/websocket"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
@@ -18,11 +19,6 @@ import (
"net/url"
)
const MetadataServiceAccountNameKey = "x-orchard-service-account-name"
//nolint:gosec // G101 check yields a false-positive here, this is not a hard-coded credential
const MetadataServiceAccountTokenKey = "x-orchard-service-account-token"
var (
ErrFailed = errors.New("API client failed")
ErrInvalidState = errors.New("invalid state")
@@ -121,8 +117,8 @@ func (client *Client) GPRCMetadata() metadata.MD {
if client.serviceAccountName != "" && client.serviceAccountToken != "" {
result = map[string]string{
MetadataServiceAccountNameKey: client.serviceAccountName,
MetadataServiceAccountTokenKey: client.serviceAccountToken,
rpc.MetadataServiceAccountNameKey: client.serviceAccountName,
rpc.MetadataServiceAccountTokenKey: client.serviceAccountToken,
}
}
+2 -2
View File
@@ -23,7 +23,7 @@ func (service *VMsService) Create(ctx context.Context, vm *v1.VM) error {
return nil
}
func (service *VMsService) FindForWorker(ctx context.Context, workerName string) (map[string]v1.VM, error) {
func (service *VMsService) FindForWorker(ctx context.Context, workerUID string) (map[string]v1.VM, error) {
allVms, err := service.List(ctx)
if err != nil {
@@ -32,7 +32,7 @@ func (service *VMsService) FindForWorker(ctx context.Context, workerName string)
var filteredVms = make(map[string]v1.VM)
for _, vmResource := range allVms {
if vmResource.Worker != workerName {
if vmResource.WorkerUID != workerUID {
continue
}
filteredVms[vmResource.UID] = vmResource