Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ providerConfigs:
# (default: "")
# POWERVS_BUILD_TIMEOUT: ""

# Maximum timeout to wait for DHCP IP assignment
# (default: "")
# POWERVS_DHCP_TIMEOUT: ""

# ID of the boot image
# (required)
POWERVS_IMAGE_ID: ""
Expand Down Expand Up @@ -87,8 +91,8 @@ providerConfigs:
# POWERVS_SSH_KEY_NAME: ""

# Name of the system type
# (default: "s922")
# POWERVS_SYSTEM_TYPE: "s922"
# (default: "s1022")
# POWERVS_SYSTEM_TYPE: "s1022"

# PowerVS zone name
# (required)
Expand Down
3 changes: 2 additions & 1 deletion src/cloud-providers/ibmcloudpowervs/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ func (*Manager) ParseCmd(flags *flag.FlagSet) {
reg.StringWithEnv(&ibmcloudPowerVSConfig.ImageID, "image-id", "", "POWERVS_IMAGE_ID", "ID of the boot image", provider.Required())
reg.StringWithEnv(&ibmcloudPowerVSConfig.SSHKey, "ssh-key", "", "POWERVS_SSH_KEY_NAME", "Name of the SSH Key")
reg.StringWithEnv(&ibmcloudPowerVSConfig.ProcessorType, "proc-type", "shared", "POWERVS_PROCESSOR_TYPE", "Name of the processor type")
reg.StringWithEnv(&ibmcloudPowerVSConfig.SystemType, "sys-type", "s922", "POWERVS_SYSTEM_TYPE", "Name of the system type")
reg.StringWithEnv(&ibmcloudPowerVSConfig.SystemType, "sys-type", "s1022", "POWERVS_SYSTEM_TYPE", "Name of the system type")
reg.Float64WithEnv(&ibmcloudPowerVSConfig.Memory, "memory", 2, "POWERVS_MEMORY", "Amount of memory in GB")
reg.Float64WithEnv(&ibmcloudPowerVSConfig.Processors, "cpu", 0.5, "POWERVS_PROCESSORS", "Number of processors allocated")
reg.BoolWithEnv(&ibmcloudPowerVSConfig.UsePublicIP, "use-public-ip", false, "USE_PUBLIC_IP", "Use Public IP for connecting to the agent-protocol-forwarder inside the Pod VM")
reg.DurationWithEnv(&ibmcloudPowerVSConfig.BuildTimeout, "build-timeout", 150*time.Second, "POWERVS_BUILD_TIMEOUT", "Maximum timeout to build the VM")
reg.DurationWithEnv(&ibmcloudPowerVSConfig.DHCPTimeout, "dhcp-timeout", 750*time.Second, "POWERVS_DHCP_TIMEOUT", "Maximum timeout to wait for DHCP IP assignment")
}

