Skip to content

Commit 488094f

Browse files
authored
Merge branch 'main' into remove-prometheus-dependency
2 parents 417217b + 33d5fd0 commit 488094f

14 files changed

Lines changed: 622 additions & 55 deletions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Bundle E2E Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-bundle-e2e:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Install the latest version of kind
21+
run: |
22+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
23+
chmod +x ./kind
24+
sudo mv ./kind /usr/local/bin/kind
25+
26+
- name: Verify kind installation
27+
run: kind version
28+
29+
- name: Install helm
30+
uses: azure/setup-helm@v4.3.0
31+
32+
# func CLI is needed in some e2e tests ATM
33+
- name: Install func cli
34+
uses: functions-dev/action@main
35+
with:
36+
version: nightly # use nightly as long as we use the latest in the operator too
37+
38+
- name: Setup KinD cluster
39+
run: make create-kind-cluster
40+
41+
- name: Running Bundle Test e2e
42+
env:
43+
REGISTRY_INSECURE: true
44+
REGISTRY: kind-registry:5000
45+
run: make test-e2e-bundle

.github/workflows/test-e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
# func CLI is needed in some e2e tests ATM
3333
- name: Install func cli
3434
uses: functions-dev/action@main
35+
with:
36+
version: nightly # use nightly as long as we use the latest in the operator too
3537

3638
- name: Setup KinD cluster
3739
run: make create-kind-cluster

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
120120

121121
.PHONY: test-e2e ## Run e2e tests.
122122
test-e2e:
123-
go test ./test/e2e/ -v -ginkgo.v
123+
go test ./test/e2e/ -v -ginkgo.v -ginkgo.timeout=1h -ginkgo.label-filter="!bundle"
124+
125+
.PHONY: test-e2e-bundle ## Run bundle e2e tests.
126+
test-e2e-bundle: operator-sdk docker-build docker-push bundle bundle-build bundle-push install-olm-in-cluster
127+
OPERATOR_SDK=$(OPERATOR_SDK) BUNDLE_IMG=$(BUNDLE_IMG) go test -timeout 1h ./test/e2e/ -v -ginkgo.v -ginkgo.timeout=1h -ginkgo.label-filter="bundle"
128+
129+
.PHONY: install-olm-in-cluster
130+
install-olm-in-cluster: operator-sdk ## Install OLM in cluster if not already installed.
131+
@$(OPERATOR_SDK) olm status || $(OPERATOR_SDK) olm install
124132

125133
.PHONY: lint
126134
lint: golangci-lint ## Run golangci-lint linter
@@ -381,4 +389,4 @@ catalog-push: ## Push a catalog image.
381389

382390
.PHONY: mocksgen
383391
gen-mocks: ${MOCKERY}
384-
${MOCKERY}
392+
${MOCKERY}

cmd/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import (
2222
"flag"
2323
"os"
2424
"path/filepath"
25+
"strings"
2526
"time"
2627

2728
"github.com/functions-dev/func-operator/internal/git"
2829
"github.com/functions-dev/func-operator/internal/monitoring"
30+
"sigs.k8s.io/controller-runtime/pkg/cache"
2931

3032
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
3133
// to ensure that exec-entrypoint and run can make use of them.
@@ -194,6 +196,20 @@ func main() {
194196
})
195197
}
196198

199+
watchNamespaces := getWatchNamespaces()
200+
var cacheOpts cache.Options
201+
if len(watchNamespaces) > 0 {
202+
setupLog.Info("Operator watching specific namespaces", "namespaces", watchNamespaces)
203+
204+
// Map the namespaces into the Cache DefaultNamespaces map
205+
cacheOpts.DefaultNamespaces = make(map[string]cache.Config)
206+
for _, ns := range watchNamespaces {
207+
cacheOpts.DefaultNamespaces[strings.TrimSpace(ns)] = cache.Config{}
208+
}
209+
} else {
210+
setupLog.Info("Operator watching all namespaces")
211+
}
212+
197213
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
198214
Scheme: scheme,
199215
Metrics: metricsServerOptions,
@@ -212,6 +228,7 @@ func main() {
212228
// if you are doing or is intended to do any operation such as perform cleanups
213229
// after the manager stops then its usage might be unsafe.
214230
// LeaderElectionReleaseOnCancel: true,
231+
Cache: cacheOpts,
215232
})
216233
if err != nil {
217234
setupLog.Error(err, "unable to start manager")
@@ -282,3 +299,15 @@ func main() {
282299
os.Exit(1)
283300
}
284301
}
302+
303+
// getWatchNamespaces returns the Namespaces the operator should be watching for changes
304+
func getWatchNamespaces() []string {
305+
watchNamespaceEnvVar := "WATCH_NAMESPACE"
306+
ns, found := os.LookupEnv(watchNamespaceEnvVar)
307+
if !found || ns == "" {
308+
return nil // Return nil to signify "watch all namespaces"
309+
}
310+
311+
// Split by comma to support multiple namespaces
312+
return strings.Split(ns, ",")
313+
}

config/manager/manager.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ spec:
6565
- --health-probe-bind-address=:8081
6666
- --disable-func-cli-update=true
6767
- --func-cli-path=/func
68+
env:
69+
- name: WATCH_NAMESPACE
70+
valueFrom:
71+
fieldRef:
72+
fieldPath: metadata.annotations['olm.targetNamespaces']
6873
image: controller:latest
6974
imagePullPolicy: Always
7075
name: manager

config/manifests/bases/func-operator.clusterserviceversion.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ spec:
2525
deployments: null
2626
strategy: ""
2727
installModes:
28-
- supported: false
28+
- supported: true
2929
type: OwnNamespace
30-
- supported: false
30+
- supported: true
3131
type: SingleNamespace
32-
- supported: false
32+
- supported: true
3333
type: MultiNamespace
3434
- supported: true
3535
type: AllNamespaces

config/rbac/deploy_function_clusterrole.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

config/rbac/deploy_function_clusterrole_binding.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

config/rbac/kustomization.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,3 @@ resources:
2626
- function_editor_role.yaml
2727
- function_viewer_role.yaml
2828

29-
- deploy_function_clusterrole.yaml
30-
- deploy_function_clusterrole_binding.yaml
31-

config/rbac/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ rules:
8484
- rbac.authorization.k8s.io
8585
resources:
8686
- rolebindings
87+
- roles
8788
verbs:
8889
- create
8990
- delete
@@ -95,6 +96,7 @@ rules:
9596
- apiGroups:
9697
- serving.knative.dev
9798
resources:
99+
- routes
98100
- services
99101
verbs:
100102
- create

0 commit comments

Comments
 (0)