Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Github workflow for updating generated files for default addons #7766

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions .github/workflows/update-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,12 @@ jobs:
go-
- name: Update ${{ matrix.resource }}
run: make update-${{ matrix.resource }}
- name: Commit changes
id: commit
run: |
git checkout $DEFAULT_BRANCH
git checkout -B update-${{ matrix.resource }}
git add -u
if ! EDITOR=true git commit -m "Update ${{ matrix.resource }}"; then
echo "changes=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "changes=true" >> $GITHUB_OUTPUT
! git diff --exit-code $DEFAULT_BRANCH HEAD
git push --force-with-lease origin HEAD
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
name: Open PR to ${{env.DEFAULT_BRANCH}}
if: steps.commit.outputs.changes == 'true'
- name: Upsert pull request
uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e #v6.0.2
with:
github-token: ${{ secrets.EKSCTLBOT_TOKEN }}
script: |
const { data: pr } = await github.rest.pulls.create({
...context.repo,
title: "Update ${{ matrix.resource }}",
head: "update-${{ matrix.resource }}",
base: "${{ env.DEFAULT_BRANCH }}",
});
await github.rest.issues.addLabels({
...context.repo,
issue_number: pr.number,
labels: ["kind/improvement"],
});
token: ${{ secrets.EKSCTLBOT_TOKEN }}
commit-message: update ${{ matrix.resource }}
committer: eksctl-bot <eksctl-bot@users.noreply.github.com>
title: 'Update ${{ matrix.resource }}'
branch: update-${{ matrix.resource }}
labels: area/tech-debt
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,10 @@ generate-all: generate-always $(conditionally_generated_files) ## Re-generate al
check-all-generated-files-up-to-date: generate-all ## Run the generate all command and verify there is no new diff
git diff --quiet -- $(conditionally_generated_files) || (git --no-pager diff $(conditionally_generated_files); echo "HINT: to fix this, run 'git commit $(conditionally_generated_files) --message \"Update generated files\"'"; exit 1)

### Update aws-node addon manifests from AWS
pkg/addons/default/assets/aws-node.yaml:
go generate ./pkg/addons/default/aws_node_generate.go

.PHONY: update-aws-node
update-aws-node: ## Re-download the aws-node manifests from AWS
go generate ./pkg/addons/default/aws_node_generate.go
pkg/addons/default/scripts/update_aws_node.sh

.PHONY:
update-coredns: ## get latest coredns builds for each available eks version
Expand Down
4 changes: 0 additions & 4 deletions pkg/addons/default/aws_node_generate.go

This file was deleted.

10 changes: 6 additions & 4 deletions pkg/addons/default/aws_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package defaultaddons_test

