public DockerImage get(Node node) {
        Optional<DockerImage> requestedImage = node.allocation()
                                                   .flatMap(allocation -> allocation.membership().cluster().dockerImageRepo());
        NodeType nodeType = node.type().isHost() ? node.type().childNodeType() : node.type();
        DockerImage wantedImage =
                nodeType != NodeType.tenant ?
                        defaultImage :
                node.resources().gpuResources().isZero() ?
                        tenantImage.orElse(defaultImage) :
                        tenantGpuImage.orElseThrow(() -> new IllegalArgumentException(node + " has GPU resources, but there is no GPU container image available"));

        return requestedImage
                // Rewrite requested images to make sure they come from a trusted registry
                .map(image -> image.withRegistry(wantedImage.registry()))
                .orElse(wantedImage);
    }
@Test
    public void image_selection() {
        DockerImage defaultImage = DockerImage.fromString("different.example.com/vespa/default");
        DockerImage tenantImage = DockerImage.fromString("registry.example.com/vespa/tenant");
        DockerImage gpuImage = DockerImage.fromString("registry.example.com/vespa/tenant-gpu");
        ContainerImages images = new ContainerImages(defaultImage, Optional.of(tenantImage), Optional.of(gpuImage));

        assertEquals(defaultImage, images.get(node(NodeType.confighost)));  // For preload purposes
        assertEquals(defaultImage, images.get(node(NodeType.config)));

        assertEquals(tenantImage, images.get(node(NodeType.host))); // For preload purposes
        assertEquals(tenantImage, images.get(node(NodeType.tenant)));

        assertEquals(defaultImage, images.get(node(NodeType.proxyhost))); // For preload purposes
        assertEquals(defaultImage, images.get(node(NodeType.proxy)));

        // Choose GPU when node has GPU resources
        assertEquals(gpuImage, images.get(node(NodeType.tenant, null, true)));

        // Tenant node requesting a special image
        DockerImage requested = DockerImage.fromString("registry.example.com/vespa/special");
        assertEquals(requested, images.get(node(NodeType.tenant, requested)));

        // Malicious registry is rewritten to the trusted one
        DockerImage malicious = DockerImage.fromString("malicious.example.com/vespa/special");
        assertEquals(requested, images.get(node(NodeType.tenant, malicious)));

        // Requested image registry for config is rewritten to the defaultImage registry
        assertEquals(DockerImage.fromString("different.example.com/vespa/special"), images.get(node(NodeType.config, requested)));

        // When there is no custom tenant image, the default one is used
        images = new ContainerImages(defaultImage, Optional.empty(), Optional.of(gpuImage));
        assertEquals(defaultImage, images.get(node(NodeType.host)));
        assertEquals(defaultImage, images.get(node(NodeType.tenant)));
    }