func()

in updater/aws.go [100:136]


func (u *updater) filterBottlerocketInstances(instances []*string) ([]instance, error) {
	log.Printf("Filtering container instances running Bottlerocket OS")
	bottlerocketInstances := make([]instance, 0)
	errCount := 0
	var lastErr error
	pageCount, err := eachPage(len(instances), ecsPageSize, func(start, stop int) error {
		resp, err := u.ecs.DescribeContainerInstances(&ecs.DescribeContainerInstancesInput{
			Cluster:            &u.cluster,
			ContainerInstances: instances[start:stop],
		})
		// count errors per page.
		if err != nil {
			log.Printf("Failed to describe container instances from %d to %d: %v", start, stop, err)
			errCount++
			lastErr = err
			return nil
		}
		for _, containerInstance := range resp.ContainerInstances {
			if containsAttribute(containerInstance.Attributes, "bottlerocket.variant") {
				bottlerocketInstances = append(bottlerocketInstances, instance{
					instanceID:          aws.StringValue(containerInstance.Ec2InstanceId),
					containerInstanceID: aws.StringValue(containerInstance.ContainerInstanceArn),
				})
				log.Printf("Bottlerocket instance %q detected.", aws.StringValue(containerInstance.Ec2InstanceId))
			}
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	// check if every page had an error; errors are only fatal if each page failed.
	if errCount == pageCount {
		return nil, fmt.Errorf("failed to describe any container instances: %w", lastErr)
	}
	return bottlerocketInstances, nil
}