Skip to content

Commit b355af5

Browse files
zmotsoSergK
authored andcommitted
chore: Update Operator SDK from v1.39.2 to v1.42.0 (#252)
1 parent 03b9e22 commit b355af5

File tree

46 files changed

+2998
-861
lines changed

Some content is hidden

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

46 files changed

+2998
-861
lines changed

.github/workflows/codecov.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v5
14+
- uses: actions/checkout@v6
1515

1616
- name: Set up Go
1717
uses: actions/setup-go@v6

.github/workflows/codeql.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ jobs:
2929

3030
steps:
3131
- name: Checkout repository
32-
uses: actions/checkout@v4
32+
uses: actions/checkout@v6
3333

3434
# Initializes the CodeQL tools for scanning.
3535
- name: Initialize CodeQL
36-
uses: github/codeql-action/init@v3
36+
uses: github/codeql-action/init@v4
3737
with:
3838
languages: ${{ matrix.language }}
3939
build-mode: manual
@@ -44,6 +44,6 @@ jobs:
4444
make build
4545
4646
- name: Perform CodeQL Analysis
47-
uses: github/codeql-action/analyze@v3
47+
uses: github/codeql-action/analyze@v4
4848
with:
4949
category: "/language:${{ matrix.language }}"

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
steps:
1919
- name: Check out code into the Go module directory
20-
uses: actions/checkout@v5
20+
uses: actions/checkout@v6
2121

2222
- name: Set up Go
2323
uses: actions/setup-go@v6

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
SOURCE_TAG: ${{ github.ref }}
1717
steps:
1818
- name: Checkout code
19-
uses: actions/checkout@v5
19+
uses: actions/checkout@v6
2020
with:
2121
fetch-depth: '0'
2222

.mockery.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
with-expecter: True
2-
inpackage: False
3-
dir: "{{.InterfaceDir}}/mocks"
4-
mockname: "Mock{{.InterfaceName}}"
5-
outpkg: "mocks"
6-
filename: "{{.InterfaceName | lower}}_mock.go"
7-
issue-845-fix: True
8-
disable-version-string: True
9-
resolve-type-alias: False
1+
all: true
2+
dir: '{{.InterfaceDir}}/mocks'
3+
structname: Mock{{.InterfaceName}}
4+
pkgname: mocks
5+
template: testify
6+
filename: "{{ .InterfaceName | snakecase }}_generated.mock.go"
7+
template-data:
8+
unroll-variadic: true
109
packages:
1110
github.com/epam/edp-codebase-operator/v2/controllers/cdstagedeploy/chain:
1211
interfaces:

Makefile

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ validate-docs: api-docs helm-docs ## Validate helm and api docs
8585
@git diff -s --exit-code docs/api.md || (echo " Run 'make api-docs' to address the issue." && git diff && exit 1)
8686

8787
# Run tests
88-
test: fmt vet envtest
88+
test: fmt vet setup-envtest
8989
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
9090
KUBECONFIG=${CURRENT_DIR}/hack/kubecfg-stub.yaml go test ./... -coverprofile=coverage.out
9191

@@ -142,16 +142,16 @@ install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~
142142
##@ Build Dependencies
143143

144144
## Tool Versions
145-
KUSTOMIZE_VERSION ?= v5.4.3
146-
CONTROLLER_TOOLS_VERSION ?= v0.16.5
147-
ENVTEST_VERSION ?= release-0.19
145+
KUSTOMIZE_VERSION ?= v5.6.0
146+
CONTROLLER_TOOLS_VERSION ?= v0.18.0
147+
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
148+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
148149
GOLANGCI_LINT_VERSION ?= v1.64.7
149-
MOCKERY_VERSION ?= v2.53.2
150+
MOCKERY_VERSION ?= v3.6.2
150151
HELMDOCS_VERSION ?= v1.14.2
151152
GITCHGLOG_VERSION ?= v0.15.4
152153
CRDOC_VERSION ?= v0.6.4
153-
ENVTEST_K8S_VERSION = 1.31.0
154-
OPERATOR_SDK_VERSION ?= v1.39.2
154+
OPERATOR_SDK_VERSION ?= v1.42.0
155155

156156
KUSTOMIZE ?= $(LOCALBIN)/kustomize
157157
.PHONY: kustomize
@@ -202,9 +202,17 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada
202202
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
203203
$(OPERATOR_SDK) bundle validate ./bundle
204204

205-
ENVTEST=$(LOCALBIN)/setup-envtest
205+
.PHONY: setup-envtest
206+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
207+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
208+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
209+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
210+
exit 1; \
211+
}
212+
213+
ENVTEST ?= $(LOCALBIN)/setup-envtest
206214
.PHONY: envtest
207-
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
215+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
208216
$(ENVTEST): $(LOCALBIN)
209217
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
210218

