URL template. Must include {x}, {y} or {-y}, and {z} placeholders. A {?-?} template pattern, for example subdomain {a-f} .domain.com, may be used instead of defining each one separately in the urls option.
This explain why subdomain template is not working
As per example on https://cartodb.com/basemaps/ subdomain template is
{s}
and url needs to be specified as -url: 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png'
But as per openlayer3 docs http://openlayers.org/en/v3.8.2/apidoc/ol.source.XYZ.html
This explain why subdomain template is not working