Skip to content

Commit 7df9b2a

Browse files
Use XOR
1 parent f2c8cbc commit 7df9b2a

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

api/v1alpha1/ionoscloudmachine_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ type Volume struct {
234234
AvailabilityZone AvailabilityZone `json:"availabilityZone,omitempty"`
235235

236236
// Image is the image to use for the VM.
237-
//+kubebuilder:validation:XValidation:rule="self.id != '' || has(self.selector)",message="must provide either id or selector"
237+
//+kubebuilder:validation:XValidation:rule="has(self.id) && !has(self.selector) || !has(self.id) && has(self.selector)",message="must provide either id or selector"
238238
Image *ImageSpec `json:"image"`
239239
}
240240

api/v1alpha1/ionoscloudmachine_types_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ var _ = Describe("IonosCloudMachine Tests", func() {
352352
Expect(m.Spec.Disk.Image.Selector.UseMachineVersion).ToNot(BeNil())
353353
Expect(*m.Spec.Disk.Image.Selector.UseMachineVersion).To(BeTrue())
354354
})
355+
It("should fail if both ID and selector are set", func() {
356+
m := defaultMachine()
357+
m.Spec.Disk.Image.ID = "1eef-48ec-a246-a51a33aa4f3a"
358+
m.Spec.Disk.Image.Selector = &ImageSelector{
359+
MatchLabels: map[string]string{
360+
"foo": "bar",
361+
},
362+
}
363+
Expect(k8sClient.Create(context.Background(), m)).ToNot(Succeed())
364+
})
355365
})
356366
})
357367
Context("Additional Networks", func() {

config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudmachines.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ spec:
235235
type: object
236236
x-kubernetes-validations:
237237
- message: must provide either id or selector
238-
rule: self.id != '' || has(self.selector)
238+
rule: has(self.id) && !has(self.selector) || !has(self.id) &&
239+
has(self.selector)
239240
name:
240241
description: Name is the name of the volume
241242
type: string

config/crd/bases/infrastructure.cluster.x-k8s.io_ionoscloudmachinetemplates.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ spec:
256256
type: object
257257
x-kubernetes-validations:
258258
- message: must provide either id or selector
259-
rule: self.id != '' || has(self.selector)
259+
rule: has(self.id) && !has(self.selector) || !has(self.id)
260+
&& has(self.selector)
260261
name:
261262
description: Name is the name of the volume
262263
type: string

internal/ionoscloud/clienttest/mock_client.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.

0 commit comments

Comments
 (0)