Skip to content

Commit a50355b

Browse files
Merge pull request #214 from openshift/synchronize
NO-ISSUE: (Manual) Synchronize From Upstream Repositories
2 parents 74c9198 + f37f9eb commit a50355b

File tree

137 files changed

+10745
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+10745
-355
lines changed

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,32 @@ you can follow the steps below to test your changes:
5959
make kind-load kind-deploy
6060
```
6161

62+
## How to debug controller tests using ENVTEST
63+
64+
[ENVTEST](https://book.kubebuilder.io/reference/envtest) requires k8s binaries to be downloaded to run the tests.
65+
To download the necessary binaries, follow the steps below:
66+
67+
```sh
68+
make envtest-k8s-bins
69+
```
70+
71+
Note that the binaries are downloaded to the `bin/envtest-binaries` directory.
72+
73+
```sh
74+
$ tree
75+
.
76+
├── envtest-binaries
77+
│   └── k8s
78+
│   └── 1.31.0-darwin-arm64
79+
│   ├── etcd
80+
│   ├── kube-apiserver
81+
│   └── kubectl
82+
```
83+
84+
Now, you can debug them with your IDE:
85+
86+
![Screenshot IDE example](https://github.com/user-attachments/assets/3096d524-0686-48ca-911c-5b843093ad1f)
87+
6288
### Communication Channels
6389

6490
- Email: [operator-framework-olm-dev](mailto:[email protected])

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export WAIT_TIMEOUT := 60s
2929
# Install default ClusterCatalogs
3030
export INSTALL_DEFAULT_CATALOGS := true
3131

32-
# By default setup-envtest will write to $XDG_DATA_HOME, or $HOME/.local/share if that is not defined.
32+
# By default setup-envtest binary will write to $XDG_DATA_HOME, or $HOME/.local/share if that is not defined.
3333
# If $HOME is not set, we need to specify a binary directory to prevent an error in setup-envtest.
3434
# Useful for some CI/CD environments that set neither $XDG_DATA_HOME nor $HOME.
35-
SETUP_ENVTEST_BIN_DIR_OVERRIDE=
35+
SETUP_ENVTEST_BIN_DIR_OVERRIDE += --bin-dir $(ROOT_DIR)/bin/envtest-binaries
3636
ifeq ($(shell [[ $$HOME == "" || $$HOME == "/" ]] && [[ $$XDG_DATA_HOME == "" ]] && echo true ), true)
3737
SETUP_ENVTEST_BIN_DIR_OVERRIDE += --bin-dir /tmp/envtest-binaries
3838
endif
@@ -158,19 +158,25 @@ test-ext-dev-e2e: $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension creat
158158
test/extension-developer-e2e/setup.sh $(OPERATOR_SDK) $(CONTAINER_RUNTIME) $(KUSTOMIZE) $(KIND) $(KIND_CLUSTER_NAME) $(E2E_REGISTRY_NAMESPACE)
159159
go test -count=1 -v ./test/extension-developer-e2e/...
160160

161-
.PHONY: test-unit
162161
ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
163162
UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/)
164163
COVERAGE_UNIT_DIR := $(ROOT_DIR)/coverage/unit
165-
test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests
164+
165+
.PHONY: envtest-k8s-bins #HELP Uses setup-envtest to download and install the binaries required to run ENVTEST-test based locally at the project/bin directory.
166+
envtest-k8s-bins: $(SETUP_ENVTEST)
167+
mkdir -p $(ROOT_DIR)/bin
168+
$(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)
169+
170+
.PHONY: test-unit
171+
test-unit: $(SETUP_ENVTEST) envtest-k8s-bins #HELP Run the unit tests
166172
rm -rf $(COVERAGE_UNIT_DIR) && mkdir -p $(COVERAGE_UNIT_DIR)
167-
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && \
173+
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use -p path $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE))" \
168174
CGO_ENABLED=1 go test \
169175
-tags '$(GO_BUILD_TAGS)' \
170176
-cover -coverprofile ${ROOT_DIR}/coverage/unit.out \
171177
-count=1 -race -short \
172178
$(UNIT_TEST_DIRS) \
173-
-test.gocoverdir=$(ROOT_DIR)/coverage/unit
179+
-test.gocoverdir=$(COVERAGE_UNIT_DIR)
174180

175181
.PHONY: image-registry
176182
E2E_REGISTRY_IMAGE=localhost/e2e-test-registry:devel

cmd/manager/main.go

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"context"
21+
"crypto/tls"
2122
"flag"
2223
"fmt"
2324
"net/http"
@@ -41,9 +42,11 @@ import (
4142
"k8s.io/klog/v2/textlogger"
4243
ctrl "sigs.k8s.io/controller-runtime"
4344
crcache "sigs.k8s.io/controller-runtime/pkg/cache"
45+
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
4446
"sigs.k8s.io/controller-runtime/pkg/client"
4547
crfinalizer "sigs.k8s.io/controller-runtime/pkg/finalizer"
4648
"sigs.k8s.io/controller-runtime/pkg/healthz"
49+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
4750
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
4851

4952
catalogd "github.com/operator-framework/catalogd/api/v1"
@@ -70,6 +73,7 @@ import (
7073
var (
7174
setupLog = ctrl.Log.WithName("setup")
7275
defaultSystemNamespace = "olmv1-system"
76+
certWatcher *certwatcher.CertWatcher
7377
)
7478

7579
const authFilePrefix = "operator-controller-global-pull-secrets"
@@ -89,6 +93,8 @@ func podNamespace() string {
8993
func main() {
9094
var (
9195
metricsAddr string
96+
certFile string
97+
keyFile string
9298
enableLeaderElection bool
9399
probeAddr string
94100
cachePath string
@@ -97,9 +103,11 @@ func main() {
97103
caCertDir string
98104
globalPullSecret string
99105
)
100-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
106+
flag.StringVar(&metricsAddr, "metrics-bind-address", "", "The address for the metrics endpoint. Requires tls-cert and tls-key. (Default: ':8443')")
101107
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
102108
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of TLS certificate to use for verifying HTTPS connections to the Catalogd and docker-registry web servers.")
109+
flag.StringVar(&certFile, "tls-cert", "", "The certificate file used for the metrics server. Required to enable the metrics server. Requires tls-key.")
110+
flag.StringVar(&keyFile, "tls-key", "", "The key file used for the metrics server. Required to enable the metrics server. Requires tls-cert")
103111
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
104112
"Enable leader election for controller manager. "+
105113
"Enabling this will ensure there is only one active controller manager.")
@@ -119,6 +127,20 @@ func main() {
119127
os.Exit(0)
120128
}
121129

130+
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
131+
setupLog.Error(nil, "unable to configure TLS certificates: tls-cert and tls-key flags must be used together")
132+
os.Exit(1)
133+
}
134+
135+
if metricsAddr != "" && certFile == "" && keyFile == "" {
136+
setupLog.Error(nil, "metrics-bind-address requires tls-cert and tls-key flags to be set")
137+
os.Exit(1)
138+
}
139+
140+
if certFile != "" && keyFile != "" && metricsAddr == "" {
141+
metricsAddr = ":8443"
142+
}
143+
122144
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
123145

124146
setupLog.Info("starting up the controller", "version info", version.String())
@@ -161,9 +183,49 @@ func main() {
161183
},
162184
}
163185
}
186+
187+
metricsServerOptions := server.Options{}
188+
if len(certFile) > 0 && len(keyFile) > 0 {
189+
setupLog.Info("Starting metrics server with TLS enabled", "addr", metricsAddr, "tls-cert", certFile, "tls-key", keyFile)
190+
191+
metricsServerOptions.BindAddress = metricsAddr
192+
metricsServerOptions.SecureServing = true
193+
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
194+
195+
// If the certificate files change, the watcher will reload them.
196+
var err error
197+
certWatcher, err = certwatcher.New(certFile, keyFile)
198+
if err != nil {
199+
setupLog.Error(err, "Failed to initialize certificate watcher")
200+
os.Exit(1)
201+
}
202+
203+
metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
204+
config.GetCertificate = certWatcher.GetCertificate
205+
// If the enable-http2 flag is false (the default), http/2 should be disabled
206+
// due to its vulnerabilities. More specifically, disabling http/2 will
207+
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
208+
// Rapid Reset CVEs. For more information see:
209+
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
210+
// - https://github.com/advisories/GHSA-4374-p667-p6c8
211+
// Besides, those CVEs are solved already; the solution is still insufficient, and we need to mitigate
212+
// the risks. More info https://github.com/golang/go/issues/63417
213+
config.NextProtos = []string{"http/1.1"}
214+
})
215+
} else {
216+
// Note that the metrics server is not serving if the BindAddress is set to "0".
217+
// Therefore, the metrics server is disabled by default. It is only enabled
218+
// if certFile and keyFile are provided. The intention is not allowing the metrics
219+
// be served with the default self-signed certificate generated by controller-runtime.
220+
metricsServerOptions.BindAddress = "0"
221+
222+
setupLog.Info("WARNING: Metrics Server is disabled. " +
223+
"Metrics will not be served since the TLS certificate and key file are not provided.")
224+
}
225+
164226
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
165227
Scheme: scheme.Scheme,
166-
Metrics: server.Options{BindAddress: metricsAddr},
228+
Metrics: metricsServerOptions,
167229
HealthProbeBindAddress: probeAddr,
168230
LeaderElection: enableLeaderElection,
169231
LeaderElectionID: "9c4404e7.operatorframework.io",
@@ -220,6 +282,14 @@ func main() {
220282
os.Exit(1)
221283
}
222284

285+
if certWatcher != nil {
286+
setupLog.Info("Adding certificate watcher to manager")
287+
if err := mgr.Add(certWatcher); err != nil {
288+
setupLog.Error(err, "unable to add certificate watcher to manager")
289+
os.Exit(1)
290+
}
291+
}
292+
223293
unpacker := &source.ContainersImageRegistry{
224294
BaseCachePath: filepath.Join(cachePath, "unpack"),
225295
SourceContextFunc: func(logger logr.Logger) (*types.SystemContext, error) {

commitchecker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
expectedMergeBase: 45f86cbcb2ffb3121d3708d6e33732427a339460
1+
expectedMergeBase: 2c812aaf385ffe786538a2ef4928bd23feb58a74
22
upstreamBranch: main
33
upstreamOrg: operator-framework
44
upstreamRepo: operator-controller

config/base/kustomization.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ resources:
1818
- crd
1919
- rbac
2020
- manager
21-
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
22-
#- ../prometheus
21+
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
resources:
2-
- manager.yaml
31
apiVersion: kustomize.config.k8s.io/v1beta1
42
kind: Kustomization
3+
4+
resources:
5+
- manager.yaml
6+
- service.yaml
7+
58
images:
69
- name: controller
710
newName: quay.io/operator-framework/operator-controller
8-
newTag: devel
11+
newTag: devel

config/base/manager/manager.yaml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ spec:
5252
- /manager
5353
args:
5454
- "--health-probe-bind-address=:8081"
55-
- "--metrics-bind-address=127.0.0.1:8080"
55+
- "--metrics-bind-address=:8443"
5656
- "--leader-elect"
5757
image: controller:latest
5858
imagePullPolicy: IfNotPresent
@@ -84,27 +84,6 @@ spec:
8484
cpu: 10m
8585
memory: 64Mi
8686
terminationMessagePolicy: FallbackToLogsOnError
87-
- name: kube-rbac-proxy
88-
securityContext:
89-
allowPrivilegeEscalation: false
90-
capabilities:
91-
drop:
92-
- "ALL"
93-
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0
94-
args:
95-
- --secure-listen-address=0.0.0.0:8443
96-
- --http2-disable
97-
- --upstream=http://127.0.0.1:8080/
98-
- --logtostderr=true
99-
ports:
100-
- containerPort: 8443
101-
protocol: TCP
102-
name: https
103-
resources:
104-
requests:
105-
cpu: 5m
106-
memory: 64Mi
107-
terminationMessagePolicy: FallbackToLogsOnError
10887
serviceAccountName: operator-controller-controller-manager
10988
terminationGracePeriodSeconds: 10
11089
volumes:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4+
name: service
5+
namespace: system
46
labels:
57
control-plane: operator-controller-controller-manager
6-
name: controller-manager-metrics-service
7-
namespace: system
88
spec:
99
ports:
1010
- name: https
1111
port: 8443
1212
protocol: TCP
13-
targetPort: https
13+
targetPort: 8443
1414
selector:
1515
control-plane: operator-controller-controller-manager

config/base/prometheus/kustomization.yaml

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

config/base/prometheus/monitor.yaml

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

0 commit comments

Comments
 (0)