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

166: Add ability to host Shared VMs to Gargantua #206

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b4a550f
Specify types for Shared VMs
PhilipAB Jul 19, 2024
0bf3aef
Change enum values to upper case
PhilipAB Jul 19, 2024
b042351
Add generic conversion functions for pb enums
PhilipAB Jul 19, 2024
fb219fe
Add vm type to vm service
PhilipAB Jul 19, 2024
6eff326
Update proto-gen-go version
PhilipAB Jul 19, 2024
bf50306
Add sharedVM field to list/get grpc endpoints
PhilipAB Jul 19, 2024
74775b9
Allow creation of shared vms in internal vm service
PhilipAB Jul 19, 2024
ef76dc0
Implement controller logic for shared services
PhilipAB Jul 19, 2024
fc98e66
Add "shared vm" field to internal create and update routes
PhilipAB Jul 19, 2024
04368fe
Add shared "shared_vms" field for create and update api routes
PhilipAB Jul 19, 2024
aa8d931
Improve controller logic for shared vms
PhilipAB Jul 19, 2024
62e8d9f
Merge branch 'master' into migrate-shared-services
PhilipAB Jul 19, 2024
4f9f1a9
Add shared vm endpoint
PhilipAB Jul 19, 2024
86c0e6d
Fix: Pass ac client to vm service
PhilipAB Jul 19, 2024
41b009e
Make Type of VM Explicit
jggoebel Sep 17, 2024
70a8450
Authnservice now also retreives the Shared Virtual Machines
jggoebel Sep 17, 2024
6b1d30d
Merge remote-tracking branch 'origin/master' into migrate-shared-serv…
jggoebel Sep 17, 2024
4849922
Verify shared virtual machines upon creation and whilest updating
jggoebel Sep 17, 2024
f690f34
Remove old logs
jggoebel Sep 17, 2024
246e547
Return VM Type instead of bool
jggoebel Sep 17, 2024
762e184
Correctly update vm ids for shared vms
PhilipAB Sep 17, 2024
dea7d30
Merge branch 'migrate-shared-services' of https://github.com/svalabs/…
PhilipAB Sep 17, 2024
59aee51
Add SharedVirtualMachine to PreparedScheduledEvent
jggoebel Sep 17, 2024
e1e088f
Merge branch 'migrate-shared-services' of github.com:svalabs/gargantu…
jggoebel Sep 17, 2024
bd7b644
Fix label selector
jggoebel Sep 17, 2024
eabd53e
Change label to retreive shared vms for user
jggoebel Sep 17, 2024
619b441
User should be able to access webinterfaces of shared VMs
jggoebel Sep 17, 2024
0ee299d
Add extra info to logs
jggoebel Sep 18, 2024
1101bf2
Remove Shared VMs when event is finished
jggoebel Sep 26, 2024
8fc768d
Merge remote-tracking branch 'origin/master' into migrate-shared-serv…
jggoebel Jan 16, 2025
a8a7de7
generate protos
jggoebel Jan 16, 2025
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
32 changes: 24 additions & 8 deletions v3/pkg/apis/hobbyfarm.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,24 @@ type VirtualMachineList struct {
}

type VirtualMachineSpec struct {
VirtualMachineTemplateId string `json:"vm_template_id"`
SshUsername string `json:"ssh_username"`
Protocol string `json:"protocol"`
SecretName string `json:"secret_name"` // this refers to the secret name for the keypair
VirtualMachineClaimId string `json:"vm_claim_id"`
UserId string `json:"user"`
Provision bool `json:"provision"`
VirtualMachineSetId string `json:"vm_set_id"`
VirtualMachineTemplateId string `json:"vm_template_id"`
SshUsername string `json:"ssh_username"`
Protocol string `json:"protocol"`
SecretName string `json:"secret_name"` // this refers to the secret name for the keypair
VirtualMachineClaimId string `json:"vm_claim_id"`
UserId string `json:"user"`
Provision bool `json:"provision"`
VirtualMachineSetId string `json:"vm_set_id"`
VirtualMachineType VirtualMachineType `json:"vm_type"`
}

type VirtualMachineType string

const (
VirtualMachineTypeUser VirtualMachineType = "USER"
VirtualMachineTypeShared VirtualMachineType = "SHARED"
)

