func SetupInstanceID()

in setup.go [20:45]


func SetupInstanceID(c *ec2macosinit.InitConfig) (err error) {
	var attempt int
	// While instance ID is empty
	for c.IMDS.InstanceID == "" {
		// Attempt to get the instance ID
		err = c.IMDS.UpdateInstanceID()
		if err != nil {
			// Fail out if attempts exceeds maximum
			if attempt > setupMaxAttempts {
				return fmt.Errorf("error getting instance ID from IMDS: %s\n", err)
			}

			// Log according to the log interval
			if math.Mod(float64(attempt), logInterval) == 0.0 {
				c.Log.Warnf("Unable to get instance ID - IMDS may not be available yet...retrying every %ds [%d/%d]", attemptInterval, attempt, setupMaxAttempts)
			}

			attempt++ // increment attempts

			// Sleep for attempt interval
			time.Sleep(attemptInterval * time.Second)
		}
	}

	return nil
}