@@ -214,7 +222,7 @@ mocks: mockery
214222
MOCKERY = $(LOCALBIN)/mockery
215223
.PHONY: mockery
216224
mockery: ## Download mockery locally if necessary.
217-
$(call go-install-tool,$(MOCKERY),github.com/vektra/mockery/v2,$(MOCKERY_VERSION))
225+
$(call go-install-tool,$(MOCKERY),github.com/vektra/mockery/v3,$(MOCKERY_VERSION))
218226

219227
.PHONY: operator-sdk
220228
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk

cmd/main.go

Lines changed: 121 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/tls"
66
"flag"
77
"os"
8+
"path/filepath"
89
"strconv"
910
"time"
1011

@@ -21,9 +22,12 @@ import (
2122
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2223
ctrl "sigs.k8s.io/controller-runtime"
2324
"sigs.k8s.io/controller-runtime/pkg/cache"
25+
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
2426
"sigs.k8s.io/controller-runtime/pkg/healthz"
2527
"sigs.k8s.io/controller-runtime/pkg/log/zap"
28+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
2629
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
30+
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
2731

2832
cdPipeApi "github.com/epam/edp-cd-pipeline-operator/v2/api/v1"
2933
buildInfo "github.com/epam/edp-common/pkg/config"
@@ -59,20 +63,31 @@ const (
5963

6064
func main() {
6165
var (
62-
metricsAddr string
63-
enableLeaderElection bool
64-
probeAddr string
65-
secureMetrics bool
66-
enableHTTP2 bool
66+
metricsAddr string
67+
metricsCertPath, metricsCertName, metricsCertKey string
68+
webhookCertPath, webhookCertName, webhookCertKey string
69+
enableLeaderElection bool
70+
probeAddr string
71+
secureMetrics bool
72+
enableHTTP2 bool
73+
tlsOpts []func(*tls.Config)
6774
)
6875

69-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
76+
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
77+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
7078
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7179
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
7280
"Enable leader election for controller manager. "+
7381
"Enabling this will ensure there is only one active controller manager.")
74-
flag.BoolVar(&secureMetrics, "metrics-secure", false,
75-
"If set the metrics endpoint is served securely")
82+
flag.BoolVar(&secureMetrics, "metrics-secure", true,
83+
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
84+
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
85+
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
86+
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
87+
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
88+
"The directory that contains the metrics server certificate.")
89+
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
90+
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
7691
flag.BoolVar(&enableHTTP2, "enable-http2", false,
7792
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
7893

@@ -90,7 +105,7 @@ func main() {
90105

91106
// if the enable-http2 flag is false (the default), http/2 should be disabled
92107
// due to its vulnerabilities. More specifically, disabling http/2 will
93-
// prevent from being vulnerable to the HTTP/2 Stream Cancelation and
108+
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
94109
// Rapid Reset CVEs. For more information see:
95110
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
96111
// - https://github.com/advisories/GHSA-4374-p667-p6c8
@@ -100,11 +115,86 @@ func main() {
100115
c.NextProtos = []string{"http/1.1"}
101116
}
102117

103-
var tlsOpts []func(*tls.Config)
104118
if !enableHTTP2 {
105119
tlsOpts = append(tlsOpts, disableHTTP2)
106120
}
107121

122+
// Create watchers for metrics and webhooks certificates
123+
var metricsCertWatcher, webhookCertWatcher *certwatcher.CertWatcher
124+
125+
// Initial webhook TLS options
126+
webhookTLSOpts := tlsOpts
127+
128+
if len(webhookCertPath) > 0 {
129+
setupLog.Info("Initializing webhook certificate watcher using provided certificates",
130+
"webhook-cert-path", webhookCertPath, "webhook-cert-name", webhookCertName, "webhook-cert-key", webhookCertKey)
131+
132+
var err error
133+
134+
webhookCertWatcher, err = certwatcher.New(
135+
filepath.Join(webhookCertPath, webhookCertName),
136+
filepath.Join(webhookCertPath, webhookCertKey),
137+
)
138+
if err != nil {
139+
setupLog.Error(err, "Failed to initialize webhook certificate watcher")
140+
os.Exit(1)
141+
}
142+
143+
webhookTLSOpts = append(webhookTLSOpts, func(config *tls.Config) {
144+
config.GetCertificate = webhookCertWatcher.GetCertificate
145+
})
146+
}
147+
148+
webhookServer := ctrlwebhook.NewServer(ctrlwebhook.Options{
149+
TLSOpts: webhookTLSOpts,
150+
})
151+
152+
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
153+
// More info:
154+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/server
155+
// - https://book.kubebuilder.io/reference/metrics.html
156+
metricsServerOptions := metricsserver.Options{
157+
BindAddress: metricsAddr,
158+
SecureServing: secureMetrics,
159+
TLSOpts: tlsOpts,
160+
}
161+
162+
if secureMetrics {
163+
// FilterProvider is used to protect the metrics endpoint with authn/authz.
164+
// These configurations ensure that only authorized users and service accounts
165+
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info:
166+
// https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/filters#WithAuthenticationAndAuthorization
167+
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
168+
}
169+
170+
// If the certificate is not specified, controller-runtime will automatically
171+
// generate self-signed certificates for the metrics server. While convenient for development and testing,
172+
// this setup is not recommended for production.
173+
//
174+
// TODO(user): If you enable certManager, uncomment the following lines:
175+
// - [METRICS-WITH-CERTS] at config/default/kustomization.yaml to generate and use certificates
176+
// managed by cert-manager for the metrics server.
177+
// - [PROMETHEUS-WITH-CERTS] at config/prometheus/kustomization.yaml for TLS certification.
178+
if len(metricsCertPath) > 0 {
179+
setupLog.Info("Initializing metrics certificate watcher using provided certificates",
180+
"metrics-cert-path", metricsCertPath, "metrics-cert-name", metricsCertName, "metrics-cert-key", metricsCertKey)
181+
182+
var err error
183+
184+
metricsCertWatcher, err = certwatcher.New(
185+
filepath.Join(metricsCertPath, metricsCertName),
186+
filepath.Join(metricsCertPath, metricsCertKey),
187+
)
188+
if err != nil {
189+
setupLog.Error(err, "to initialize metrics certificate watcher", "error", err)
190+
os.Exit(1)
191+
}
192+
193+
metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
194+
config.GetCertificate = metricsCertWatcher.GetCertificate
195+
})
196+
}
197+
108198
setupLog.Info("Starting the Codebase Operator",
109199
"version", v.Version,
110200
"git-commit", v.GitCommit,
@@ -132,12 +222,9 @@ func main() {
132222
cfg := ctrl.GetConfigOrDie()
133223

134224
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
135-
Scheme: scheme,
136-
Metrics: metricsserver.Options{
137-
BindAddress: metricsAddr,
138-
SecureServing: secureMetrics,
139-
TLSOpts: tlsOpts,
140-
},
225+
Scheme: scheme,
226+
Metrics: metricsServerOptions,
227+
WebhookServer: webhookServer,
141228
HealthProbeBindAddress: probeAddr,
142229
LeaderElection: enableLeaderElection,
143230
LeaderElectionID: codebaseOperatorLock,
@@ -208,6 +295,24 @@ func main() {
208295

209296
// +kubebuilder:scaffold:builder
210297

298+
if metricsCertWatcher != nil {
299+
setupLog.Info("Adding metrics certificate watcher to manager")
300+
301+
if err := mgr.Add(metricsCertWatcher); err != nil {
302+
setupLog.Error(err, "Unable to add metrics certificate watcher to manager")
303+
os.Exit(1)
304+
}
305+
}
306+
307+
if webhookCertWatcher != nil {
308+
setupLog.Info("Adding webhook certificate watcher to manager")
309+
310+
if err := mgr.Add(webhookCertWatcher); err != nil {
311+
setupLog.Error(err, "Unable to add webhook certificate watcher to manager")
312+
os.Exit(1)
313+
}
314+
}
315+
211316
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
212317
setupLog.Error(err, "failed to set up health check")
213318
os.Exit(1)

config/crd/bases/v2.edp.epam.com_cdstagedeployments.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.5
6+
controller-gen.kubebuilder.io/version: v0.18.0
77
name: cdstagedeployments.v2.edp.epam.com
88
spec:
99
group: v2.edp.epam.com

config/crd/bases/v2.edp.epam.com_codebasebranches.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.5
6+
controller-gen.kubebuilder.io/version: v0.18.0
77
name: codebasebranches.v2.edp.epam.com
88
spec:
99
group: v2.edp.epam.com

config/crd/bases/v2.edp.epam.com_codebaseimagestreams.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.5
6+
controller-gen.kubebuilder.io/version: v0.18.0
77
name: codebaseimagestreams.v2.edp.epam.com
88
spec:
99
group: v2.edp.epam.com

0 commit comments

Comments
 (0)