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

Have better hygiene of e2e leftovers #1580

Merged
merged 1 commit into from
May 17, 2024
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
2 changes: 1 addition & 1 deletion .github/actions/gen-install-scripts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
description: "Version of the Operator"
required: true
ENV:
description: "Kustomize patch name (enviroment configuration patch)"
description: "Kustomize patch name (environment configuration patch)"
required: true
runs:
using: 'docker'
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ tags
testbin/

# don't include generated files from e2e tests
test/helper/e2e/data/gen/
output/
test/e2e/data/
test/e2e/output/

node_modules
tmp/
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,5 @@ gen-sdlc-checklist: envsubst docker-sbom ## Generate the SDLC checklist
.PHONY: clear-e2e-leftovers
clear-e2e-leftovers: ## Clear the e2e test leftovers quickly
git restore bundle* config deploy
cd helm-charts && git restore .
git submodule update helm-charts
1 change: 0 additions & 1 deletion output/keep-directory.txt

This file was deleted.

8 changes: 4 additions & 4 deletions test/e2e/helm_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ var _ = Describe("HELM charts", Ordered, func() {
Expect(err).Should(BeNil())
namespaceDeploymentJSON, err := json.MarshalIndent(namespaceDeployment, "", " ")
Expect(err).Should(BeNil())
utils.SaveToFile("namespace-deployment.json", namespaceDeploymentJSON)
utils.SaveToFile("output/namespace-deployment.json", namespaceDeploymentJSON)

pod, err := k8s.GetAllDeploymentPods("mongodb-atlas-operator", data.Resources.Namespace)
Expect(err).Should(BeNil())
podJSON, err := json.MarshalIndent(pod, "", " ")
Expect(err).Should(BeNil())
utils.SaveToFile("namespace-pod.json", podJSON)
utils.SaveToFile("output/namespace-pod.json", podJSON)

bytes, err := k8s.GetPodLogsByDeployment("mongodb-atlas-operator", config.DefaultOperatorNS, corev1.PodLogOptions{})
if err != nil {
GinkgoWriter.Write([]byte(err.Error()))
}
utils.SaveToFile(
fmt.Sprintf("../../output/%s/operator-logs-default.txt", data.Resources.Namespace),
fmt.Sprintf("output/%s/operator-logs-default.txt", data.Resources.Namespace),
bytes,
)
bytes, err = k8s.GetPodLogsByDeployment("mongodb-atlas-operator", data.Resources.Namespace, corev1.PodLogOptions{})
if err != nil {
GinkgoWriter.Write([]byte(err.Error()))
}
utils.SaveToFile(
fmt.Sprintf("../../output/%s/operator-logs.txt", data.Resources.Namespace),
fmt.Sprintf("output/%s/operator-logs.txt", data.Resources.Namespace),
bytes,
)
actions.SaveProjectsToFile(data.Context, data.K8SClient, data.Resources.Namespace)
Expand Down
Empty file.
10 changes: 5 additions & 5 deletions test/helper/e2e/actions/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func SaveProjectsToFile(ctx context.Context, k8sClient client.Client, ns string)
if err != nil {
return fmt.Errorf("error getting project list: %w", err)
}
path := fmt.Sprintf("../../output/%s/%s.yaml", ns, "projects")
path := fmt.Sprintf("output/%s/%s.yaml", ns, "projects")
err = utils.SaveToFile(path, yaml)
if err != nil {
return fmt.Errorf("error saving projects to file: %w", err)
Expand All @@ -219,7 +219,7 @@ func SaveTeamsToFile(ctx context.Context, k8sClient client.Client, ns string) er
if err != nil {
return fmt.Errorf("error getting team list: %w", err)
}
path := fmt.Sprintf("../../output/%s/%s.yaml", ns, "teams")
path := fmt.Sprintf("output/%s/%s.yaml", ns, "teams")
err = utils.SaveToFile(path, yaml)
if err != nil {
return fmt.Errorf("error saving teams to file: %w", err)
Expand All @@ -232,7 +232,7 @@ func SaveDeploymentsToFile(ctx context.Context, k8sClient client.Client, ns stri
if err != nil {
return fmt.Errorf("error getting deployment list: %w", err)
}
path := fmt.Sprintf("../../output/%s/%s.yaml", ns, "deployments")
path := fmt.Sprintf("output/%s/%s.yaml", ns, "deployments")
err = utils.SaveToFile(path, yaml)
if err != nil {
return fmt.Errorf("error saving deployments to file: %w", err)
Expand All @@ -245,7 +245,7 @@ func SaveUsersToFile(ctx context.Context, k8sClient client.Client, ns string) er
if err != nil {
return fmt.Errorf("error getting user list: %w", err)
}
path := fmt.Sprintf("../../output/%s/%s.yaml", ns, "users")
path := fmt.Sprintf("output/%s/%s.yaml", ns, "users")
err = utils.SaveToFile(path, yaml)
if err != nil {
return fmt.Errorf("error saving users to file: %w", err)
Expand All @@ -260,7 +260,7 @@ func SaveTestAppLogs(input model.UserInputs) {
Expect(err).ToNot(HaveOccurred())

utils.SaveToFile(
fmt.Sprintf("../../output/%s/testapp-logs-%s.txt", input.Namespace, user.Spec.Username),
fmt.Sprintf("output/%s/testapp-logs-%s.txt", input.Namespace, user.Spec.Username),
bytes,
)
}
Expand Down
5 changes: 4 additions & 1 deletion test/helper/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ const (
AzureRegionEU = "northeurope"

// GCP
FileNameSAGCP = "../../output/gcp_service_account.json"
FileNameSAGCP = "output/gcp_service_account.json"

// X509 auth test PEM key
PEMCertFileName = "output/x509cert.pem"
)
17 changes: 9 additions & 8 deletions test/helper/e2e/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/pem"
"fmt"
"os"
"path/filepath"

. "github.com/onsi/gomega"
"github.com/sethvargo/go-password/password"
Expand All @@ -14,16 +15,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
k8scfg "sigs.k8s.io/controller-runtime/pkg/client/config"

akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1/status"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/connectionsecret"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/config"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/utils"
)

func CreateNewClient() (client.Client, error) {
cfg, err := config.GetConfig()
cfg, err := k8scfg.GetConfig()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -252,26 +254,25 @@ func CreateCertificateX509(ctx context.Context, k8sClient client.Client, name, n
return fmt.Errorf("error generating x509 cert: %w", err)
}

certFileName := "x509cert.pem"
certFile, err := os.Create(certFileName)
certFile, err := os.Create(filepath.Clean(config.PEMCertFileName))
if err != nil {
return fmt.Errorf("failed to create file %s: %w", certFileName, err)
return fmt.Errorf("failed to create file %s: %w", config.PEMCertFileName, err)
}

err = pem.Encode(certFile, &pem.Block{
Type: "CERTIFICATE",
Bytes: cert,
})
if err != nil {
return fmt.Errorf("failed to write data to %s: %w", certFileName, err)
return fmt.Errorf("failed to write data to %s: %w", config.PEMCertFileName, err)
}
err = certFile.Close()
if err != nil {
return fmt.Errorf("cant close file: %w", err)
}

var rawCert []byte
rawCert, err = os.ReadFile(certFileName)
rawCert, err = os.ReadFile(filepath.Clean(config.PEMCertFileName))
if err != nil {
return fmt.Errorf("failed to read cert file: %w", err)
}
Expand All @@ -282,7 +283,7 @@ func CreateCertificateX509(ctx context.Context, k8sClient client.Client, name, n
Namespace: ns,
},
Data: map[string][]byte{
certFileName: rawCert,
filepath.Base(config.PEMCertFileName): rawCert,
},
}
certificateSecret.Labels = map[string]string{
Expand Down
8 changes: 4 additions & 4 deletions test/helper/e2e/k8s/pod_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client/config"
k8scfg "sigs.k8s.io/controller-runtime/pkg/client/config"
)

func GetPodLogsByDeployment(deploymentName, deploymentNS string, options corev1.PodLogOptions) ([]byte, error) {
Expand All @@ -24,7 +24,7 @@ func GetPodLogsByDeployment(deploymentName, deploymentNS string, options corev1.
}

func GetPodLogs(options corev1.PodLogOptions, ns string, podName string) ([]byte, error) {
cfg, err := config.GetConfig()
cfg, err := k8scfg.GetConfig()
if err != nil {
return nil, fmt.Errorf("failed to get config: %w", err)
}
Expand All @@ -50,7 +50,7 @@ func GetPodLogs(options corev1.PodLogOptions, ns string, podName string) ([]byte
}

func GetAllDeploymentPods(deploymentName, deploymentNS string) ([]corev1.Pod, error) {
cfg, err := config.GetConfig()
cfg, err := k8scfg.GetConfig()
if err != nil {
return nil, fmt.Errorf("failed to get config: %w", err)
}
Expand All @@ -75,7 +75,7 @@ func GetAllDeploymentPods(deploymentName, deploymentNS string) ([]corev1.Pod, er
}

func GetDeployment(deploymentName, deploymentNS string) (*appsv1.Deployment, error) {
cfg, err := config.GetConfig()
cfg, err := k8scfg.GetConfig()
if err != nil {
return nil, fmt.Errorf("failed to get config: %w", err)
}
Expand Down
Loading