Skip to content

Commit 502cedd

Browse files
committed
feat: rework instsance types to include zone/region
Signed-off-by: Dinar Valeev <k0da@opensuse.org>
1 parent 3df5079 commit 502cedd

File tree

9 files changed

+71
-28
lines changed

9 files changed

+71
-28
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Karpenter provider for VMWare Vsphere
44

5+
# !!!Early alpha - NOT for Production use!!!
6+
57
# Required flags
68

79
| Flag | Environment variable | Required |
@@ -22,7 +24,13 @@ Besides `VSPHERE_PATH` (vsphere folder to place virtulal machines on), all place
2224

2325
All selectors have `tag` and `name` properties, those are mutually exclusive. Karpenter will find a resource either by Tag or Name.
2426

25-
* `.spec.instanceTypes` - a list of desired instance types, in a following format: `%cpu-%mem-%os`, e.g. 8-16-linux
27+
* `.spec.instanceTypes` - a list of desired instance types:
28+
- `os`: linux
29+
- `cpu`: number of CPUS
30+
- `memory`: amount of memory in gigabytes
31+
- `region`: region topology
32+
- `zone`: zone topology
33+
- `maxPods`: maxPods to pass to kubelet (not implemented)
2634
* `.spec.diskSize` - a desired root volume size in Gigabytes
2735

2836
* `.spec.tags` - a list of tags to apply to Karpenter managed virtual machines
@@ -36,4 +44,4 @@ All selectors have `tag` and `name` properties, those are mutually exclusive. Ka
3644
- `templateBase64` - A base64 encoded template
3745
- `values` - a v1.Secret reference (name/namespace) to key/values used in a template
3846

39-
[!NOTE] user-data should hanndle `karpenter.sh/unregistered` taint to the node
47+
[!NOTE] user-data should hanndle `karpenter.sh/unregistered` taint to the node

charts/karpenter-crd/templates/karpenter.vsphere.com_vspherenodeclasses.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,22 @@ spec:
119119
type: object
120120
instanceTypes:
121121
items:
122-
type: string
122+
properties:
123+
arch:
124+
type: string
125+
cpu:
126+
type: string
127+
maxPods:
128+
type: string
129+
memory:
130+
type: string
131+
os:
132+
type: string
133+
region:
134+
type: string
135+
zone:
136+
type: string
137+
type: object
123138
type: array
124139
networkSelector:
125140
properties:

charts/karpenter/crds/karpenter.vsphere.com_vspherenodeclasses.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,22 @@ spec:
116116
type: object
117117
instanceTypes:
118118
items:
119-
type: string
119+
properties:
120+
arch:
121+
type: string
122+
cpu:
123+
type: string
124+
maxPods:
125+
type: string
126+
memory:
127+
type: string
128+
os:
129+
type: string
130+
region:
131+
type: string
132+
zone:
133+
type: string
134+
type: object
120135
type: array
121136
networkSelector:
122137
properties:

pkg/apis/crds/karpenter.vsphere.com_vspherenodeclasses.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,22 @@ spec:
116116
type: object
117117
instanceTypes:
118118
items:
119-
type: string
119+
properties:
120+
arch:
121+
type: string
122+
cpu:
123+
type: string
124+
maxPods:
125+
type: string
126+
memory:
127+
type: string
128+
os:
129+
type: string
130+
region:
131+
type: string
132+
zone:
133+
type: string
134+
type: object
120135
type: array
121136
networkSelector:
122137
properties:

pkg/apis/v1alpha1/labels.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1alpha1
22

