Skip to content

Commit

Permalink
[ci skip] 2024.09.13-31621
Browse files Browse the repository at this point in the history
  • Loading branch information
cybozu-neco committed Sep 13, 2024
2 parents 7f50cd3 + 6d65dbb commit b1e0ad7
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 25 deletions.
14 changes: 10 additions & 4 deletions dctest/etcdpasswd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dctest

import (
"os"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -17,28 +18,33 @@ func testEtcdpasswd() {
execRetryAt(bootServers[0], handleNetworkRetry, "etcdpasswd", "set", "start-gid", "2000")
execRetryAt(bootServers[0], handleNetworkRetry, "etcdpasswd", "set", "default-group", "cybozu")
execRetryAt(bootServers[0], handleNetworkRetry, "etcdpasswd", "set", "default-groups", "sudo,adm")
execSafeAt(bootServers[0], "etcdpasswd", "user", "add", user)

Eventually(func(g Gomega) {
stdout := execSafeGomegaAt(g, bootServers[0], "etcdpasswd", "user", "list")
if !strings.Contains(string(stdout), user) {
execSafeGomegaAt(g, bootServers[0], "etcdpasswd", "user", "add", user)
}
}).Should(Succeed())
execRetryAt(bootServers[0], handleNetworkRetry, "etcdpasswd", "user", "get", user)

keyBytes, err := os.ReadFile(bobPublicKey)

Expect(err).ShouldNot(HaveOccurred())

stdout, stderr, err := execAtWithInput(bootServers[0], keyBytes, "etcdpasswd", "cert", "add", user)
Expect(err).ShouldNot(HaveOccurred(), "stdout=%s, stderr=%s", stdout, stderr)

By("executing command with sudo at boot servers")
sshKey, err := parsePrivateKey(bobPrivateKey)
Expect(err).ShouldNot(HaveOccurred())

Eventually(func(g Gomega) error {
Eventually(func(g Gomega) {
for _, h := range bootServers {
agent, err := sshTo(h, sshKey, user)
g.Expect(err).ShouldNot(HaveOccurred(), "agent=%v", agent)

stdout, stderr, err = doExec(agent, nil, "sudo", "ls")
g.Expect(err).ShouldNot(HaveOccurred(), "agent=%v stdout=%s, stderr=%s", agent, stdout, stderr)
}
return nil
}).Should(Succeed())
})
}
2 changes: 1 addition & 1 deletion dctest/join_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func testJoinRemove() {
execSafeAt(bootServers[0], "sudo", "env", "VAULT_TOKEN="+token, "neco", "leave", "3")

By("Waiting for the request to complete")
waitRequestCompleteWithRecover("members: [0 1 2]", 3)
waitRequestComplete("members: [0 1 2]", true)

By("Waiting boot-3 gets removed from etcd")
Eventually(func() error {
Expand Down
21 changes: 9 additions & 12 deletions dctest/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ func execSafeAt(host string, args ...string) []byte {
return stdout
}

func execSafeGomegaAt(g Gomega, host string, args ...string) []byte {
stdout, stderr, err := execAt(host, args...)
g.ExpectWithOffset(1, err).To(Succeed(), "[%s] %v, stdout: %s, stderr: %s", host, args, stdout, stderr)
return stdout
}

func execRetryAt(host string, handler retryHandler, args ...string) []byte {
var stdout, stderr []byte
var err error
Expand All @@ -193,14 +199,12 @@ func execRetryAt(host string, handler retryHandler, args ...string) []byte {
}

// waitRequestComplete waits for the current request to be completed.
// If the requests is aborted, it try to recover a specified number of times.
// If check is not "", the contents is also checked against the output from "neco status".
func waitRequestCompleteWithRecover(check string, recoverMax int) {
func waitRequestComplete(check string, recover ...bool) {
// wait a moment for neco-updater to put a new request.
time.Sleep(time.Second * 2)

recoverCount := 0
Eventually(func() error {
EventuallyWithOffset(1, func() error {
stdout, stderr, err := execAt(bootServers[0], "neco", "status")
if err != nil {
return fmt.Errorf("stdout: %s, stderr: %s, err: %v", stdout, stderr, err)
Expand All @@ -209,10 +213,9 @@ func waitRequestCompleteWithRecover(check string, recoverMax int) {

// Sometimes, neco-worker aborts the update process. Detect it and recover if it is necessary.
if strings.Contains(out, "status: aborted") {
if recoverCount >= recoverMax {
if len(recover) == 0 || !recover[0] {
return StopTrying("update process is aborted: " + out)
}
recoverCount++
fmt.Println(out)
fmt.Println("update request is aborted, try to recover...")
execAt(bootServers[0], "neco", "recover")
Expand All @@ -230,12 +233,6 @@ func waitRequestCompleteWithRecover(check string, recoverMax int) {
}).Should(Succeed())
}

// waitRequestComplete waits for the current request to be completed.
// If check is not "", the contents is also checked against the output from "neco status".
func waitRequestComplete(check string) {
waitRequestCompleteWithRecover(check, 0)
}

func getVaultToken() string {
var token string
Eventually(func() error {
Expand Down
2 changes: 1 addition & 1 deletion dctest/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ WantedBy=multi-user.target`

It("should complete updates", func() {
By("Waiting for request to complete")
waitRequestCompleteWithRecover("", 3)
waitRequestComplete("", true)

By("Installing sshd_config and sudoers")
for _, h := range bootServers {
Expand Down
2 changes: 1 addition & 1 deletion dctest/squid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func testSquid() {

It("should serve for docker daemon", func() {
By("running a testhttpd pod")
execSafeAt(bootServers[0], "kubectl", "run", "testhttpd", "--image=quay.io/cybozu/testhttpd:0")
execSafeAt(bootServers[0], "kubectl", "run", "testhttpd", "--image=ghcr.io/cybozu/testhttpd:0")

Eventually(func() error {
stdout, _, err := execAt(bootServers[0], "kubectl", "get", "pod/testhttpd", "-o=json")
Expand Down
2 changes: 1 addition & 1 deletion dctest/testdata/l4lb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
spec:
containers:
- name: testhttpd
image: quay.io/cybozu/testhttpd:0
image: ghcr.io/cybozu/testhttpd:0
---
kind: Service
apiVersion: v1
Expand Down
2 changes: 1 addition & 1 deletion dctest/testdata/l4lb_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
containers:
- args:
- pause
image: quay.io/cybozu/ubuntu-debug:22.04
image: ghcr.io/cybozu/ubuntu-debug:22.04
name: ubuntu
nodeSelector:
kubernetes.io/hostname: {{.Node}}
2 changes: 1 addition & 1 deletion dctest/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func testUpgrade() {

It("should SHA1 veth name is attached with newer coil", func() {
By("deploying testhttpd")
execSafeAt(bootServers[0], "kubectl", "run", "testhttpd", "--image=quay.io/cybozu/testhttpd:0")
execSafeAt(bootServers[0], "kubectl", "run", "testhttpd", "--image=ghcr.io/cybozu/testhttpd:0")
Eventually(func() error {
stdout, _, err := execAt(bootServers[0], "kubectl", "get", "pod/testhttpd", "-o=json")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions docs/artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Use this, for example, if you have a bug in the latest versions and do not want

```yaml
images:
- repository: quay.io/cybozu/cke
- repository: ghcr.io/cybozu-go/cke
versions: ["1.2.3", "1.2.4", "1.2.5"]
- repository: quay.io/cybozu/etcd
- repository: ghcr.io/cybozu/etcd
versions: ["1.2.3.4"]
debs:
- name: etcdpasswd
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type ContainerImage struct {
Private bool
}

// ParseContainerImageName parses image name like "quay.io/cybozu/etcd:3.3.9-4"
// ParseContainerImageName parses image name like "ghcr.io/cybozu/etcd:3.3.9-4"
func ParseContainerImageName(name string) (ContainerImage, error) {
nametag := strings.Split(name, ":")
if len(nametag) != 2 {
Expand Down

0 comments on commit b1e0ad7

Please sign in to comment.