Skip to content

Commit

Permalink
[ci skip] 2025.01.14-33759
Browse files Browse the repository at this point in the history
  • Loading branch information
cybozu-neco committed Jan 14, 2025
2 parents 8ee94ad + 7ff2577 commit 40dbbc7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 74 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ FAKEROOT = fakeroot
ETCD_DIR = /tmp/neco-etcd
TAGS =

K8S_MINOR_VERSION = $(shell go list -m -f '{{.Version}}' github.com/cybozu-go/cke | cut -d. -f2)

### for Go
GOTAGS = $(TAGS)

Expand Down Expand Up @@ -90,6 +92,7 @@ update-cilium: helm
cd /tmp/work-cilium
$(HELM) template /tmp/work-cilium/install/kubernetes/cilium/ \
--namespace=kube-system \
--kube-version=1.$(K8S_MINOR_VERSION) \
--values cilium/$(CILIUM_OVERLAY)/values.yaml \
--set image.repository=ghcr.io/cybozu/cilium \
--set image.tag=$(CILIUM_TAG) \
Expand Down
93 changes: 19 additions & 74 deletions dctest/cilium_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package dctest

import (
"encoding/json"
"errors"
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -31,83 +27,32 @@ func testCilium() {
}

func checkCiliumAgentDaemonSet() {
EventuallyWithOffset(1, func() error {
stdout, _, err := execAt(bootServers[0], "kubectl", "--namespace=kube-system",
"get", "daemonsets/cilium", "-o=json")
if err != nil {
return err
}

daemonset := new(appsv1.DaemonSet)
err = json.Unmarshal(stdout, daemonset)
if err != nil {
return err
}
EventuallyWithOffset(1, func(g Gomega) {
ds := kubectlGetSafe[appsv1.DaemonSet](g, "--namespace=kube-system", "daemonsets/cilium")

if daemonset.Status.NumberReady != daemonset.Status.DesiredNumberScheduled {
return fmt.Errorf("NumberReady: %d, DesiredNumberScheduled: %d", daemonset.Status.NumberReady, daemonset.Status.DesiredNumberScheduled)
}
if daemonset.Status.NumberReady == 0 {
return errors.New("NumberReady == 0")
}
return nil
g.Expect(ds.Status.NumberReady).To(BeNumerically(">", 0), "NumberReady should be positive")
g.Expect(ds.Status.NumberReady).To(Equal(ds.Status.DesiredNumberScheduled),
"NumberReady: %d, DesiredNumberScheduled: %d", ds.Status.NumberReady, ds.Status.DesiredNumberScheduled)
}).Should(Succeed())
}

func checkCiliumOperatorDeployment() {
EventuallyWithOffset(1, func() error {
stdout, _, err := execAt(bootServers[0], "kubectl", "--namespace=kube-system",
"get", "deployment/cilium-operator", "-o=json")
if err != nil {
return err
}

deployment := new(appsv1.Deployment)
err = json.Unmarshal(stdout, deployment)
if err != nil {
return err
}

if deployment.Status.ReadyReplicas != 2 {
return fmt.Errorf("ReadyReplicas is not 2 but %d", deployment.Status.ReadyReplicas)
}
return nil
EventuallyWithOffset(1, func(g Gomega) {
deployment := kubectlGetSafe[appsv1.Deployment](g, "--namespace=kube-system", "deployment/cilium-operator")
g.Expect(deployment.Status.ReadyReplicas).To(Equal(int32(2)),
"ReadyReplicas of cilium-operator should be 2 but %d", deployment.Status.ReadyReplicas)
}).Should(Succeed())
}
func checkHubbleRelayDeployment() {
EventuallyWithOffset(1, func() error {
stdout, _, err := execAt(bootServers[0], "kubectl", "--namespace=kube-system",
"get", "deployment/hubble-relay", "-o=json")
if err != nil {
return err
}

deployment := new(appsv1.Deployment)
err = json.Unmarshal(stdout, deployment)
if err != nil {
return err
}

if deployment.Status.ReadyReplicas != 1 {
return fmt.Errorf("ReadyReplicas is not 1 but %d", deployment.Status.ReadyReplicas)
}

stdout, _, err = execAt(bootServers[0], "hubble", "status", "-o", "json", "--server",
"hubble-relay.kube-system.svc:443", "--tls", "--tls-allow-insecure")
if err != nil {
return err
}

hubbleStatus := new(hubbleStatus)
err = json.Unmarshal(stdout, hubbleStatus)
if err != nil {
return err
}

if hubbleStatus.NumUnavailableNodes != 0 {
return fmt.Errorf("NumUnavailableNodes is not 0 but %d", hubbleStatus.NumUnavailableNodes)
}

return nil
func checkHubbleRelayDeployment() {
EventuallyWithOffset(1, func(g Gomega) {
deployment := kubectlGetSafe[appsv1.Deployment](g, "--namespace=kube-system", "deployment/hubble-relay")
g.Expect(deployment.Status.ReadyReplicas).To(Equal(int32(1)),
"ReadyReplicas of hubble-relay should be 1 but %d", deployment.Status.ReadyReplicas)

hubbleStatus := unmarshalSafe[hubbleStatus](g, execSafeGomegaAt(g, bootServers[0], "hubble", "status", "-o", "json",
"--server", "hubble-relay.kube-system.svc:443", "--tls", "--tls-allow-insecure"))
g.Expect(hubbleStatus.NumUnavailableNodes).To(Equal(0),
"NumUnavailableNodes should be 0 but %d", hubbleStatus.NumUnavailableNodes)
}).Should(Succeed())
}
17 changes: 17 additions & 0 deletions dctest/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ func execRetryAt(host string, handler retryHandler, args ...string) []byte {
return stdout
}

func unmarshalSafeWithOffset[T any](g Gomega, offset int, data []byte) *T {
ret := new(T)
err := json.Unmarshal(data, ret)
g.ExpectWithOffset(offset, err).NotTo(HaveOccurred(), "unmarshal failed: %w", err)
return ret
}

func unmarshalSafe[T any](g Gomega, data []byte) *T {
return unmarshalSafeWithOffset[T](g, 2, data)
}

func kubectlGetSafe[T any](g Gomega, args ...string) *T {
args = append([]string{"kubectl", "get", "-o=json"}, args...)
data := execSafeGomegaAt(g, bootServers[0], args...)
return unmarshalSafeWithOffset[T](g, 2, data)
}

// 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, recover ...bool) {
Expand Down

0 comments on commit 40dbbc7

Please sign in to comment.