type VirtualMachineStatus struct {
Status VmStatus `json:"status"` // default is nothing, but could be one of the following: readyforprovisioning, provisioning, running, terminating
Allocated bool `json:"allocated"`
Expand Down Expand Up @@ -488,6 +496,7 @@ type ScheduledEventSpec struct {
Printable bool `json:"printable"`
Scenarios []string `json:"scenarios"`
Courses []string `json:"courses"`
SharedVirtualMachines []SharedVirtualMachine `json:"shared_vms"`
}

type ScheduledEventStatus struct {
Expand All @@ -498,6 +507,13 @@ type ScheduledEventStatus struct {
Finished bool `json:"finished"`
}

type SharedVirtualMachine struct {
VMId string `json:"vmId"`
Name string `json:"name"`
Environment string `json:"environment"`
VMTemplate string `json:"vmTemplate"`
}

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
7 changes: 3 additions & 4 deletions v3/pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func (sp ShellProxy) proxy(w http.ResponseWriter, r *http.Request, user *userpb.
return
}

if vm.GetUser() != user.GetId() {
// TODO, if this is a shared VM we should check if the user has access to the Event this Shared VM belongs too.
if vm.GetUser() != user.GetId() && vm.GetVmType() == vmpb.VirtualMachineType_USER {
// check if the user has access to user sessions
impersonatedUserId := user.GetId()
authrResponse, err := rbac2.Authorize(r, sp.authrClient, impersonatedUserId, []*authrpb.Permission{
Expand Down Expand Up @@ -840,11 +841,9 @@ func (sp ShellProxy) VerifyTasksFuncByVMIdGroupWithSemaphore(w http.ResponseWrit
// Handle the error (log, return HTTP error response)
close(errorChan)
glog.Infof("Error in goroutine: %v", err)
util.ReturnHTTPMessage(w, r, 500, "error", "could send command to vm")
util.ReturnHTTPMessage(w, r, 500, "error", "could not send command to vm")
return
default:
// No error in the errorChan
glog.Infof("No Error in goroutine: %v", vm_output_tasks)
jsonStr, _ := json.Marshal(vm_output_tasks)
util.ReturnHTTPContent(w, r, 200, "success", jsonStr)
}
Expand Down
17 changes: 17 additions & 0 deletions v3/pkg/util/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,20 @@ func ConvertToStringMapStructMap(in map[string]map[string]string) map[string]*ge
}
return output
}

// This function converts a string or underlying string type to a protobuf enum
func ConvertToPBEnum[T ~string, PB ~int32](val T, pbmap map[string]int32, dftVal PB) PB {
v, ok := pbmap[string(val)]
if !ok {
return dftVal
}
return PB(v)
}

func ConvertToStringEnum[PB ~int32, T ~string](pbval PB, pbmap map[int32]string, dftStr T) T {
v, ok := pbmap[int32(pbval)]
if !ok {
return dftStr
}
return T(v)
}
21 changes: 21 additions & 0 deletions v3/pkg/util/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,24 @@ func VerifyTaskContent(vm_tasks []hfv1.VirtualMachineTasks, request proto.Messag
}
return nil
}

func VerifySharedVirtualMachineContent(virtual_machines []hfv1.SharedVirtualMachine, request proto.Message) error {
//Verify that name, description and command are not empty
for _, virtual_machine := range virtual_machines {
if virtual_machine.Name == "" {
glog.Errorf("error: Name (of virtual_machines) is not specified")
return hferrors.GrpcError(codes.InvalidArgument, "name for virtual_machines property is not specified", request)
}

if virtual_machine.Environment == "" {
glog.Errorf("error: Environment (of virtual_machine %s) is not specified", virtual_machine.Name)
return hferrors.GrpcError(codes.InvalidArgument, "name for virtual_machines property is not specified for "+virtual_machine.Name, request)
}

if virtual_machine.VMTemplate == "" {
glog.Errorf("error VMTemplate (of virtual_machine %s) is not specified", virtual_machine.Name)
return hferrors.GrpcError(codes.InvalidArgument, "name for virtual_machines property is not specified for "+virtual_machine.Name, request)
}
}
return nil
}
2 changes: 1 addition & 1 deletion v3/protos/accesscode/accesscode.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/authn/authn.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/authr/authr.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/cost/cost.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/course/course.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/dbconfig/dbconfig.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/environment/environment.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/general/general.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/progress/progress.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/rbac/rbac.pb.go

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

2 changes: 1 addition & 1 deletion v3/protos/scenario/scenario.pb.go

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

Loading
Loading