Skip to content

Commit 083b6c2

Browse files
committed
fix(webhook): return err when the ns label on nad is missing
Signed-off-by: Zespre Chang <[email protected]> (cherry picked from commit 54275d2)
1 parent 3343f5e commit 083b6c2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/webhook/vmnetcfg/validator.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ func (v *Validator) Create(request *admission.Request, newObj runtime.Object) er
4545
}
4646
ipPoolNamespace, ok := nad.Labels[util.IPPoolNamespaceLabelKey]
4747
if !ok {
48-
ipPoolNamespace = nadNamespace
48+
return fmt.Errorf(
49+
webhook.CreateErr,
50+
vmNetCfg.Kind,
51+
vmNetCfg.Namespace,
52+
vmNetCfg.Name,
53+
fmt.Errorf("%s label not found", util.IPPoolNamespaceLabelKey),
54+
)
4955
}
5056
ipPoolName, ok := nad.Labels[util.IPPoolNameLabelKey]
5157
if !ok {

pkg/webhook/vmnetcfg/validator_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ func TestValidator_Create(t *testing.T) {
121121
shouldErr: true,
122122
},
123123
},
124+
{
125+
name: "nad referenced has incomplete labels set to associate with the target ippool",
126+
given: input{
127+
vmNetCfg: newTestVirtualMachineNetworkConfigBuilder().
128+
WithNetworkConfig("", "", testNetworkName).Build(),
129+
ipPool: newTestIPPoolBuilder().Build(),
130+
nad: newTestNetworkAttachmentDefinitionBuilder().
131+
Label(util.IPPoolNameLabelKey, testIPPoolName).Build(),
132+
},
133+
expected: output{
134+
shouldErr: true,
135+
},
136+
},
124137
}
125138

126139
nadGVR := schema.GroupVersionResource{

0 commit comments

Comments
 (0)