33
import (
44
"github.com/absaoss/karpenter-provider-vsphere/pkg/apis"
5+
corev1 "k8s.io/api/core/v1"
56
coreapis "sigs.k8s.io/karpenter/pkg/apis"
67
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"
78
)
@@ -23,6 +24,7 @@ var (
2324
LabelInstanceCPU = apis.Group + "/instance-cpu"
2425
LabelInstanceMemory = apis.Group + "/instance-memory"
2526
LabelInstanceSize = apis.Group + "/instance-size"
27+
LabelInstanceType = corev1.LabelInstanceTypeStable
2628
AnnotationVsphereNodeClassHashVersion = apis.Group + "/vspherenodeclass-hash-version"
2729
NodeClaimTagKey = coreapis.Group + "/nodeclaim"
2830
NodePoolTagKey = karpv1.NodePoolLabelKey

pkg/apis/v1alpha1/vspherenodeclass.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type VsphereNodeClassSpec struct {
9898
Datacenter DCSelectorTerm `json:"dcSelector,omitempty"`
9999
ImageSelector ImageSelectorTerm `json:"imageSelector,omitempty"`
100100
DiskSize int64 `json:"diskSize,omitempty"`
101-
InstanceTypes []string `json:"instanceTypes,omitempty"`
101+
InstanceTypes []InstanceType `json:"instanceTypes,omitempty"`
102102
UserData UserData `json:"userData,omitempty"`
103103
Tags map[string]string `json:"tags,omitempty"`
104104
}
@@ -124,6 +124,8 @@ type InstanceType struct {
124124
MaxPods string `json:"maxPods,omitempty"`
125125
OS string `json:"os,omitempty"`
126126
Arch string `json:"arch,omitempty"`
127+
Zone string `json:"zone,omitempty"`
128+
Region string `json:"region,omitempty"`
127129
}
128130

129131
func (nc *VsphereNodeClass) Hash() string {

pkg/apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cloudprovider/cloudprovider.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
stderrors "errors"
66
"fmt"
7-
"regexp"
87
"strings"
98
"time"
109

@@ -114,6 +113,8 @@ func (c *CloudProvider) instanceToNodeClaim(i *instance.Instance, instanceType *
114113
nodeClaim.Status.Capacity = lo.PickBy(instanceType.Capacity, resourceFilter)
115114
nodeClaim.Status.Allocatable = lo.PickBy(instanceType.Allocatable(), resourceFilter)
116115
}
116+
labels[corev1.LabelInstanceTypeStable] = instanceType.Name
117+
117118
//TODO: Figure out TopologyZone label
118119
labels[corev1.LabelTopologyZone] = i.Tags[corev1.LabelTopologyZone]
119120

@@ -277,22 +278,9 @@ func instanceTypesFromNodeClass(nodeClass *v1alpha1.VsphereNodeClass) []*cloudpr
277278
instanceTypes := []*cloudprovider.InstanceType{}
278279
var cpu, memory, os string
279280
for _, t := range nodeClass.Spec.InstanceTypes {
280-
instanceTypeRegex := regexp.MustCompile(`(?P<CPU>.*)-(?P<Memory>.*)-(?P<OS>.*)`)
281-
matches := instanceTypeRegex.FindStringSubmatch(t)
282-
if matches == nil {
283-
fmt.Printf("instance type %s does not match expected format\n", t)
284-
}
285-
for i, name := range instanceTypeRegex.SubexpNames() {
286-
if name == "CPU" {
287-
cpu = matches[i]
288-
}
289-
if name == "Memory" {
290-
memory = matches[i]
291-
}
292-
if name == "OS" {
293-
os = matches[i]
294-
}
295-
}
281+
cpu = t.CPU
282+
memory = t.Memory
283+
os = strings.ToLower(t.OS)
296284
typeName := fmt.Sprintf("vsphere-vm.cpu-%s.mem-%sgb.os-%s", cpu, memory, os)
297285
instanceType := &cloudprovider.InstanceType{
298286
Name: typeName,
@@ -304,15 +292,15 @@ func instanceTypesFromNodeClass(nodeClass *v1alpha1.VsphereNodeClass) []*cloudpr
304292
Capacity: corev1.ResourceList{
305293
corev1.ResourceCPU: resource.MustParse(cpu),
306294
corev1.ResourceMemory: resource.MustParse(memory),
307-
corev1.ResourcePods: resource.MustParse("110"),
295+
corev1.ResourcePods: resource.MustParse(t.MaxPods),
308296
corev1.ResourceEphemeralStorage: resource.MustParse(utils.GiToByteAsString(nodeClass.Spec.DiskSize)),
309297
},
310298
//TODO: compute kubelet overhead
311299
Overhead: &cloudprovider.InstanceTypeOverhead{},
312300
Offerings: []*cloudprovider.Offering{
313301
{
314302
Requirements: scheduling.NewRequirements(
315-
scheduling.NewRequirement(corev1.LabelTopologyZone, corev1.NodeSelectorOpIn)),
303+
scheduling.NewRequirement(corev1.LabelTopologyZone, corev1.NodeSelectorOpIn, t.Zone)),
316304
Price: float64(0.0),
317305
Available: true,
318306
},

pkg/controllers/nodeclass/hash/controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ func (c *Controller) updateNodeClaimHash(ctx context.Context, nodeClass *v1alpha
7777
v1alpha1.AnnotationVsphereNodeClassHashVersion: v1alpha1.VsphereNodeClassHashVersion,
7878
})
7979

80-
// Any NodeClaim that is already drifted will remain drifted if the karpenter.azure.com/nodepool-hash-version doesn't match
81-
// Since the hashing mechanism has changed we will not be able to determine if the drifted status of the NodeClaim has changed
8280
if nc.StatusConditions().Get(karpv1.ConditionTypeDrifted) == nil {
8381
nc.Annotations = lo.Assign(nc.Annotations, map[string]string{
8482
v1alpha1.AnnotationVsphereNodeClassHash: nodeClass.Hash(),

0 commit comments

Comments
 (0)