Skip to content

Commit

Permalink
fix: Enforce name consistency (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: guofei <guofei@microsoft.com>
  • Loading branch information
Fei-Guo and Fei-Guo authored Oct 6, 2023
1 parent 2f2e38c commit 511790d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ You should have a running controller in `gpu-provisioner` namespace.

## How to test
After deploying the controller successfully, one can apply the yaml in `/example` to create a machine CR. A real node will be created and added to the cluster by the controller.

## Important note
The gpu-provisioner assumes the Machine CR name is **equal** to the agent pool name. Hence, **the machine CR name must be 1-11 characters in length, start with a letter, and the only allowed characters are letters and numbers**.
2 changes: 1 addition & 1 deletion examples/machine-gpu.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: karpenter.sh/v1alpha5
kind: Machine
metadata:
name: machine-gpu-1
name: gpuvm
labels:
karpenter.sh/provisioner-name: default
spec:
Expand Down
2 changes: 1 addition & 1 deletion examples/machine-regular.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: karpenter.sh/v1alpha5
kind: Machine
metadata:
name: machine-regular-vms
name: regularvms
labels:
karpenter.sh/provisioner-name: default
spec:
Expand Down
5 changes: 3 additions & 2 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ func NewProvider(
func (p *Provider) Create(ctx context.Context, machine *v1alpha5.Machine, instanceTypes []*corecloudprovider.InstanceType) (*Instance, error) {
klog.InfoS("Instance.Create", "machine", klog.KObj(machine))

apName := strings.ReplaceAll(machine.Name, "-", "")
// We made a strong assumption here. The machine name should be a valid agent pool name without "-".
apName := machine.Name
if len(apName) > 11 {
//https://learn.microsoft.com/en-us/troubleshoot/azure/azure-kubernetes/aks-common-issues-faq#what-naming-restrictions-are-enforced-for-aks-resources-and-parameters-
return nil, fmt.Errorf("agentpool %q name is too long", apName)
return nil, fmt.Errorf("the length agentpool name should be less than 11, got %d (%s)", len(apName), apName)
}

if len(instanceTypes) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suites/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = Describe("GPU", func() {

machine := test.Machine(v1alpha5.Machine{
ObjectMeta: metav1.ObjectMeta{
Name: "test-machine",
Name: "testmachine",
Labels: machineLabels,
},
Spec: v1alpha5.MachineSpec{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 511790d

Please sign in to comment.