Repository: keikoproj/instance-manager
Pull request #143 (2020-07-01 22:24:45)

Added sleep after attach and ensured profile name does not start with…
… 'eks'

codecov[bot]: # [Codecov](https://codecov.io/gh/keikoproj/instance-manager/pull/143?src=pr&el=h1) Report
> Merging [#143](https://codecov.io/gh/keikoproj/instance-manager/pull/143?src=pr&el=desc) into [master](https://codecov.io/gh/keikoproj/instance-manager/commit/7d6df4534ce82d2e6151776fc3aa1a69470d336f&el=desc) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/keikoproj/instance-manager/pull/143/graphs/tree.svg?width=650&height=150&src=pr&token=IJbjmSBliL)](https://codecov.io/gh/keikoproj/instance-manager/pull/143?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #143   +/-   ##
=======================================
  Coverage   89.51%   89.51%           
=======================================
  Files          12       12           
  Lines        1469     1469           
=======================================
  Hits         1315     1315           
  Misses        105      105           
  Partials       49       49           
```


| [Impacted Files](https://codecov.io/gh/keikoproj/instance-manager/pull/143?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [controllers/provisioners/eksfargate/eksfargate.go](https://codecov.io/gh/keikoproj/instance-manager/pull/143/diff?src=pr&el=tree#diff-Y29udHJvbGxlcnMvcHJvdmlzaW9uZXJzL2Vrc2ZhcmdhdGUvZWtzZmFyZ2F0ZS5nbw==) | `94.21% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/keikoproj/instance-manager/pull/143?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/keikoproj/instance-manager/pull/143?src=pr&el=footer). Last update [7d6df45...d96e289](https://codecov.io/gh/keikoproj/instance-manager/pull/143?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/Makefile b/Makefile
index 8c226ab..bf7c82c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,18 @@
 export GO111MODULE=on
 
+CONTROLLER_GEN_VERSION := v0.2.9
 GO_MIN_VERSION := 11100 # go1.11
+
+define generate_int_from_semver
+  echo $(1) |cut -dv -f2 |awk '{split($$0,a,"."); print  a[3]+(100*a[2])+(10000* a[1])}'
+endef
+
+CONTROLLER_GEN_VERSION_CHECK = \
+  $(shell expr \
+    $(shell $(call generate_int_from_semver,$(shell $(CONTROLLER_GEN) --version | awk '{print $$2}' | cut -dv -f2))) \
+    \>= $(shell $(call generate_int_from_semver,$(shell echo $(CONTROLLER_GEN_VERSION) | cut -dv -f2))) \
+  )
+
 GO_VERSION_CHECK := \
   $(shell expr \
     $(shell go version | \
@@ -97,12 +109,22 @@ docker-build:
 docker-push:
 	docker push ${IMG}
 
+.PHONY: check-controller-gen
+check-controller-gen:
+	@if [ $(CONTROLLER_GEN_VERSION_CHECK) -eq 0 ]; then \
+	    echo "Need to upgrade controller-gen to $(CONTROLLER_GEN_VERSION) or higher"; \
+	    exit 1; \
+	fi
+
 # find or download controller-gen
 # download controller-gen if necessary
 .PHONY: controller-gen
-controller-gen:
+controller-gen: controller-gen-find check-controller-gen
+
+.PHONY: controller-gen-real
+controller-gen-find: 
 ifeq (, $(shell which controller-gen))
-	go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.9
+	go get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
 CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
 else
 CONTROLLER_GEN=$(shell which controller-gen)
@@ -128,4 +150,4 @@ vendor:
 
 .PHONY: clean
 clean:
-	@rm -rf ./bin	
+	@rm -rf ./bin
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index 020ecd0..11ff037 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -21,7 +21,7 @@ package v1alpha1
 
 import (
 	"k8s.io/api/core/v1"
-	runtime "k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/runtime"
 	"k8s.io/apimachinery/pkg/util/intstr"
 )
 
diff --git a/controllers/providers/aws/aws.go b/controllers/providers/aws/aws.go
index 3361c1f..1a2f4b8 100644
--- a/controllers/providers/aws/aws.go
+++ b/controllers/providers/aws/aws.go
@@ -892,6 +892,9 @@ func (w *AwsWorker) AttachDefaultPolicyToDefaultRole() error {
 		RoleName:  aws.String(roleName),
 	}
 	_, err := w.IamClient.AttachRolePolicy(rolePolicy)
+	if err == nil {
+		time.Sleep(DefaultInstanceProfilePropagationDelay)
+	}
 	return err
 }
 
diff --git a/controllers/provisioners/eksfargate/eksfargate.go b/controllers/provisioners/eksfargate/eksfargate.go
index d46d252..ad9be11 100644
--- a/controllers/provisioners/eksfargate/eksfargate.go
+++ b/controllers/provisioners/eksfargate/eksfargate.go
@@ -85,7 +85,7 @@ func (ctx *FargateInstanceGroupContext) generateUniqueName() string {
 	instanceGroup := ctx.GetInstanceGroup()
 	spec := instanceGroup.GetEKSFargateSpec()
 	name := fmt.Sprintf("%v-%v-%v", spec.GetClusterName(), instanceGroup.GetNamespace(), instanceGroup.GetName())
-	return fmt.Sprintf("%v-%v", spec.GetClusterName(), hash(name))
+	return fmt.Sprintf("fargate-%v-%v", spec.GetClusterName(), hash(name))
 
 }
 
diff --git a/go.sum b/go.sum
index d7a21e7..ca8b8bf 100644
--- a/go.sum
+++ b/go.sum
@@ -73,6 +73,7 @@ github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT
 github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
 github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
 github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
+github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
 github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
 github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -198,6 +199,7 @@ github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
 github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
 github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
 github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
+github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
 github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
 github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
@@ -315,6 +317,7 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
 github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
 github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
 github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
+github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
 github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
 github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@@ -461,6 +464,7 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn
 golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
+golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72 h1:bw9doJza/SFBEweII/rHQh338oozWyiFsBRHtrflcws=
 golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=


Test patch:
diff --git a/controllers/provisioners/eksfargate/eksfargate_test.go b/controllers/provisioners/eksfargate/eksfargate_test.go
index c0fc878..b39c9cb 100644
--- a/controllers/provisioners/eksfargate/eksfargate_test.go
+++ b/controllers/provisioners/eksfargate/eksfargate_test.go
@@ -243,6 +243,10 @@ func (f *FakeIG) getInstanceGroup() *v1alpha1.InstanceGroup {
 	return instanceGroup
 }
 func (u *EksFargateUnitTest) BuildProvisioner(t *testing.T) *FargateInstanceGroupContext {
+
+	// Speeds up sleep in the AttachRolePolicy logic
+	awsprovider.DefaultInstanceProfilePropagationDelay = time.Millisecond * 1
+
 	aws := &awsprovider.AwsWorker{
 		EksClient: &stubEKS{
 			ProfileBasic:            u.ProfileBasic,
@@ -935,7 +939,7 @@ func TestCreateProfileName(t *testing.T) {
 	}
 	ctx := testCase.BuildProvisioner(t)
 	profileName := ctx.generateUniqueName()
-	if profileName != "TestNameCluster-13281223259712081633" {
+	if profileName != "fargate-TestNameCluster-13281223259712081633" {
 		t.Fatalf("TestCreateProfileName: profile name is %v.", profileName)
 	}
 }