Repository: keikoproj/instance-manager
Pull request #152 (2020-07-29 20:16:05)

adding lifecycle node label
This will help to restrict daemonset/pod using node label selector

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

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

```diff
@@            Coverage Diff             @@
##           master     #152      +/-   ##
==========================================
+ Coverage   89.22%   89.25%   +0.02%     
==========================================
  Files          13       13              
  Lines        1559     1563       +4     
==========================================
+ Hits         1391     1395       +4     
  Misses        111      111              
  Partials       57       57              
```


| [Impacted Files](https://codecov.io/gh/keikoproj/instance-manager/pull/152?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [controllers/provisioners/eks/eks.go](https://codecov.io/gh/keikoproj/instance-manager/pull/152/diff?src=pr&el=tree#diff-Y29udHJvbGxlcnMvcHJvdmlzaW9uZXJzL2Vrcy9la3MuZ28=) | `88.23% <ø> (ø)` | |
| [controllers/provisioners/eks/helpers.go](https://codecov.io/gh/keikoproj/instance-manager/pull/152/diff?src=pr&el=tree#diff-Y29udHJvbGxlcnMvcHJvdmlzaW9uZXJzL2Vrcy9oZWxwZXJzLmdv) | `89.00% <100.00%> (+0.11%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/keikoproj/instance-manager/pull/152?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/152?src=pr&el=footer). Last update [ebba4c2...ad67b0d](https://codecov.io/gh/keikoproj/instance-manager/pull/152?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/controllers/provisioners/eks/eks.go b/controllers/provisioners/eks/eks.go
index 6d09914..bec2b6b 100644
--- a/controllers/provisioners/eks/eks.go
+++ b/controllers/provisioners/eks/eks.go
@@ -34,8 +34,9 @@ const (
 )
 
 var (
-	RoleNewLabelFmt = "node.kubernetes.io/role=%s"
-	RoleOldLabelFmt = "node-role.kubernetes.io/%s=\"\""
+	RoleNewLabelFmt     = "node.kubernetes.io/role=%s"
+	RoleOldLabelFmt     = "node-role.kubernetes.io/%s=\"\""
+	InstanceMgrLabelFmt = "instancemgr.keikoproj.io/%s=%s"
 
 	DefaultManagedPolicies = []string{"AmazonEKSWorkerNodePolicy", "AmazonEKS_CNI_Policy", "AmazonEC2ContainerRegistryReadOnly"}
 )
diff --git a/controllers/provisioners/eks/helpers.go b/controllers/provisioners/eks/helpers.go
index f6733f8..ba657c4 100644
--- a/controllers/provisioners/eks/helpers.go
+++ b/controllers/provisioners/eks/helpers.go
@@ -244,6 +244,12 @@ func (ctx *EksInstanceGroupContext) GetLabelList() []string {
 		}
 	}
 
+	if configuration.GetSpotPrice() == "" {
+		labelList = append(labelList, fmt.Sprintf(InstanceMgrLabelFmt, "lifecycle", v1alpha1.LifecycleStateNormal))
+	} else {
+		labelList = append(labelList, fmt.Sprintf(InstanceMgrLabelFmt, "lifecycle", v1alpha1.LifecycleStateSpot))
+	}
+
 	sort.Strings(labelList)
 	return labelList
 }


Test patch:
diff --git a/controllers/provisioners/eks/helpers_test.go b/controllers/provisioners/eks/helpers_test.go
index 8af29e0..76e768f 100644
--- a/controllers/provisioners/eks/helpers_test.go
+++ b/controllers/provisioners/eks/helpers_test.go
@@ -16,6 +16,7 @@ limitations under the License.
 package eks
 
 import (
+	"sort"
 	"testing"
 
 	"github.com/aws/aws-sdk-go/aws"
@@ -144,6 +145,8 @@ func TestGetLabelList(t *testing.T) {
 		expectedLabelsWithCustom   = []string{"custom.kubernetes.io=customlabel", "node.kubernetes.io/role=instance-group-1"}
 		expectedLabelsWithOverride = []string{"custom.kubernetes.io=customlabel", "override.kubernetes.io=instance-group-1", "override2.kubernetes.io=instance-group-1"}
 		overrideAnnotation         = map[string]string{OverrideDefaultLabelsAnnotationKey: "override.kubernetes.io=instance-group-1,override2.kubernetes.io=instance-group-1"}
+		expectedSpotLable          = []string{"instancemgr.keikoproj.io/lifecycle=spot", "node-role.kubernetes.io/instance-group-1=\"\"", "node.kubernetes.io/role=instance-group-1"}
+		defaultLifecycleLable      = "instancemgr.keikoproj.io/lifecycle=normal"
 	)
 
 	w := MockAwsWorker(asgMock, iamMock, eksMock)
@@ -154,7 +157,9 @@ func TestGetLabelList(t *testing.T) {
 		instanceGroupLabels      map[string]string
 		instanceGroupAnnotations map[string]string
 		expectedLabels           []string
+		spotPrice                string
 	}{
+		{clusterVersion: "", spotPrice: "0.7773", expectedLabels: expectedSpotLable},
 		// Default labels with missing cluster version
 		{clusterVersion: "", expectedLabels: expectedLabels115},
 		// Kubernetes 1.15 default labels
@@ -171,6 +176,7 @@ func TestGetLabelList(t *testing.T) {
 		t.Logf("Test #%v - %+v", i, tc)
 		configuration.SetLabels(tc.instanceGroupLabels)
 		ig.SetAnnotations(tc.instanceGroupAnnotations)
+		configuration.SetSpotPrice(tc.spotPrice)
 		ctx.SetDiscoveredState(&DiscoveredState{
 			Publisher: kubeprovider.EventPublisher{
 				Client: k.Kubernetes,
@@ -179,7 +185,10 @@ func TestGetLabelList(t *testing.T) {
 				Version: aws.String(tc.clusterVersion),
 			},
 		})
-
+		if tc.spotPrice == "" {
+			tc.expectedLabels = append(tc.expectedLabels, defaultLifecycleLable)
+		}
+		sort.Strings(tc.expectedLabels)
 		labels := ctx.GetLabelList()
 		g.Expect(labels).To(gomega.Equal(tc.expectedLabels))
 	}