From a4d9e3c0f9fecdf5678beef11f465d15344e6859 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 28 Sep 2016 00:14:36 -0400 Subject: [PATCH] Better messaging during IAM replication --- .../cloudup/awstasks/launchconfiguration.go | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/upup/pkg/fi/cloudup/awstasks/launchconfiguration.go b/upup/pkg/fi/cloudup/awstasks/launchconfiguration.go index d60441541f4b6..4ec4075fb9cfb 100644 --- a/upup/pkg/fi/cloudup/awstasks/launchconfiguration.go +++ b/upup/pkg/fi/cloudup/awstasks/launchconfiguration.go @@ -11,6 +11,7 @@ import ( "k8s.io/kops/upup/pkg/fi/cloudup/awsup" "k8s.io/kops/upup/pkg/fi/cloudup/terraform" "strings" + "time" ) //go:generate fitask -type=LaunchConfiguration @@ -255,18 +256,32 @@ func (_ *LaunchConfiguration) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *La request.IamInstanceProfile = e.IAMInstanceProfile.Name } - _, err = t.Cloud.Autoscaling().CreateLaunchConfiguration(request) + maxAttempts := 6 + attempt := 0 + for { + attempt++ + _, err = t.Cloud.Autoscaling().CreateLaunchConfiguration(request) + + if err == nil { + break + } - if err != nil { if awsup.AWSErrorCode(err) == "ValidationError" { message := awsup.AWSErrorMessage(err) if strings.Contains(message, "not authorized") || strings.Contains(message, "Invalid IamInstance") { - // IAM instance profile creation is notoriously async - return fmt.Errorf("IAM instance profile not yet created/propagated") + if attempt == maxAttempts { + // IAM instance profile creation is notoriously async + return fmt.Errorf("IAM instance profile not yet created/propagated") + } else { + glog.Infof("Waiting for IAM to replicate") + glog.V(2).Infof("IAM error was %v", err) + time.Sleep(10 * time.Second) + continue + } } + glog.V(4).Infof("ErrorCode=%q, Message=%q", awsup.AWSErrorCode(err), awsup.AWSErrorMessage(err)) + return fmt.Errorf("error creating AutoscalingLaunchConfiguration: %v", err) } - glog.V(4).Infof("ErrorCode=%q, Message=%q", awsup.AWSErrorCode(err), awsup.AWSErrorMessage(err)) - return fmt.Errorf("error creating AutoscalingLaunchConfiguration: %v", err) } e.ID = fi.String(launchConfigurationName)