Skip to content

Commit

Permalink
Fix Branch Name logic for Dependabot and UpdateCLI pushes to k3s-io (#…
Browse files Browse the repository at this point in the history
…11376)

* Improve node checking for etcd docker test
* Fix branch name for dependabot and updatecli PRs

Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola authored Nov 27, 2024
1 parent 55cda22 commit c669600
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,17 @@ jobs:
# For upgrade and skew tests, we need to know the branch name this run is based off.
# Since this is predetermined, we can run this step before the docker-go job, saving time.
# For PRs we can use the base_ref (ie the target branch of the PR).
# For pushes to k3s-io/k3s, the branch_name is a valid ref, master or release-x.y.
# For pushes to k3s-io/k3s from dependabot or updatecli, use master
# All other pushes should be a valid ref, master or release-1.XX.
# For pushes to a fork, we need to determine the branch name by finding the parent branch from git show-branch history.
- name: Determine branch name
id: branch_step
run: |
if [ ${{ github.repository }} = "k3s-io/k3s" ]; then
BRANCH_NAME=$(echo ${{ github.base_ref || github.ref_name }})
if [[ $BRANCH_NAME =~ ^(dependabot|updatecli) ]]; then
BRANCH_NAME=master
fi
elif [ -z "${{ github.base_ref }}" ]; then
# We are in a fork, and need some git history to determine the branch name
git fetch origin --depth=100 +refs/heads/*:refs/remotes/origin/*
Expand All @@ -162,7 +166,14 @@ jobs:
fi
echo "Branch Name is $BRANCH_NAME"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
# branch name should be either master or release-1.XX
- name: Fail if branch name does not match pattern
run: |
if [[ ! ${{ steps.branch_step.outputs.branch_name }} =~ ^(master|release-[0-9]+\.[0-9]+)$ ]]; then
echo "Branch name ${{ steps.branch_step.outputs.branch_name }} does not match pattern"
exit 1
fi
docker-go:
needs: [build, build-go-tests]
name: Docker Tests In GO
Expand Down Expand Up @@ -193,7 +204,7 @@ jobs:
name: docker-go-tests
path: ./dist/artifacts
- name: Run ${{ matrix.dtest }} Test
# Put the compied test binary back in the same place as the test source
# Put the compiled test binary back in the same place as the test source
run: |
chmod +x ./dist/artifacts/${{ matrix.dtest }}.test
mv ./dist/artifacts/${{ matrix.dtest }}.test ./tests/docker/${{ matrix.dtest }}/
Expand Down
12 changes: 5 additions & 7 deletions tests/docker/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ var _ = Describe("Etcd Tests", Ordered, func() {
Eventually(func() error {
return tester.DeploymentsReady([]string{"coredns", "local-path-provisioner", "metrics-server", "traefik"}, config.KubeconfigFile)
}, "60s", "5s").Should(Succeed())
Eventually(func(g Gomega) {
g.Expect(tester.ParseNodes(config.KubeconfigFile)).To(HaveLen(3))
g.Expect(tester.NodesReady(config.KubeconfigFile)).To(Succeed())
Eventually(func() error {
return tester.NodesReady(config.KubeconfigFile, config.GetNodeNames()...)
}, "60s", "5s").Should(Succeed())
})
It("should destroy the cluster", func() {
Expand All @@ -59,10 +58,9 @@ var _ = Describe("Etcd Tests", Ordered, func() {
Eventually(func() error {
return tester.DeploymentsReady([]string{"coredns", "local-path-provisioner", "metrics-server", "traefik"}, config.KubeconfigFile)
}, "90s", "5s").Should(Succeed())
Eventually(func(g Gomega) {
g.Expect(tester.ParseNodes(config.KubeconfigFile)).To(HaveLen(6))
g.Expect(tester.NodesReady(config.KubeconfigFile)).To(Succeed())
}, "60s", "5s").Should(Succeed())
Eventually(func() error {
return tester.NodesReady(config.KubeconfigFile, config.GetNodeNames()...)
}, "90s", "5s").Should(Succeed())
})
})
})
Expand Down
15 changes: 14 additions & 1 deletion tests/docker/test-helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,29 @@ func PodReady(podName, namespace, kubeconfigFile string) (bool, error) {
}

// Checks if all nodes are ready, otherwise returns an error
func NodesReady(kubeconfigFile string) error {
// If nodeNames are provided, make sure those nodes are ready
func NodesReady(kubeconfigFile string, nodeNames ...string) error {
nodes, err := ParseNodes(kubeconfigFile)
if err != nil {
return err
}
nodesFound := make(map[string]bool, len(nodeNames))
for _, nodeName := range nodeNames {
nodesFound[nodeName] = false
}
for _, node := range nodes {
for _, condition := range node.Status.Conditions {
if condition.Type == corev1.NodeReady && condition.Status != corev1.ConditionTrue {
return fmt.Errorf("node %s is not ready", node.Name)
}
if _, ok := nodesFound[node.Name]; ok {
nodesFound[node.Name] = true
}
}
}
for nodeName, found := range nodesFound {
if !found {
return fmt.Errorf("node %s not found", nodeName)
}
}
return nil
Expand Down

0 comments on commit c669600

Please sign in to comment.