Skip to content

Commit 383cc91

Browse files
committed
fix: Parse flexible shape name correctly for OCI API
- Extract base shape name (VM.Standard.E4.Flex) from full name (VM.Standard.E4.Flex-1-16) - Parse CPU and memory config from shape suffix - Use base shape name in LaunchInstance API call with separate ShapeConfig
1 parent 1b769c5 commit 383cc91

3 files changed

Lines changed: 62 additions & 9 deletions

File tree

docs/flux-helmrelease-final.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ spec:
3232

3333
settings:
3434
clusterName: "ashburn-ops-oke-stg"
35-
logLevel: "info"
35+
logLevel: "debug"
36+
37+
# Add environment variable to enable OCI SDK debug logging
38+
controller:
39+
env:
40+
- name: OCI_GO_SDK_DEBUG
41+
value: "info"
3642

3743
serviceAccount:
3844
create: false

pkg/providers/oci/client.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/base64"
2222
"fmt"
2323
"io"
24+
"strconv"
2425
"strings"
2526
"time"
2627

@@ -161,26 +162,44 @@ func (c *Client) LaunchInstance(ctx context.Context, nodeClaim *v1.NodeClaim, no
161162
},
162163
}
163164

164-
// Add shape config for flexible shapes
165+
// Handle flexible shapes - extract base shape and config
166+
actualShape := shape
165167
if isFlexibleShape(shape) {
166168
// Parse shape name to extract OCPUs and memory
167169
// Format: VM.Standard.E4.Flex-1-16 (1 OCPU, 16GB memory)
168170
var ocpus, memory int32 = 1, 16
169-
if _, err := fmt.Sscanf(shape, "VM.Standard.E4.Flex-%d-%d", &ocpus, &memory); err == nil {
170-
request.LaunchInstanceDetails.ShapeConfig = &core.LaunchInstanceShapeConfigDetails{
171-
Ocpus: common.Float32(float32(ocpus)),
172-
MemoryInGBs: common.Float32(float32(memory)),
171+
172+
// Extract base shape name and config
173+
parts := strings.Split(shape, "-")
174+
if len(parts) >= 3 {
175+
// Get base shape (e.g., VM.Standard.E4.Flex)
176+
actualShape = strings.Join(parts[:len(parts)-2], "-")
177+
178+
// Try to parse CPU and memory from the last two parts
179+
if cpu, err := strconv.Atoi(parts[len(parts)-2]); err == nil {
180+
ocpus = int32(cpu)
181+
}
182+
if mem, err := strconv.Atoi(parts[len(parts)-1]); err == nil {
183+
memory = int32(mem)
173184
}
174-
logger.Info("added shape config for flexible shape",
175-
"shape", shape, "ocpus", ocpus, "memory", memory)
176185
}
186+
187+
request.LaunchInstanceDetails.ShapeConfig = &core.LaunchInstanceShapeConfigDetails{
188+
Ocpus: common.Float32(float32(ocpus)),
189+
MemoryInGBs: common.Float32(float32(memory)),
190+
}
191+
logger.Info("added shape config for flexible shape",
192+
"originalShape", shape, "actualShape", actualShape, "ocpus", ocpus, "memory", memory)
177193
}
194+
195+
// Update the shape in the request
196+
request.LaunchInstanceDetails.Shape = &actualShape
178197

179198
// Log the launch request details including shape config
180199
logFields := []interface{}{
181200
"displayName", *request.LaunchInstanceDetails.DisplayName,
182201
"subnet", *request.LaunchInstanceDetails.CreateVnicDetails.SubnetId,
183-
"shape", shape,
202+
"shape", actualShape,
184203
}
185204
if request.LaunchInstanceDetails.ShapeConfig != nil {
186205
logFields = append(logFields,

scripts/test-launch-instance.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Test launching an instance with the same parameters as Karpenter
3+
4+
COMPARTMENT_ID="ocid1.compartment.oc1..aaaaaaaalr5oi5mfqpjedsdsyn3vxn2fh2bltqezqrmk4bi7gaq6i245qnkq"
5+
IMAGE_ID="ocid1.image.oc1.iad.aaaaaaaaknzkygdhz6n3vmaovv3ouh2sxt7cudrdomefqfxnampnfrtpp6rq"
6+
SUBNET_ID="ocid1.subnet.oc1.iad.aaaaaaaaznwweno45m7klssbzt2kyl6qa4ec34335patiolemkti6d4ioita"
7+
SHAPE="VM.Standard.E4.Flex"
8+
9+
# Get availability domain
10+
AD=$(oci iam availability-domain list --compartment-id "$COMPARTMENT_ID" --query "data[0].name" --raw-output)
11+
12+
echo "Testing instance launch with:"
13+
echo " Compartment: $COMPARTMENT_ID"
14+
echo " Image: $IMAGE_ID"
15+
echo " Subnet: $SUBNET_ID"
16+
echo " Shape: $SHAPE"
17+
echo " AD: $AD"
18+
19+
# Test launching instance
20+
oci compute instance launch \
21+
--compartment-id "$COMPARTMENT_ID" \
22+
--availability-domain "$AD" \
23+
--shape "$SHAPE" \
24+
--shape-config '{"ocpus": 1, "memoryInGBs": 16}' \
25+
--image-id "$IMAGE_ID" \
26+
--subnet-id "$SUBNET_ID" \
27+
--display-name "karpenter-test-manual" \
28+
--assign-public-ip false

0 commit comments

Comments
 (0)