mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-21 10:45:25 +02:00
Disable host directory sharing by default (#462)
This commit is contained in:
@@ -46,6 +46,7 @@ type Controller struct {
|
||||
listener net.Listener
|
||||
httpServer *http.Server
|
||||
insecureAuthDisabled bool
|
||||
insecureAllowHostDirs bool
|
||||
scheduler *scheduler.Scheduler
|
||||
store storepkg.Store
|
||||
logger *zap.SugaredLogger
|
||||
@@ -195,6 +196,14 @@ func New(opts ...Option) (*Controller, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// When no "--insecure-allow-host-dirs" is present,
|
||||
// fail the VMs that have "hostDirs" set
|
||||
if !controller.insecureAllowHostDirs {
|
||||
if err := controller.failVMsWithHostDirs(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
@@ -305,6 +314,31 @@ func (controller *Controller) DeleteServiceAccount(name string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (controller *Controller) failVMsWithHostDirs() error {
|
||||
return controller.store.Update(func(txn storepkg.Transaction) error {
|
||||
vms, err := txn.ListVMs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, vm := range vms {
|
||||
if vm.TerminalState() || len(vm.HostDirs) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
vm.Status = v1.VMStatusFailed
|
||||
vm.StatusMessage = "host directories are used, but host directory sharing is disabled"
|
||||
vm.RestartPolicy = v1.RestartPolicyNever
|
||||
|
||||
if err := txn.SetVM(vm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (controller *Controller) Run(ctx context.Context) error {
|
||||
// Run the scheduler so that each VM will eventually
|
||||
// be assigned to a specific Worker
|
||||
|
||||
Reference in New Issue
Block a user