Skip to content

Commit

Permalink
Merge pull request #10 from dougbtv/allow-empty-spec
Browse files Browse the repository at this point in the history
Bug 1743496: Allows empty spec.config
  • Loading branch information
openshift-merge-robot committed Aug 22, 2019
2 parents bd61f98 + 27c5cf3 commit ccd6c61
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,28 @@ func validateNetworkAttachmentDefinition(netAttachDef types.NetworkAttachmentDef
return false, err
}

if netAttachDef.Spec.Config == "" {
err := errors.New("network config is empty")
glog.Info(err)
return false, err
}

glog.Infof("validating network config spec: %s", netAttachDef.Spec.Config)

/* try to unmarshal config into NetworkConfig or NetworkConfigList
using actual code from libcni - if succesful, it means that the config
will be accepted by CNI itself as well */
confBytes := []byte(netAttachDef.Spec.Config)
_, err = libcni.ConfListFromBytes(confBytes)
if err != nil {
glog.Infof("spec is not a valid network config list: %s - trying to parse into standalone config", err)
_, err = libcni.ConfFromBytes(confBytes)
var confBytes []byte
if netAttachDef.Spec.Config != "" {

// try to unmarshal config into NetworkConfig or NetworkConfigList
// using actual code from libcni - if succesful, it means that the config
// will be accepted by CNI itself as well
confBytes = []byte(netAttachDef.Spec.Config)
_, err = libcni.ConfListFromBytes(confBytes)
if err != nil {
glog.Infof("spec is not a valid network config: %s", confBytes)
err := errors.Wrap(err, "invalid config")
return false, err
glog.Infof("spec is not a valid network config list: %s - trying to parse into standalone config", err)
_, err = libcni.ConfFromBytes(confBytes)
if err != nil {
glog.Infof("spec is not a valid network config: %s", confBytes)
err := errors.Wrap(err, "invalid config")
return false, err
}
}

} else {
glog.Infof("Allowing empty spec.config")
}

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

0 comments on commit ccd6c61

Please sign in to comment.