Skip to content

Commit

Permalink
Add ginkgo label filter for e2e test failpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
soma00333 committed Jan 22, 2025
1 parent 9ca7ae3 commit e8138a3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 198 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
exit 1; \
}
go test ./test/e2e/ -v -ginkgo.v
go test ./test/e2e/ -v -ginkgo.v -ginkgo.skip="failpoint"

.PHONY: test-e2e-failpoint
test-e2e-failpoint: manifests generate fmt vet ## Run the e2e tests using gofail. Expected an isolated environment using Kind.
Expand All @@ -90,7 +90,7 @@ test-e2e-failpoint: manifests generate fmt vet ## Run the e2e tests using gofail
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
exit 1; \
}
go test ./test/e2e_failpoint/ -v -ginkgo.v
go test ./test/e2e_failpoint/ -v -ginkgo.v -ginkgo.label-filter="failpoint"

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e_failpoint
package e2e

import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -31,19 +28,7 @@ import (
gofail "go.etcd.io/gofail/runtime"
)

// namespace where the project is deployed in
const namespace = "etcd-operator-system"

// serviceAccountName created for the project
const serviceAccountName = "etcd-operator-controller-manager"

// metricsServiceName is the name of the metrics service of the project
const metricsServiceName = "etcd-operator-controller-manager-metrics-service"

// metricsRoleBindingName is the name of the RBAC that will be created to allow get the metrics data
const metricsRoleBindingName = "etcd-operator-metrics-binding"

var _ = Describe("Manager", Ordered, func() {
var _ = Describe("Manager", Label("failpoint"), Ordered, func() {
// Temp
err := gofail.Enable("CrashAfterAddMember", `return("hello")`)
if err != nil {
Expand Down Expand Up @@ -252,62 +237,3 @@ var _ = Describe("Manager", Ordered, func() {
// ))
})
})

// serviceAccountToken returns a token for the specified service account in the given namespace.
// It uses the Kubernetes TokenRequest API to generate a token by directly sending a request
// and parsing the resulting token from the API response.
func serviceAccountToken() (string, error) {
const tokenRequestRawString = `{
"apiVersion": "authentication.k8s.io/v1",
"kind": "TokenRequest"
}`

// Temporary file to store the token request
secretName := fmt.Sprintf("%s-token-request", serviceAccountName)
tokenRequestFile := filepath.Join("/tmp", secretName)
err := os.WriteFile(tokenRequestFile, []byte(tokenRequestRawString), os.FileMode(0o644))
if err != nil {
return "", err
}

var out string
verifyTokenCreation := func(g Gomega) {
// Execute kubectl command to create the token
cmd := exec.Command("kubectl", "create", "--raw", fmt.Sprintf(
"/api/v1/namespaces/%s/serviceaccounts/%s/token",
namespace,
serviceAccountName,
), "-f", tokenRequestFile)

output, err := cmd.CombinedOutput()
g.Expect(err).NotTo(HaveOccurred())

// Parse the JSON output to extract the token
var token tokenRequest
err = json.Unmarshal(output, &token)
g.Expect(err).NotTo(HaveOccurred())

out = token.Status.Token
}
Eventually(verifyTokenCreation).Should(Succeed())

return out, err
}

// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
func getMetricsOutput() string {
By("getting the curl-metrics logs")
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
metricsOutput, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
return metricsOutput
}

// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,
// containing only the token field that we need to extract.
type tokenRequest struct {
Status struct {
Token string `json:"token"`
} `json:"status"`
}
120 changes: 0 additions & 120 deletions test/e2e_failpoint/failpoint_suite_test.go

This file was deleted.

0 comments on commit e8138a3

Please sign in to comment.