<!--
GitHub is reserved for bug reports and feature requests; it is not the place
for general questions. If you have a question or an unconfirmed bug , please
visit the [forums](https://discuss.elastic.co/c/elasticsearch).  Please also
check your OS is [supported](https://www.elastic.co/support/matrix#show_os).
If it is not, the issue is likely to be closed.

For security vulnerabilities please only send reports to security@elastic.co.
See https://www.elastic.co/community/security for more information.

Please fill in the following details to help us reproduce the bug:
-->

**Elasticsearch version** (`bin/elasticsearch --version`): `7.14.2`

**Plugins installed**: []

**JVM version** (`java -version`): ESS

**OS version** (`uname -a` if on a Unix-like system): ESS

**Description of the problem including expected versus actual behavior**:

The `shrink` ILM phase failed when trying to apply to an index with a single primary shard and a phase definition that utilises the `max_primary_shard_size` option.

Exception recorded:
```
java.lang.IllegalArgumentException: can't shrink an index with only one shard
	at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.validateShrinkIndex(MetadataCreateIndexService.java:1147)
	at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.prepareResizeIndexSettings(MetadataCreateIndexService.java:1233)
	at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.aggregateIndexSettings(MetadataCreateIndexService.java:809)
	at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.applyCreateIndexRequestWithExistingMetadata(MetadataCreateIndexService.java:631)
	at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.applyCreateIndexRequest(MetadataCreateIndexService.java:334)
	at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.applyCreateIndexRequest(MetadataCreateIndexService.java:377)
	at org.elasticsearch.cluster.metadata.MetadataCreateIndexService$1.execute(MetadataCreateIndexService.java:294)
	at org.elasticsearch.cluster.ClusterStateUpdateTask.execute(ClusterStateUpdateTask.java:48)
	at org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:691)
	at org.elasticsearch.cluster.service.MasterService.calculateTaskOutputs(MasterService.java:313)
	at org.elasticsearch.cluster.service.MasterService.runTasks(MasterService.java:208)
	at org.elasticsearch.cluster.service.MasterService.access$000(MasterService.java:62)
	at org.elasticsearch.cluster.service.MasterService$Batcher.run(MasterService.java:140)
	at org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:139)
	at org.elasticsearch.cluster.service.TaskBatcher$BatchedTask.run(TaskBatcher.java:177)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:673)
	at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:241)
	at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:204)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:831)
```

**Steps to reproduce**:

Please include a *minimal* but *complete* recreation of the problem,
including (e.g.) index creation, mappings, settings, query etc.  The easier
you make for us to reproduce it, the more likely that somebody will take the
time to look at it.

 1. Create an index with a single primary shard.
 2. Define an ILM policy with the following `warm` phase:
  ```json
{
  "policy": "metricbeat",
  "phase_definition": {
    "min_age": "0d",
    "actions": {
      "allocate": {
        "number_of_replicas": 1,
        "include": {},
        "exclude": {},
        "require": {}
      },
      "forcemerge": {
        "max_num_segments": 1
      },
      "set_priority": {
        "priority": 25
      },
      "shrink": {
        "max_primary_shard_size": "50gb"
      }
    }
  },
  "version": 18,
  "modified_date_in_millis": 1635781185067
}
  ```
 3. Associate ILM policy with index
 4. Trigger rollover of index.

**Provide logs (if relevant)**:

Related: #33275

server/src/test/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeActionTests.java
ResizeRequest target = new ResizeRequest("target", indexName);
        final ActiveShardCount activeShardCount = randomBoolean() ? ActiveShardCount.ALL : ActiveShardCount.ONE;
        target.setWaitForActiveShards(activeShardCount);
        CreateIndexClusterStateUpdateRequest request = TransportResizeAction.prepareCreateIndexRequest(
            target,
            clusterState.metadata().index(indexName),
            new StoreStats(between(1, 100), between(0, 100), between(1, 100)),
            (i) -> stats,
            "target"
        );
        assertNotNull(request.recoverFrom());
        assertEquals(indexName, request.recoverFrom().getName());
        assertEquals("1", request.settings().get("index.number_of_shards"));
        assertEquals("shrink_index", request.cause());
        assertEquals(request.waitForActiveShards(), activeShardCount);
    }
    public void testCalculateTargetShardsNum() {
        assertEquals(TransportResizeAction.calTargetShardsNum(0, 0), 1);
        assertEquals(TransportResizeAction.calTargetShardsNum(10, 0), 1);
        assertEquals(TransportResizeAction.calTargetShardsNum(10, 1), 1);
        assertEquals(TransportResizeAction.calTargetShardsNum(10, 2), 2);
        assertEquals(TransportResizeAction.calTargetShardsNum(10, 3), 5);
        assertEquals(TransportResizeAction.calTargetShardsNum(10, 6), 10);
        assertEquals(TransportResizeAction.calTargetShardsNum(10, 11), 10);
        assertEquals(TransportResizeAction.calTargetShardsNum(59, 21), 59);
        assertEquals(TransportResizeAction.calTargetShardsNum(60, 21), 30);
        assertEquals(TransportResizeAction.calTargetShardsNum(60, 31), 60);
    }
    public void testShrinkWithMaxPrimaryShardSize() {
        int sourceIndexShardsNum = randomIntBetween(2, 42);