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

🌱Add log and manifest collection for clusterctl upgrade test #1124

Merged
merged 1 commit into from
Aug 11, 2023
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
3 changes: 3 additions & 0 deletions scripts/fetch_target_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ do
for POD in ${PODS}
do
mkdir -p "${DIR_NAME}/${NAMESPACE}/${POD}"
kubectl --kubeconfig="${KUBECONFIG_WORKLOAD}" describe pods -n "${NAMESPACE}" "${POD}" \
> "${DIR_NAME}/${NAMESPACE}/${POD}/stdout_describe.log" \
2> "${DIR_NAME}/${NAMESPACE}/${POD}/stderr_describe.log"
CONTAINERS="$(kubectl --kubeconfig="${KUBECONFIG_WORKLOAD}" get pods -n "${NAMESPACE}" "${POD}" -o jsonpath='{.spec.containers[*].name}')"
for CONTAINER in ${CONTAINERS}
do
Expand Down
43 changes: 43 additions & 0 deletions test/e2e/upgrade_clusterctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -49,6 +50,7 @@ var _ = Describe(fmt.Sprintf("When testing cluster upgrade from releases %s > cu
// Override capi/capm3 versions exported in preInit
os.Setenv("CAPI_VERSION", "v1beta1")
os.Setenv("CAPM3_VERSION", "v1beta1")
os.Setenv("KUBECONFIG_BOOTSTRAP", bootstrapClusterProxy.GetKubeconfigPath())
},
PreWaitForCluster: preWaitForCluster,
PreUpgrade: preUpgrade,
Expand Down Expand Up @@ -197,6 +199,21 @@ func preInitFunc(clusterProxy framework.ClusterProxy) {
Expect(clusterProxy.Apply(ctx, certManagerYaml)).ShouldNot(HaveOccurred())
}

By("Fetch manifest for bootstrap cluster")
path := filepath.Join(os.Getenv("CAPM3PATH"), "scripts")
cmd := exec.Command("./fetch_manifests.sh") // #nosec G204:gosec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to avoid this invoking of shell inside go code? As you can see you have to ignore the gosec error and we are trying to get rid of such invocations from other places too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running of these script are part of e2e test and used the approach in different place of e2e tests. I think we need to check for a solution for that separately with new ticket.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theres already ticket for that , I am concerned about adding new cases when old cases are being worked upon.

cmd.Dir = path
_ = cmd.Run()

By("Fetch target cluster kubeconfig for target cluster log collection")
kconfigPathWorkload := clusterProxy.GetKubeconfigPath()
os.Setenv("KUBECONFIG_WORKLOAD", kconfigPathWorkload)
Logf("Save kubeconfig in temp folder for project-infra target log collection")
kubeconfigPathTemp := "/tmp/kubeconfig-test1.yaml"
cmd = exec.Command("cp", kconfigPathWorkload, kubeconfigPathTemp) // #nosec G204:gosec
stdoutStderr, er := cmd.CombinedOutput()
Logf("%s\n", stdoutStderr)
Expect(er).To(BeNil(), "Cannot fetch target cluster kubeconfig")
// install certmanager
installCertManager(clusterProxy)
// Remove ironic
Expand Down Expand Up @@ -295,10 +312,36 @@ func preUpgrade(clusterProxy framework.ClusterProxy) {
func preCleanupManagementCluster(clusterProxy framework.ClusterProxy) {
// Abort the test in case of failure and keepTestEnv is true during keep VM trigger
if CurrentSpecReport().Failed() {
// Fetch logs in case of failure in management cluster
By("Fetch logs from management cluster")
path := filepath.Join(os.Getenv("CAPM3PATH"), "scripts")
cmd := exec.Command("./fetch_target_logs.sh") // #nosec G204:gosec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

cmd.Dir = path
errorPipe, _ := cmd.StderrPipe()
_ = cmd.Start()
errorData, _ := io.ReadAll(errorPipe)
if len(errorData) > 0 {
Logf("Error of the shell: %v\n", string(errorData))
}

if keepTestEnv {
AbortSuite("e2e test aborted and skip cleaning the VM", 4)
}
}
// Fetch logs from management cluster
By("Fetch logs from management cluster")
path := filepath.Join(os.Getenv("CAPM3PATH"), "scripts")
cmd := exec.Command("./fetch_target_logs.sh") // #nosec G204:gosec
cmd.Dir = path
errorPipe, _ := cmd.StderrPipe()
_ = cmd.Start()
errorData, _ := io.ReadAll(errorPipe)
if len(errorData) > 0 {
Logf("Error of the shell: %v\n", string(errorData))
}
os.Unsetenv("KUBECONFIG_WORKLOAD")
os.Unsetenv("KUBECONFIG_BOOTSTRAP")

// Reinstall ironic
reInstallIronic := func() {
By("Reinstate Ironic containers and BMH")
Expand Down
Loading