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
24 changes: 23 additions & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ concurrency:

jobs:
test-e2e:
name: E2E Tests
name: E2E Tests (${{ matrix.builder }}/${{ matrix.deployer }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
builder: [pack, s2i]
deployer: [knative, raw, keda]
steps:
- name: Clone the code
uses: actions/checkout@v4
Expand Down Expand Up @@ -50,4 +55,21 @@ jobs:
env:
REGISTRY_INSECURE: true
REGISTRY: kind-registry:5000
DEFAULT_BUILDER: ${{ matrix.builder }}
DEFAULT_DEPLOYER: ${{ matrix.deployer }}
run: make test-e2e

- name: Collect Kubernetes artifacts
if: failure()
run: |
mkdir -p /tmp/k8s-artifacts
kubectl logs -n func-operator-system -l control-plane=controller-manager --tail=-1 --all-containers --prefix --timestamps > /tmp/k8s-artifacts/func-operator.log
kubectl get functions -A -o yaml > /tmp/functions.yaml

- name: Upload Kubernetes artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: func-operator-logs-${{ matrix.builder }}-${{ matrix.deployer }}
path: /tmp/k8s-artifacts/
retention-days: 7
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rules:
- apps
resources:
- deployments
- replicasets
verbs:
- create
- delete
Expand Down
19 changes: 18 additions & 1 deletion internal/controller/function_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type FunctionReconciler struct {
// +kubebuilder:rbac:groups=functions.dev,resources=functions/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=functions.dev,resources=functions/finalizers,verbs=update
// +kubebuilder:rbac:groups="",resources=pods;pods/attach;secrets;services;persistentvolumeclaims,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="apps",resources=deployments,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="apps",resources=deployments;replicasets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="serving.knative.dev",resources=services;routes,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="eventing.knative.dev",resources=triggers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=tekton.dev,resources=pipelines;pipelineruns,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -249,6 +249,7 @@ func (r *FunctionReconciler) setupPipelineRBAC(ctx context.Context, function *v1
func (r *FunctionReconciler) ensureDeployFunctionRole(ctx context.Context, namespace string) error {
logger := log.FromContext(ctx)

// TODO: only add the rules which are needed for the functions deployer
expectedRole := &rbacv1.Role{
ObjectMeta: metav1.ObjectMeta{
Name: deployFunctionRoleName,
Expand All @@ -259,6 +260,22 @@ func (r *FunctionReconciler) ensureDeployFunctionRole(ctx context.Context, names
APIGroups: []string{"serving.knative.dev"},
Resources: []string{"services", "routes"},
Verbs: []string{"create", "delete", "get", "list", "patch", "update", "watch"},
}, {
APIGroups: []string{"eventing.knative.dev"},
Resources: []string{"triggers"},
Verbs: []string{"create", "delete", "get", "list", "patch", "update", "watch"},
}, {
APIGroups: []string{"apps"},
Resources: []string{"deployments", "replicasets"},
Verbs: []string{"create", "delete", "get", "list", "patch", "update", "watch"},
}, {
APIGroups: []string{""},
Resources: []string{"services", "pods"},
Verbs: []string{"create", "delete", "get", "list", "patch", "update", "watch"},
}, {
APIGroups: []string{"http.keda.sh"},
Resources: []string{"httpscaledobjects"},
Verbs: []string{"create", "delete", "get", "list", "patch", "update", "watch"},
},
},
}
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ var _ = Describe("Bundle", Label("bundle"), Ordered, func() {
By("Collecting logs from deployed operators")
for _, testNs := range testNamespaces {
By("Logs from operator in namespace " + testNs.Name)
cmd := exec.Command("kubectl", "logs", "-l", "control-plane=controller-manager", "--namespace", testNs.Name)
cmd := exec.Command(
"kubectl", "logs",
"-l", "control-plane=controller-manager",
"--namespace", testNs.Name,
"-t", "-1")
controllerLogs, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func logFailedTestDetails(functionName, functionNamespace string) {
}

By("Fetching controller manager pod logs")
cmd := exec.Command("kubectl", "logs", "-l", "control-plane=controller-manager", "-n", namespace)
cmd := exec.Command("kubectl", "logs", "-l", "control-plane=controller-manager", "-n", namespace, "-t", "20")
controllerLogs, err := utils.Run(cmd)
if err == nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Controller logs:\n %s", controllerLogs)
Expand Down
8 changes: 3 additions & 5 deletions test/e2e/func_middleware_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ var _ = Describe("Middleware Update", func() {
DeferCleanup(os.RemoveAll, repoDir)

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

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

// 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) {
funcBinary, err := ensureFuncVersion(version)
if err != nil {
return "", err
}

allArgs := append([]string{command}, args...)
cmd := exec.Command(funcBinary, allArgs...)
return Run(cmd)
}

// RunFuncDeploy runs func deploy
func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, error) {
opts := &FuncDeployOptions{
// defaults
Registry: Registry(),
RegistryInsecure: IsRegistryInsecure(),
Builder: os.Getenv("DEFAULT_BUILDER"),
Deployer: os.Getenv("DEFAULT_DEPLOYER"),
}

for _, optFn := range optFns {
Expand All @@ -63,20 +78,11 @@ func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, erro
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) {
funcBinary, err := ensureFuncVersion(version)
if err != nil {
return "", err
if opts.CliVersion != "" {
return RunFuncWithVersion(opts.CliVersion, "deploy", args...)
}

allArgs := append([]string{command}, args...)
cmd := exec.Command(funcBinary, allArgs...)
return Run(cmd)
return RunFunc("deploy", args...)
}

type FuncDeployOptions struct {
Expand All @@ -85,6 +91,7 @@ type FuncDeployOptions struct {
Namespace string
Builder string
Deployer string
CliVersion string
}

type FuncDeployOption func(*FuncDeployOptions)
Expand All @@ -107,6 +114,12 @@ func WithDeployer(deployer string) FuncDeployOption {
}
}

func WithDeployCliVersion(version string) FuncDeployOption {
return func(opts *FuncDeployOptions) {
opts.CliVersion = version
}
}

// ensureFuncVersion ensures the specified func version is available and returns its path
func ensureFuncVersion(version string) (string, error) {
projectDir, err := GetProjectDir()
Expand Down
Loading