Skip to content

Commit 539b1dd

Browse files
authored
chore(vmip): prevent creation of a vmip outside the allowed ip range (#2201)
Signed-off-by: Valeriy Khorunzhin <valeriy.khorunzhin@flant.com>
1 parent 97dd48a commit 539b1dd

3 files changed

Lines changed: 22 additions & 23 deletions

File tree

images/virtualization-artifact/pkg/controller/vmip/vmip_webhook.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,19 @@ func (v *Validator) ValidateCreate(ctx context.Context, obj runtime.Object) (adm
6565
return nil, fmt.Errorf("the VirtualMachineIPAddress validation is failed: %w", err)
6666
}
6767

68-
var warnings admission.Warnings
69-
7068
if vmip.Spec.StaticIP != "" {
7169
err = v.validateAllocatedIPAddresses(ctx, vmip.Spec.StaticIP)
7270
switch {
7371
case err == nil:
7472
// OK.
7573
case errors.Is(err, service.ErrIPAddressOutOfRange):
76-
warnings = append(warnings, fmt.Sprintf("The requested address %s is out of the valid range", vmip.Spec.StaticIP))
74+
return nil, fmt.Errorf("the requested address %s is out of the valid range", vmip.Spec.StaticIP)
7775
default:
7876
return nil, err
7977
}
8078
}
8179

82-
return warnings, nil
80+
return nil, nil
8381
}
8482

8583
func (v *Validator) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {

test/e2e/legacy/complex.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var _ = Describe("ComplexTest", Ordered, label.Legacy(), func() {
4343
hasNoConsumerLabel = map[string]string{"hasNoConsumer": "complex-test"}
4444
ns string
4545
phaseByVolumeBindingMode = util.GetExpectedDiskPhaseByVolumeBindingMode()
46-
f = framework.NewFramework("")
4746
)
4847

4948
AfterEach(func() {
@@ -107,23 +106,25 @@ var _ = Describe("ComplexTest", Ordered, label.Legacy(), func() {
107106
})
108107
})
109108

110-
Context("When virtual machines IP addresses are applied", func() {
111-
It("patches custom VMIP with unassigned address", func() {
112-
vmipName := fmt.Sprintf("%s-%s", namePrefix, "vm-custom-ip")
113-
Eventually(func() error {
114-
return AssignIPToVMIP(f, ns, vmipName)
115-
}).WithTimeout(LongWaitDuration).WithPolling(Interval).Should(Succeed())
116-
})
117-
118-
It("checks VMIPs phases", func() {
119-
By(fmt.Sprintf("VMIPs should be in %s phases", PhaseAttached))
120-
WaitPhaseByLabel(kc.ResourceVMIP, PhaseAttached, kc.WaitOptions{
121-
Labels: testCaseLabel,
122-
Namespace: ns,
123-
Timeout: MaxWaitTimeout,
124-
})
125-
})
126-
})
109+
// TODO: Creating a VMIP outside the allowed range is now rejected by the webhook.
110+
// Re-enable this when we figure out how to keep the test coverage.
111+
// Context("When virtual machines IP addresses are applied", func() {
112+
// It("patches custom VMIP with unassigned address", func() {
113+
// vmipName := fmt.Sprintf("%s-%s", namePrefix, "vm-custom-ip")
114+
// Eventually(func() error {
115+
// return AssignIPToVMIP(f, ns, vmipName)
116+
// }).WithTimeout(LongWaitDuration).WithPolling(Interval).Should(Succeed())
117+
// })
118+
119+
// It("checks VMIPs phases", func() {
120+
// By(fmt.Sprintf("VMIPs should be in %s phases", PhaseAttached))
121+
// WaitPhaseByLabel(kc.ResourceVMIP, PhaseAttached, kc.WaitOptions{
122+
// Labels: testCaseLabel,
123+
// Namespace: ns,
124+
// Timeout: MaxWaitTimeout,
125+
// })
126+
// })
127+
// })
127128

128129
Context("When virtual disks are applied", func() {
129130
It("checks VDs phases with consumers", func() {

test/e2e/legacy/testdata/complex-test/vm/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resources:
44
- overlays/default
55
- overlays/always-on
66
- overlays/embedded-cloudinit
7-
- overlays/custom-ip
7+
# - overlays/custom-ip
88
- overlays/automatic
99
- overlays/vm-a-not-b
1010
- overlays/vm-b-not-a

0 commit comments

Comments
 (0)