Skip to content

Commit 2d44e2c

Browse files
committed
fix: nits from review
1 parent 3881216 commit 2d44e2c

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

docs/content/customization/nutanix/machine-details.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,18 @@ spec:
111111
vcpusPerSocket: 1
112112
```
113113

114-
### (Optional) Use Image template
114+
### (Optional) Using templates for VM Image lookup:
115+
116+
Users can set format look up the image for a VM, It will be ignored if an explicit image is set.
117+
Supports substitutions for `{{.BaseOS}}` and `{{.K8sVersion}}` with the base OS and
118+
kubernetes version, respectively. The BaseOS will be the value in BaseOS and the K8sVersion
119+
is the value in the Machine `.spec.version`, with the v prefix removed.
120+
This is effectively the defined by the packages produced by kubernetes/release without v as a
121+
prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
122+
image format of `{{.BaseOS}}-?{{.K8sVersion}}-*` and `BaseOS` as "rhel-8.10" will end up
123+
searching for images that match the pattern rhel-8.10-1.30.5-* for a
124+
Machine that is targeting Kubernetes version `v1.30.5`. See
125+
also: https://golang.org/pkg/text/template/
115126

116127
```yaml
117128
apiVersion: cluster.x-k8s.io/v1beta1

pkg/handlers/nutanix/mutation/machinedetails/inject.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package machinedetails
55

66
import (
77
"context"
8+
"errors"
89
"slices"
910

1011
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -32,6 +33,9 @@ type nutanixMachineDetailsPatchHandler struct {
3233
patchSelector clusterv1.PatchSelector
3334
}
3435

36+
// ErrNoImageOrImageLookupSet is an error that gets returned only if image and lookup are both set.
37+
var ErrNoImageOrImageLookupSet = errors.New("image or image lookup must be set")
38+
3539
func newNutanixMachineDetailsPatchHandler(
3640
metaVariableName string,
3741
variableFieldPath []string,
@@ -94,10 +98,14 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
9498

9599
spec.BootType = nutanixMachineDetailsVar.BootType
96100
spec.Cluster = nutanixMachineDetailsVar.Cluster
97-
if nutanixMachineDetailsVar.Image != nil {
101+
102+
switch {
103+
case nutanixMachineDetailsVar.Image != nil:
98104
spec.Image = nutanixMachineDetailsVar.Image.DeepCopy()
99-
} else if nutanixMachineDetailsVar.ImageLookup != nil {
105+
case nutanixMachineDetailsVar.ImageLookup != nil:
100106
spec.ImageLookup = nutanixMachineDetailsVar.ImageLookup.DeepCopy()
107+
default:
108+
return ErrNoImageOrImageLookupSet
101109
}
102110

103111
spec.VCPUSockets = nutanixMachineDetailsVar.VCPUSockets

test/e2e/data/shared/v1beta1-capx/metadata.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
1111
kind: Metadata
1212
releaseSeries:
13-
- major: 1
14-
minor: 5
15-
contract: v1beta1
1613
- major: 1
1714
minor: 6
1815
contract: v1beta1

0 commit comments

Comments
 (0)