Skip to content
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
18 changes: 7 additions & 11 deletions test/e2e/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("Bundle", Label("bundle"), Ordered, func() {
out, err := utils.OperatorSdkRun("run", "bundle",
"--namespace", testNamespaces[0].Name,
"--install-mode", "OwnNamespace",
fmt.Sprintf("--skip-tls-verify=%v", registryInsecure),
fmt.Sprintf("--skip-tls-verify=%v", utils.IsRegistryInsecure()),
bundleImage)
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)
Expand Down Expand Up @@ -129,7 +129,7 @@ var _ = Describe("Bundle", Label("bundle"), Ordered, func() {
out, err := utils.OperatorSdkRun("run", "bundle",
"--namespace", testNamespaces[0].Name,
"--install-mode", fmt.Sprintf("SingleNamespace=%s", testNamespaces[1].Name),
fmt.Sprintf("--skip-tls-verify=%v", registryInsecure),
fmt.Sprintf("--skip-tls-verify=%v", utils.IsRegistryInsecure()),
bundleImage)
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)
Expand Down Expand Up @@ -169,7 +169,7 @@ var _ = Describe("Bundle", Label("bundle"), Ordered, func() {
out, err := utils.OperatorSdkRun("run", "bundle",
"--namespace", testNamespaces[0].Name,
"--install-mode", fmt.Sprintf("MultiNamespace=%s,%s", testNamespaces[1].Name, testNamespaces[2].Name),
fmt.Sprintf("--skip-tls-verify=%v", registryInsecure),
fmt.Sprintf("--skip-tls-verify=%v", utils.IsRegistryInsecure()),
bundleImage)
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)
Expand Down Expand Up @@ -209,7 +209,7 @@ var _ = Describe("Bundle", Label("bundle"), Ordered, func() {
out, err := utils.OperatorSdkRun("run", "bundle",
"--namespace", testNamespaces[0].Name,
"--install-mode", fmt.Sprintf("SingleNamespace=%s", testNamespaces[1].Name),
fmt.Sprintf("--skip-tls-verify=%v", registryInsecure),
fmt.Sprintf("--skip-tls-verify=%v", utils.IsRegistryInsecure()),
bundleImage)
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)
Expand All @@ -218,7 +218,7 @@ var _ = Describe("Bundle", Label("bundle"), Ordered, func() {
out, err = utils.OperatorSdkRun("run", "bundle",
"--namespace", testNamespaces[2].Name,
"--install-mode", fmt.Sprintf("SingleNamespace=%s", testNamespaces[3].Name),
fmt.Sprintf("--skip-tls-verify=%v", registryInsecure),
fmt.Sprintf("--skip-tls-verify=%v", utils.IsRegistryInsecure()),
bundleImage)
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)
Expand Down Expand Up @@ -266,7 +266,7 @@ var _ = Describe("Bundle", Label("bundle"), Ordered, func() {
out, err := utils.OperatorSdkRun("run", "bundle",
"--namespace", testNamespaces[0].Name,
"--install-mode", "AllNamespaces",
fmt.Sprintf("--skip-tls-verify=%v", registryInsecure),
fmt.Sprintf("--skip-tls-verify=%v", utils.IsRegistryInsecure()),
bundleImage)
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)
Expand Down Expand Up @@ -363,11 +363,7 @@ func createNamespaceAndDeployFunction() TestNamespace {
DeferCleanup(os.RemoveAll, repoDir)

// Deploy function
out, err := utils.RunFunc("deploy",
"--namespace", ns,
"--path", repoDir,
"--registry", registry,
fmt.Sprintf("--registry-insecure=%t", registryInsecure))
out, err := utils.RunFuncDeploy(repoDir, utils.WithNamespace(ns))
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)

Expand Down
16 changes: 0 additions & 16 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package e2e
import (
"context"
"fmt"
"os"
"strings"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -37,9 +35,6 @@ var (
k8sClient client.Client
ctx context.Context

registry string
registryInsecure bool

repoProvider utils.RepositoryProvider
)

Expand Down Expand Up @@ -72,17 +67,6 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())

// Setup vars from env
registry = os.Getenv("REGISTRY")
if registry == "" {
registry = "kind-registry:5000"
}

registryInsecure = false
if sec := os.Getenv("REGISTRY_INSECURE"); strings.ToLower(sec) == "true" {
registryInsecure = true
}

// Initialize repository provider (Gitea)
repoProvider, err = utils.NewGiteaClient()
Expect(err).NotTo(HaveOccurred())
Expand Down
25 changes: 9 additions & 16 deletions test/e2e/func_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ var _ = Describe("Operator", func() {
DeferCleanup(cleanupNamespaces, functionNamespace)

// Deploy function using func CLI
out, err := utils.RunFunc("deploy",
"--namespace", functionNamespace,
"--path", repoDir,
"--registry", registry,
fmt.Sprintf("--registry-insecure=%t", registryInsecure))
out, err := utils.RunFuncDeploy(repoDir, utils.WithNamespace(functionNamespace))
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)

Expand Down Expand Up @@ -223,7 +219,12 @@ var _ = Describe("Operator", func() {
DeferCleanup(cleanup)

// Initialize repository with function code
repoDir, err = utils.InitializeRepoWithFunctionInSubDir(repoURL, subPath, username, password, "go")
repoDir, err = utils.InitializeRepoWithFunction(
repoURL,
username,
password,
"go",
utils.WithSubDir(subPath))
Expect(err).NotTo(HaveOccurred())
DeferCleanup(os.RemoveAll, repoDir)

Expand All @@ -234,11 +235,7 @@ var _ = Describe("Operator", func() {
functionDir := filepath.Join(repoDir, subPath)

// Deploy function using func CLI
out, err := utils.RunFunc("deploy",
"--namespace", functionNamespace,
"--path", functionDir,
"--registry", registry,
fmt.Sprintf("--registry-insecure=%t", registryInsecure))
out, err := utils.RunFuncDeploy(functionDir, utils.WithNamespace(functionNamespace))
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)

Expand Down Expand Up @@ -378,11 +375,7 @@ var _ = Describe("Operator", func() {
DeferCleanup(cleanupNamespaces, functionNamespace)

// Deploy function using func CLI
out, err := utils.RunFunc("deploy",
"--namespace", functionNamespace,
"--path", repoDir,
"--registry", registry,
fmt.Sprintf("--registry-insecure=%t", registryInsecure))
out, err := utils.RunFuncDeploy(repoDir, utils.WithNamespace(functionNamespace))
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)

Expand Down
11 changes: 8 additions & 3 deletions test/e2e/func_middleware_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,21 @@ var _ = Describe("Middleware Update", func() {
// Initialize repository with function code using OLD func CLI version
// v1.20.1 has no middleware-version label and uses instance-compatible templates
oldFuncVersion := "v1.20.1"
repoDir, err = utils.InitializeRepoWithFunctionVersion(repoURL, ".", username, password, "go", oldFuncVersion)
repoDir, err = utils.InitializeRepoWithFunction(
repoURL,
username,
password,
"go",
utils.WithCliVersion(oldFuncVersion))
Expect(err).NotTo(HaveOccurred())
DeferCleanup(os.RemoveAll, repoDir)

// Deploy function using the same OLD func CLI version
out, err := utils.RunFuncWithVersion(oldFuncVersion, "deploy",
"--namespace", functionNamespace,
"--path", repoDir,
"--registry", registry,
fmt.Sprintf("--registry-insecure=%t", registryInsecure))
"--registry", utils.Registry(),
fmt.Sprintf("--registry-insecure=%t", utils.IsRegistryInsecure()))
Expect(err).NotTo(HaveOccurred())
_, _ = fmt.Fprint(GinkgoWriter, out)

Expand Down
61 changes: 61 additions & 0 deletions test/utils/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ func RunFunc(command string, args ...string) (string, error) {
return Run(cmd)
}

// RunFuncDeploy runs func deploy
func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, error) {
opts := &FuncDeployOptions{
// defaults
Registry: Registry(),
RegistryInsecure: IsRegistryInsecure(),
}

for _, optFn := range optFns {
optFn(opts)
}

args := []string{
"--path", functionDir,
"--registry", opts.Registry,
fmt.Sprintf("--registry-insecure=%t", opts.RegistryInsecure),
}

if opts.Namespace != "" {
args = append(args, "--namespace", opts.Namespace)
}

if opts.Builder != "" {
args = append(args, "--builder", opts.Builder)
}

if opts.Deployer != "" {
args = append(args, "--deployer", opts.Deployer)
}

return RunFunc("deploy", args...)
}

// RunFuncWithVersion executes the func CLI with a specific version
// It downloads and caches the version if not already present
func RunFuncWithVersion(version string, command string, args ...string) (string, error) {
Expand All @@ -46,6 +79,34 @@ func RunFuncWithVersion(version string, command string, args ...string) (string,
return Run(cmd)
}

type FuncDeployOptions struct {
Registry string
RegistryInsecure bool
Namespace string
Builder string
Deployer string
}

type FuncDeployOption func(*FuncDeployOptions)

func WithNamespace(namespace string) FuncDeployOption {
return func(opts *FuncDeployOptions) {
opts.Namespace = namespace
}
}

func WithBuilder(builder string) FuncDeployOption {
return func(o *FuncDeployOptions) {
o.Builder = builder
}
}

func WithDeployer(deployer string) FuncDeployOption {
return func(o *FuncDeployOptions) {
o.Deployer = deployer
}
}

// ensureFuncVersion ensures the specified func version is available and returns its path
func ensureFuncVersion(version string) (string, error) {
projectDir, err := GetProjectDir()
Expand Down
36 changes: 24 additions & 12 deletions test/utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,45 @@ func buildAuthURL(repoURL, username, password string) string {
fmt.Sprintf("http://%s:%s@", username, password), 1)
}

// InitializeRepoWithFunction creates a function project and pushes it to the Gitea repo
func InitializeRepoWithFunction(repoURL, username, password, language string) (string, error) {
return InitializeRepoWithFunctionVersion(repoURL, ".", username, password, language, "")
type RepoOptions struct {
SubDir string
CliVersion string
}

// InitializeRepoWithFunctionInSubDir creates a function project in a repos subdirectory and pushes it to the Gitea repo
func InitializeRepoWithFunctionInSubDir(repoURL, subDir, username, password, language string) (string, error) {
return InitializeRepoWithFunctionVersion(repoURL, subDir, username, password, language, "")
type RepoOption func(*RepoOptions)

func WithSubDir(subDir string) RepoOption {
return func(o *RepoOptions) {
o.SubDir = subDir
}
}
func WithCliVersion(cliVersion string) RepoOption {
return func(o *RepoOptions) {
o.CliVersion = cliVersion
}
}

// InitializeRepoWithFunctionVersion creates a function project with a specific func CLI version
// If version is empty, uses the current func CLI
func InitializeRepoWithFunctionVersion(repoURL, subdir, username, password, language, version string) (string, error) {
// InitializeRepoWithFunction creates a function project and pushes it to the Gitea repo
func InitializeRepoWithFunction(repoURL, username, password, language string, optFns ...RepoOption) (string, error) {
opts := &RepoOptions{}
for _, fn := range optFns {
fn(opts)
}

repoDir := fmt.Sprintf("%s/func-test-%s", os.TempDir(), rand.String(10))

// Build authenticated URL
authURL := buildAuthURL(repoURL, username, password)

functionPath := filepath.Join(repoDir, subdir)
functionPath := filepath.Join(repoDir, opts.SubDir)

// Initialize function (func init creates the directory)
if version == "" {
if opts.CliVersion == "" {
if _, err := RunFunc("init", "-l", language, functionPath); err != nil {
return "", fmt.Errorf("failed to init function: %w", err)
}
} else {
if _, err := RunFuncWithVersion(version, "init", "-l", language, functionPath); err != nil {
if _, err := RunFuncWithVersion(opts.CliVersion, "init", "-l", language, functionPath); err != nil {
return "", fmt.Errorf("failed to init function: %w", err)
}
}
Expand Down
41 changes: 41 additions & 0 deletions test/utils/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package utils

import (
"os"
"strings"
"sync"
)

var (
registry string
registryInsecure bool
)

var registryOnce sync.Once

// Registry returns the registry used for the e2e tests
func Registry() string {
registryOnce.Do(func() {
// Setup vars from env
registry = os.Getenv("REGISTRY")
if registry == "" {
registry = "kind-registry:5000"
}
})

return registry
}

var registryInsecureOnce sync.Once

// IsRegistryInsecure returns if the registry for the e2e tests is insecure (no TLS verify)
func IsRegistryInsecure() bool {
registryInsecureOnce.Do(func() {
registryInsecure = false
if sec := os.Getenv("REGISTRY_INSECURE"); strings.ToLower(sec) == "true" {
registryInsecure = true
}
})

return registryInsecure
}
Loading