private OsUpgrader chooseUpgrader(NodeType nodeType, Optional<Version> target) {
        if (cloud.dynamicProvisioning()) {
            boolean canRebuild = cloud.name().equals(CloudName.AWS);
            boolean canSnapshot = snapshotsEnabled.value();
            if (canRebuild) {
                if (canSnapshot) {
                    // When snapshots are supported, we can rebuild any host
                    return new RebuildingOsUpgrader(nodeRepository, true, false);
                } else {
                    // Otherwise we need a combination of rebuilding (remote disks) and retiring (local disks)
                    return new CompositeOsUpgrader(nodeRepository,
                                                   List.of(new RebuildingOsUpgrader(nodeRepository, true, true),
                                                           new RetiringOsUpgrader(nodeRepository, true)));
                }
            }
            // Rebuild unsupported. Retire hosts regardless of storage type
            return new RetiringOsUpgrader(nodeRepository, false);
        }
        // Require rebuild if we have any nodes of this type on a major version lower than target
        boolean rebuildRequired = target.isPresent() &&
                                  nodeRepository.nodes().list(Node.State.active).nodeType(nodeType).stream()
                                                .map(Node::status)
                                                .map(Status::osVersion)
                                                .anyMatch(osVersion -> osVersion.current().isPresent() &&
                                                                       osVersion.current().get().getMajor() < target.get().getMajor());
        if (rebuildRequired) {
            return new RebuildingOsUpgrader(nodeRepository, false, false);
        }
        return new DelegatingOsUpgrader(nodeRepository);
    }
Returns the upgrader to use when upgrading given node type to target
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/os/OsVersions.java