Skip to content

Commit

Permalink
feat: add image default label to nodes (#270)
Browse files Browse the repository at this point in the history
* add image lbl

Signed-off-by: Eytan Avisror <[email protected]>

* fix var name

Signed-off-by: Eytan Avisror <[email protected]>
  • Loading branch information
eytan-avisror authored Apr 7, 2021
1 parent 6577998 commit c0eb25d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/instancegroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@ func (h LifecycleHookSpec) ExistInSlice(hooks []LifecycleHookSpec) bool {
}
return false
}
func (c *EKSConfiguration) GetImage() string {
return c.Image
}
func (c *EKSConfiguration) GetInstanceProfileName() string {
return c.ExistingInstanceProfileName
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/provisioners/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
RoleOldLabel = "node-role.kubernetes.io/%s"
RoleOldLabelFmt = "node-role.kubernetes.io/%s=\"\""
InstanceMgrLifecycleLabel = "instancemgr.keikoproj.io/lifecycle"
InstanceMgrLabelFmt = "instancemgr.keikoproj.io/%s=%s"
InstanceMgrImageLabel = "instancemgr.keikoproj.io/image"

DefaultManagedPolicies = []string{"AmazonEKSWorkerNodePolicy", "AmazonEC2ContainerRegistryReadOnly"}
CNIManagedPolicy = "AmazonEKS_CNI_Policy"
Expand Down
1 change: 1 addition & 0 deletions controllers/provisioners/eks/eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func MockInstanceGroup() *v1alpha1.InstanceGroup {
MaxSize: 3,
MinSize: 1,
EKSConfiguration: &v1alpha1.EKSConfiguration{
Image: "ami-123456789012",
EksClusterName: "my-cluster",
InstanceType: "m5.large",
SuspendedProcesses: []string{
Expand Down
2 changes: 2 additions & 0 deletions controllers/provisioners/eks/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ func (ctx *EksInstanceGroupContext) GetComputedLabels() map[string]string {
labelMap[InstanceMgrLifecycleLabel] = v1alpha1.LifecycleStateMixed
}

labelMap[InstanceMgrImageLabel] = configuration.GetImage()

return labelMap
}

Expand Down
15 changes: 8 additions & 7 deletions controllers/provisioners/eks/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mkdir /mnt/foo
mount /dev/xvda /mnt/foo
mount
set -o xtrace
/etc/eks/bootstrap.sh foo --use-max-pods false --kubelet-extra-args '--node-labels=foo=bar,node.kubernetes.io/role=instance-group-1 --register-with-taints=foo=bar:NoSchedule --eviction-hard=memory.available<300Mi,nodefs.available<5% --system-reserved=memory=2.5Gi --v=2 --max-pods=4'
/etc/eks/bootstrap.sh foo --use-max-pods false --kubelet-extra-args '--node-labels=foo=bar,instancemgr.keikoproj.io/image=ami-123456789012,node.kubernetes.io/role=instance-group-1 --register-with-taints=foo=bar:NoSchedule --eviction-hard=memory.available<300Mi,nodefs.available<5% --system-reserved=memory=2.5Gi --v=2 --max-pods=4'
set +o xtrace
bar`
userData := ctx.GetBasicUserData("foo", args, kubeletArgs, userDataPayload, mounts)
Expand Down Expand Up @@ -447,13 +447,14 @@ func TestGetLabelList(t *testing.T) {
eksMock = NewEksMocker()
ec2Mock = NewEc2Mocker()
defaultLifecycleLabel = "instancemgr.keikoproj.io/lifecycle=normal"
expectedLabels115 = []string{defaultLifecycleLabel, "node-role.kubernetes.io/instance-group-1=\"\"", "node.kubernetes.io/role=instance-group-1"}
expectedLabels116 = []string{defaultLifecycleLabel, "node.kubernetes.io/role=instance-group-1"}
expectedLabelsWithCustom = []string{defaultLifecycleLabel, "custom.kubernetes.io=customlabel", "node.kubernetes.io/role=instance-group-1"}
expectedLabelsWithOverride = []string{defaultLifecycleLabel, "custom.kubernetes.io=customlabel", "override.kubernetes.io=instance-group-1", "override2.kubernetes.io=instance-group-1"}
defaultImageLabel = fmt.Sprintf("instancemgr.keikoproj.io/image=%v", configuration.GetImage())
expectedLabels115 = []string{defaultImageLabel, defaultLifecycleLabel, "node-role.kubernetes.io/instance-group-1=\"\"", "node.kubernetes.io/role=instance-group-1"}
expectedLabels116 = []string{defaultImageLabel, defaultLifecycleLabel, "node.kubernetes.io/role=instance-group-1"}
expectedLabelsWithCustom = []string{defaultImageLabel, defaultLifecycleLabel, "custom.kubernetes.io=customlabel", "node.kubernetes.io/role=instance-group-1"}
expectedLabelsWithOverride = []string{defaultImageLabel, defaultLifecycleLabel, "custom.kubernetes.io=customlabel", "override.kubernetes.io=instance-group-1", "override2.kubernetes.io=instance-group-1"}
overrideAnnotation = map[string]string{OverrideDefaultLabelsAnnotation: "override.kubernetes.io=instance-group-1,override2.kubernetes.io=instance-group-1"}
expectedSpotLabel = []string{"instancemgr.keikoproj.io/lifecycle=spot", "node-role.kubernetes.io/instance-group-1=\"\"", "node.kubernetes.io/role=instance-group-1"}
expectedMixedLabel = []string{"instancemgr.keikoproj.io/lifecycle=mixed", "node-role.kubernetes.io/instance-group-1=\"\"", "node.kubernetes.io/role=instance-group-1"}
expectedSpotLabel = []string{defaultImageLabel, "instancemgr.keikoproj.io/lifecycle=spot", "node-role.kubernetes.io/instance-group-1=\"\"", "node.kubernetes.io/role=instance-group-1"}
expectedMixedLabel = []string{defaultImageLabel, "instancemgr.keikoproj.io/lifecycle=mixed", "node-role.kubernetes.io/instance-group-1=\"\"", "node.kubernetes.io/role=instance-group-1"}
)

w := MockAwsWorker(asgMock, iamMock, eksMock, ec2Mock)
Expand Down

0 comments on commit c0eb25d

Please sign in to comment.