github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/orbiter/kinds/providers/cs/pool.go (about)

     1  package cs
     2  
     3  import (
     4  	"errors"
     5  	"github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/core/infra"
     6  	"github.com/caos/orbos/internal/operator/orbiter/kinds/providers/core"
     7  )
     8  
     9  var _ infra.Pool = (*infraPool)(nil)
    10  
    11  type infraPool struct {
    12  	pool        string
    13  	machinesSvc core.MachinesService
    14  }
    15  
    16  func newInfraPool(pool string, machinesSvc core.MachinesService) *infraPool {
    17  	return &infraPool{
    18  		pool:        pool,
    19  		machinesSvc: machinesSvc,
    20  	}
    21  }
    22  
    23  func (i *infraPool) DesiredMembers(instances int) int {
    24  	return instances
    25  }
    26  
    27  func (i *infraPool) EnsureMember(infra.Machine) error {
    28  	// Keepalived health checks should work
    29  	return nil
    30  }
    31  
    32  func (i *infraPool) EnsureMembers() error {
    33  	// Keepalived health checks should work
    34  	return nil
    35  }
    36  
    37  func (i *infraPool) GetMachines() (infra.Machines, error) {
    38  	return i.machinesSvc.List(i.pool)
    39  }
    40  
    41  func (i *infraPool) AddMachine(desiredInstances int) (infra.Machines, error) {
    42  	machines, err := i.machinesSvc.Create(i.pool, desiredInstances)
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  	if machines == nil || len(machines) != 1 {
    47  		return nil, errors.New("error while creating machine")
    48  	}
    49  	return machines, nil
    50  }