Skip to content

Commit

Permalink
Adding AWSNodeTemplate drift
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam committed Jul 31, 2023
1 parent e08a862 commit f840901
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 183 deletions.
10 changes: 10 additions & 0 deletions .github/actions/e2e/cleanup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ runs:
- uses: ./.github/actions/e2e/install-eksctl
with:
eksctl_version: v0.147.0
- name: delete-instance-profiles
shell:
run: |
for name in $(aws iam list-instance-profiles --query "InstanceProfiles[*].{Name:InstanceProfileName}" --output text); do
tags=$(aws iam list-instance-profile-tags --instance-profile-name $name --output json)
if [[ $(echo $tags | jq -r '.Tags[] | select(.Key == "karpenter.sh/discovery") | .Value') == "${{ inputs.cluster_name }}" ]]; then
aws iam delete-instance-profile --instance-profile-name $name
break
fi
done
- name: delete-cluster
shell: bash
run: |
Expand Down
12 changes: 11 additions & 1 deletion pkg/cloudprovider/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *CloudProvider) isNodeTemplateDrifted(ctx context.Context, machine *v1al
return false, fmt.Errorf("calculating subnet drift, %w", err)
}

return amiDrifted || securitygroupDrifted || subnetDrifted, nil
return amiDrifted || securitygroupDrifted || subnetDrifted || c.areStaticFieldsDrifted(machine, nodeTemplate), nil
}

func (c *CloudProvider) isAMIDrifted(ctx context.Context, machine *v1alpha5.Machine, provisioner *v1alpha5.Provisioner,
Expand Down Expand Up @@ -106,6 +106,16 @@ func (c *CloudProvider) areSecurityGroupsDrifted(ec2Instance *instance.Instance,
return !securityGroupIds.Equal(sets.New(ec2Instance.SecurityGroupIDs...)), nil
}

func (c *CloudProvider) areStaticFieldsDrifted(machine *v1alpha5.Machine, nodeTemplate *v1alpha1.AWSNodeTemplate) bool {
nodeTemplateHash, foundHashNodeTemplate := nodeTemplate.ObjectMeta.Annotations[v1alpha1.AnnotationNodeTemplateHash]
machineHash, foundHashMachine := machine.ObjectMeta.Annotations[v1alpha1.AnnotationNodeTemplateHash]
if !foundHashNodeTemplate || !foundHashMachine {
return false
}

return nodeTemplateHash != machineHash
}

func (c *CloudProvider) getInstance(ctx context.Context, providerID string) (*instance.Instance, error) {
// Get InstanceID to fetch from EC2
instanceID, err := utils.ParseInstanceID(providerID)
Expand Down
Loading

0 comments on commit f840901

Please sign in to comment.