Skip to content

Commit

Permalink
refrect review
Browse files Browse the repository at this point in the history
Signed-off-by: Yuji Ito <[email protected]>
  • Loading branch information
llamerada-jp committed Feb 25, 2025
1 parent 2a1a5b1 commit d501110
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 298 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ mock: mockgen
.PHONY: test
test: manifests generate fmt vet envtest mock ## Run tests.
# adding -p 1 -v to stream logs. see https://github.com/golang/go/issues/46959
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out -p 1 -v
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --bin-dir $(LOCALBIN) -p path)" \
SKIP_CEPH_CMD_TEST=1 \
go test ./... -coverprofile cover.out -p 1 -v

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
golangci-lint:
Expand Down
1 change: 0 additions & 1 deletion ceph/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ test: ceph-custom.tar
$(MINIKUBE_CMD) image load ceph-custom.tar
$(KUBECTL_CMD) apply -k ./manifests/
env \
CEPH_CMD_TEST=1 \
KUBECTL=$(KUBECTL_CMD) \
go test -v -count=1 -timeout 1h ./test/

Expand Down
4 changes: 2 additions & 2 deletions ceph/test/cluster/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func CompareBlockWithFile(namespace, deployName, filename string) error {
}

args := []string{path.Join(workDir, filename), path.Join(workDir, workFilename)}
log.Printf("📂 diff %s", strings.Join(args, " "))
_, err := exec.Command("diff", args...).CombinedOutput()
log.Printf("📂 cmp %s", strings.Join(args, " "))
_, err := exec.Command("cmp", args...).CombinedOutput()
if err != nil {
showMD5Sum(path.Join(workDir, filename))
showMD5Sum(path.Join(workDir, workFilename))
Expand Down
27 changes: 8 additions & 19 deletions ceph/test/cluster/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/exec"
"regexp"
"strings"
"time"

storagev1 "k8s.io/api/storage/v1"
)
Expand All @@ -36,22 +37,7 @@ var kubectlCmd = os.Getenv("KUBECTL")
var cephMatcher = regexp.MustCompile(` (ceph|rbd) `)

func Kubectl(args ...string) ([]byte, error) {
if len(kubectlCmd) == 0 {
return nil, fmt.Errorf("KUBECTL environment variable should be set")
}

icon := "⚓"
if cephMatcher.MatchString(strings.Join(args, " ")) {
icon = "🐙"
}
log.Printf("%s kubectl %s", icon, strings.Join(args, " "))
var stdout bytes.Buffer
command := exec.Command(kubectlCmd, args...)
command.Stdout = &stdout
command.Stderr = os.Stderr

err := command.Run()
return stdout.Bytes(), err
return KubectlWithInput(nil, args...)
}

func KubectlWithInput(stdin []byte, args ...string) ([]byte, error) {
Expand All @@ -66,7 +52,9 @@ func KubectlWithInput(stdin []byte, args ...string) ([]byte, error) {
log.Printf("%s kubectl %s", icon, strings.Join(args, " "))
var stdout bytes.Buffer
command := exec.Command(kubectlCmd, args...)
command.Stdin = bytes.NewReader(stdin)
if stdin != nil {
command.Stdin = bytes.NewReader(stdin)
}
command.Stdout = &stdout
command.Stderr = os.Stderr

Expand Down Expand Up @@ -185,6 +173,7 @@ func ResizePVC(namespace, pvcName, size string) error {
if string(after) != string(before) {
return nil
}
time.Sleep(500 * time.Millisecond)
}
return fmt.Errorf("PVC size is not changed")
}
Expand Down Expand Up @@ -217,11 +206,11 @@ func CleanupNamespace(namespace string) error {
}

func CleanupGlobal() error {
SCs, err := GetObjectList[storagev1.StorageClassList]("sc", "")
scs, err := GetObjectList[storagev1.StorageClassList]("sc", "")
if err != nil {
return err
}
for _, sc := range SCs.Items {
for _, sc := range scs.Items {
if sc.Provisioner == RBD_PROVISIONER {
_, err = Kubectl("delete", "sc", sc.Name)
if err != nil {
Expand Down
Loading

0 comments on commit d501110

Please sign in to comment.