import (
"context"
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -60,6 +61,7 @@ var _ = Describe("AWS Node", func() {

Describe("UpdateAWSNode", func() {
var preUpdateAwsNode *v1.DaemonSet
const expectedVersion = "v1.18.1"
BeforeEach(func() {
loadSamples(rawClient, "testdata/sample-1.15.json")

Expand All @@ -79,11 +81,11 @@ var _ = Describe("AWS Node", func() {
Expect(err).NotTo(HaveOccurred())
Expect(awsNode.Spec.Template.Spec.Containers).To(HaveLen(2))
Expect(awsNode.Spec.Template.Spec.Containers[0].Image).To(
Equal("602401143452.dkr.ecr.us-east-1.amazonaws.com/amazon-k8s-cni:v1.18.1"),
Equal(fmt.Sprintf("602401143452.dkr.ecr.us-east-1.amazonaws.com/amazon-k8s-cni:%s", expectedVersion)),
)
Expect(awsNode.Spec.Template.Spec.InitContainers).To(HaveLen(1))
Expect(awsNode.Spec.Template.Spec.InitContainers[0].Image).To(
Equal("602401143452.dkr.ecr.us-east-1.amazonaws.com/amazon-k8s-cni-init:v1.18.1"),
Equal(fmt.Sprintf("602401143452.dkr.ecr.us-east-1.amazonaws.com/amazon-k8s-cni-init:%s", expectedVersion)),
)
})
})
Expand All @@ -99,11 +101,11 @@ var _ = Describe("AWS Node", func() {
Expect(err).NotTo(HaveOccurred())
Expect(awsNode.Spec.Template.Spec.Containers).To(HaveLen(2))
Expect(awsNode.Spec.Template.Spec.Containers[0].Image).To(
Equal("961992271922.dkr.ecr.cn-northwest-1.amazonaws.com.cn/amazon-k8s-cni:v1.18.1"),
Equal(fmt.Sprintf("961992271922.dkr.ecr.cn-northwest-1.amazonaws.com.cn/amazon-k8s-cni:%s", expectedVersion)),
)
Expect(awsNode.Spec.Template.Spec.InitContainers).To(HaveLen(1))
Expect(awsNode.Spec.Template.Spec.InitContainers[0].Image).To(
Equal("961992271922.dkr.ecr.cn-northwest-1.amazonaws.com.cn/amazon-k8s-cni-init:v1.18.1"),
Equal(fmt.Sprintf("961992271922.dkr.ecr.cn-northwest-1.amazonaws.com.cn/amazon-k8s-cni-init:%s", expectedVersion)),
)
})
})
Expand Down
20 changes: 20 additions & 0 deletions pkg/addons/default/scripts/update_aws_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Set base URL for VPC CNI releases on GitHub
base_url="https://raw.githubusercontent.com/aws/amazon-vpc-cni-k8s/"

get_latest_release_tag() {
curl -sL https://api.github.com/repos/aws/amazon-vpc-cni-k8s/releases/latest | jq -r '.tag_name'
}

latest_release_tag=$(get_latest_release_tag)

default_addons_dir="pkg/addons/default"

# Download the latest aws-k8s-cni.yaml file
curl -sL "$base_url$latest_release_tag/config/master/aws-k8s-cni.yaml?raw=1" --output "$default_addons_dir/assets/aws-node.yaml"

echo "found latest release tag:" $latest_release_tag

# Update the unit test file
sed -i "s/expectedVersion = \"\(.*\)\"/expectedVersion = \"$latest_release_tag\"/g" "$default_addons_dir/aws_node_test.go"
20 changes: 13 additions & 7 deletions pkg/addons/default/scripts/update_coredns_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,33 @@ func getLatestVersion(ctx context.Context, clusterProvider *eks.ClusterProvider,
log.Fatalf("failed calling EKS::DescribeAddonVersions: %v", err)
}

corednsVersions := output.Addons[0].AddonVersions
if len(corednsVersions) == 0 {
if len(output.Addons[0].AddonVersions) == 0 {
return ""
}
var corednsVersions []string
regexpVersion := regexp.MustCompile(`v\d+\.\d+\.\d+-eksbuild\.\d+`)
for _, info := range output.Addons[0].AddonVersions {
if regexpVersion.MatchString(*info.AddonVersion) {
corednsVersions = append(corednsVersions, *info.AddonVersion)
}
}

sort.Slice(corednsVersions, func(i, j int) bool {
vi, err := semver.Parse(trim(*corednsVersions[i].AddonVersion))
vi, err := semver.Parse(trim(corednsVersions[i]))
if err != nil {
log.Fatalf("failed to parse coredns version %s: %v", trim(*corednsVersions[i].AddonVersion), err)
log.Fatalf("failed to parse coredns version %s: %v", trim(corednsVersions[i]), err)
}
vj, err := semver.Parse(trim(*corednsVersions[j].AddonVersion))
vj, err := semver.Parse(trim(corednsVersions[j]))
if err != nil {
log.Fatalf("failed to parse coredns version %s: %v", trim(*corednsVersions[j].AddonVersion), err)
log.Fatalf("failed to parse coredns version %s: %v", trim(corednsVersions[j]), err)
}
if vi.Compare(vj) >= 0 {
return true
}
return false
})

return *corednsVersions[0].AddonVersion
return corednsVersions[0]
}

func replaceCurrentVersionIfOutdated(latestVersion string, kubernetesVersion string) {
Expand Down