Skip to content

Commit ab74a26

Browse files
dougbtvs1061123
authored andcommitted
[validation] Allows empty spec.config
1 parent 46f6733 commit ab74a26

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

pkg/webhook/webhook.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,28 @@ func validateNetworkAttachmentDefinition(netAttachDef types.NetworkAttachmentDef
6666
return false, err
6767
}
6868

69-
if netAttachDef.Spec.Config == "" {
70-
err := errors.New("network config is empty")
71-
glog.Info(err)
72-
return false, err
73-
}
74-
7569
glog.Infof("validating network config spec: %s", netAttachDef.Spec.Config)
7670

77-
/* try to unmarshal config into NetworkConfig or NetworkConfigList
78-
using actual code from libcni - if succesful, it means that the config
79-
will be accepted by CNI itself as well */
80-
confBytes := []byte(netAttachDef.Spec.Config)
81-
_, err = libcni.ConfListFromBytes(confBytes)
82-
if err != nil {
83-
glog.Infof("spec is not a valid network config list: %s - trying to parse into standalone config", err)
84-
_, err = libcni.ConfFromBytes(confBytes)
71+
var confBytes []byte
72+
if netAttachDef.Spec.Config != "" {
73+
74+
// try to unmarshal config into NetworkConfig or NetworkConfigList
75+
// using actual code from libcni - if succesful, it means that the config
76+
// will be accepted by CNI itself as well
77+
confBytes = []byte(netAttachDef.Spec.Config)
78+
_, err = libcni.ConfListFromBytes(confBytes)
8579
if err != nil {
86-
glog.Infof("spec is not a valid network config: %s", confBytes)
87-
err := errors.Wrap(err, "invalid config")
88-
return false, err
80+
glog.Infof("spec is not a valid network config list: %s - trying to parse into standalone config", err)
81+
_, err = libcni.ConfFromBytes(confBytes)
82+
if err != nil {
83+
glog.Infof("spec is not a valid network config: %s", confBytes)
84+
err := errors.Wrap(err, "invalid config")
85+
return false, err
86+
}
8987
}
88+
89+
} else {
90+
glog.Infof("Allowing empty spec.config")
9091
}
9192

9293
glog.Infof("AdmissionReview request allowed: Network Attachment Definition '%s' is valid", confBytes)

0 commit comments

Comments
 (0)