Skip to content

Commit c688d9a

Browse files
committed
fix: move addon from CFN to manager for cloudwatch stack
1 parent f3a0a41 commit c688d9a

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

internal/deployers/eksapi/addons.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ func NewAddonManager(clients *awsClients) *AddonManager {
2626
}
2727

2828
func (m *AddonManager) createAddons(infra *Infrastructure, cluster *Cluster, opts *deployerOptions) error {
29+
ctx := context.TODO()
30+
31+
addonMap := map[string]string{}
2932
for _, addon := range opts.Addons {
3033
addonParts := strings.Split(addon, ":")
3134
if len(addonParts) != 2 {
32-
return fmt.Errorf("invalid addon: %s", addon)
35+
return fmt.Errorf("invalid addon format: %s", addon)
3336
}
3437
name := addonParts[0]
3538
version := addonParts[1]
@@ -38,26 +41,32 @@ func (m *AddonManager) createAddons(infra *Infrastructure, cluster *Cluster, opt
3841
if err != nil {
3942
return err
4043
}
41-
klog.Infof("creating addon %s version: %s", name, resolvedVersion)
44+
// dedupe addons with the same name. last provided entry wins.
45+
addonMap[name] = resolvedVersion
46+
}
47+
48+
for addonName, addonVersion := range addonMap {
49+
klog.Infof("creating addon %s version: %s", addonName, addonVersion)
4250
input := eks.CreateAddonInput{
43-
AddonName: aws.String(name),
44-
AddonVersion: aws.String(resolvedVersion),
51+
AddonName: aws.String(addonName),
52+
AddonVersion: aws.String(addonVersion),
4553
ClusterName: aws.String(cluster.name),
4654
}
47-
_, err = m.clients.EKS().CreateAddon(context.TODO(), &input)
55+
_, err := m.clients.EKS().CreateAddon(ctx, &input)
4856
if err != nil {
4957
return fmt.Errorf("failed to create addon: %v", err)
5058
}
51-
klog.Infof("waiting for addon to be active: %s", name)
59+
klog.Infof("waiting for addon to be active: %s", addonName)
5260
err = eks.NewAddonActiveWaiter(m.clients.EKS()).
53-
Wait(context.TODO(), &eks.DescribeAddonInput{
61+
Wait(ctx, &eks.DescribeAddonInput{
62+
AddonName: aws.String(addonName),
5463
ClusterName: aws.String(cluster.name),
55-
AddonName: aws.String(name),
5664
}, addonCreationTimeout)
5765
if err != nil {
5866
return fmt.Errorf("failed to wait for addon to be active: %v", err)
5967
}
6068
}
69+
6170
return nil
6271
}
6372

internal/deployers/eksapi/deployer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ func (d *deployer) Up() error {
209209
if d.AMI != "" && d.ExpectedAMI == "" {
210210
d.ExpectedAMI = d.AMI
211211
}
212+
213+
// TODO: add the pod identity agent addons because it is required for
214+
// cloudwatch infrastructure. cloudwatch infra might want to be optional.
215+
// this must be prepended to the list in order to respect user overrides.
216+
d.deployerOptions.Addons = slices.Insert(d.deployerOptions.Addons, 0, "eks-pod-identity-agent:default")
217+
212218
if err := d.addonManager.createAddons(d.infra, d.cluster, &d.deployerOptions); err != nil {
213219
return err
214220
}

internal/deployers/eksapi/templates/cloudwatch-infra.yaml.template

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ Resources:
3636
Namespace: amazon-cloudwatch
3737
ServiceAccount: cwagent
3838
RoleArn: !GetAtt CloudWatchRole.Arn
39-
40-
EksPodIdentityAgentAddon:
41-
Type: AWS::EKS::Addon
42-
Properties:
43-
AddonName: eks-pod-identity-agent
44-
ClusterName: !Ref ClusterName
4539

4640
Outputs:
4741
CloudWatchRoleArn:

0 commit comments

Comments
 (0)