func (*Manager) LoadEnv() {
Expand Down
56 changes: 43 additions & 13 deletions src/cloud-providers/ibmcloudpowervs/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log"
"net/netip"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -69,21 +70,27 @@ func (p *ibmcloudPowerVSProvider) CreateInstance(ctx context.Context, podName, s
// If machine type is set in annotations then use it (ie. shape <system_type>-<cpu>x<memoery>)
// vCPU and Memory gets higher priority than instance type from annotation
if spec.VCPUs != 0 && spec.Memory != 0 {
memory = float64(spec.Memory / 1024)
memory = float64(spec.Memory) / 1024.0
processors = float64(spec.VCPUs)
logger.Printf("Instance type selected by the cloud provider based on vCPU and memory annotations: %s-%gx%g", systemType, processors, memory)
} else if spec.InstanceType != "" {
typeAndSize := strings.Split(spec.InstanceType, "-")
if len(typeAndSize) != 2 {
return nil, fmt.Errorf("invalid instance type format %q: expected <sys_type>-<cpu>x<memory>", spec.InstanceType)
}
systemType = typeAndSize[0]
size := strings.Split(typeAndSize[1], "x")
if len(size) != 2 {
return nil, fmt.Errorf("invalid instance type format %q: expected <sys_type>-<cpu>x<memory>", spec.InstanceType)
}
f, err := strconv.Atoi(size[0])
if err != nil {
return nil, err
return nil, fmt.Errorf("invalid cpu value in instance type %q: %w", spec.InstanceType, err)
}
processors = float64(f)
m, err := strconv.Atoi(size[1])
if err != nil {
return nil, err
return nil, fmt.Errorf("invalid memory value in instance type %q: %w", spec.InstanceType, err)
}
memory = float64(m)
logger.Printf("Instance type selected by the cloud provider based on instance type annotation: %s", spec.InstanceType)
Expand Down Expand Up @@ -195,9 +202,32 @@ func (p *ibmcloudPowerVSProvider) Teardown() error {
}

func (p *ibmcloudPowerVSProvider) ConfigVerifier() error {
imageID := p.serviceConfig.ImageID
if len(imageID) == 0 {
return fmt.Errorf("ImageId is empty")
validProcessorTypes := []string{"shared", "dedicated", "capped"}
validSystemTypes := []string{"s922", "s1022", "s1122", "e980", "e1080"}

var errs []string

if len(p.serviceConfig.ImageID) == 0 {
errs = append(errs, "ImageID is empty")
}
if len(p.serviceConfig.NetworkID) == 0 {
errs = append(errs, "NetworkID is empty")
}
if len(p.serviceConfig.ServiceInstanceID) == 0 {
errs = append(errs, "ServiceInstanceID is empty")
}
if len(p.serviceConfig.Zone) == 0 {
errs = append(errs, "Zone is empty")
}
if !slices.Contains(validProcessorTypes, p.serviceConfig.ProcessorType) {
errs = append(errs, fmt.Sprintf("ProcessorType %q is invalid, must be one of %v", p.serviceConfig.ProcessorType, validProcessorTypes))
}
if !slices.Contains(validSystemTypes, p.serviceConfig.SystemType) {
errs = append(errs, fmt.Sprintf("SystemType %q is invalid, must be one of %v", p.serviceConfig.SystemType, validSystemTypes))
}

if len(errs) > 0 {
return fmt.Errorf("invalid PowerVS config: %s", strings.Join(errs, "; "))
}
return nil
}
Expand Down Expand Up @@ -230,19 +260,19 @@ func (p *ibmcloudPowerVSProvider) getVMIPs(ctx context.Context, instanceID strin
return ips, nil
}

ctx, cancel := context.WithTimeout(ctx, 750*time.Second)
defer cancel()

// If IP is not assigned to the instance, fetch it from DHCP server
logger.Printf("Trying to fetch IP from DHCP server..")
dhcpCtx, dhcpCancel := context.WithTimeout(ctx, p.serviceConfig.DHCPTimeout)
defer dhcpCancel()

logger.Printf("Trying to fetch IP from DHCP server (timeout: %s)..", p.serviceConfig.DHCPTimeout)
err = retry.Do(func() error {
ip, err := p.getIPFromDHCPServer(ctx, ins)
ip, err := p.getIPFromDHCPServer(dhcpCtx, ins)
if err != nil {
logger.Print(err)
return err
}
if ip == nil {
return fmt.Errorf("failed to get IP from DHCP server: %v", err)
return fmt.Errorf("DHCP lease not yet assigned for instance (will retry)")
}

addr, err := netip.ParseAddr(*ip)
Expand All @@ -254,7 +284,7 @@ func (p *ibmcloudPowerVSProvider) getVMIPs(ctx context.Context, instanceID strin
logger.Printf("podNodeIP=%s", addr.String())
return nil
},
retry.Context(ctx),
retry.Context(dhcpCtx),
retry.Attempts(0),
retry.MaxDelay(10*time.Second),
)
Expand Down
1 change: 1 addition & 0 deletions src/cloud-providers/ibmcloudpowervs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
SystemType string
UsePublicIP bool
BuildTimeout time.Duration
DHCPTimeout time.Duration
}

func (c Config) Redact() Config {
Expand Down
Loading