Skip to content

Commit 458c0cd

Browse files
committed
chore(deps): bump all and update operator-sdk scaffold to v1.40.0
1 parent df7ad4a commit 458c0cd

38 files changed

+632
-339
lines changed

.devcontainer/devcontainer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "docker.io/golang:1.23",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
7+
},
8+
9+
"runArgs": ["--network=host"],
10+
11+
"customizations": {
12+
"vscode": {
13+
"settings": {
14+
"terminal.integrated.shell.linux": "/bin/bash"
15+
},
16+
"extensions": [
17+
"ms-kubernetes-tools.vscode-kubernetes-tools",
18+
"ms-azuretools.vscode-docker"
19+
]
20+
}
21+
},
22+
23+
"onCreateCommand": "bash .devcontainer/post-install.sh"
24+
}

.devcontainer/post-install.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -x
3+
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
7+
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
11+
12+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
16+
17+
docker network create -d=bridge --subnet=172.19.0.0/24 kind
18+
19+
kind version
20+
kubebuilder version
21+
docker --version
22+
go version
23+
kubectl version --client

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ run:
44
linters:
55
default: none
66
enable:
7+
- copyloopvar
78
- dupl
89
- errcheck
910
- ginkgolinter

Makefile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ OPERATOR_SDK_VERSION ?= v1.38.0
5656
# Image URL to use all building/pushing image targets
5757
IMG ?= $(IMAGE_TAG_BASE):latest
5858
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
59-
ENVTEST_K8S_VERSION = 1.31.0
59+
ENVTEST_K8S_VERSION := $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
6060

6161
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6262
ifeq (,$(shell go env GOBIN))
@@ -125,7 +125,7 @@ vet: ## Run go vet against code.
125125
go vet ./...
126126

127127
.PHONY: test
128-
test: manifests generate fmt vet envtest ## Run tests.
128+
test: manifests generate fmt vet setup-envtest ## Run tests.
129129
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
130130

131131
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
@@ -141,6 +141,10 @@ lint: golangci-lint ## Run golangci-lint linter
141141
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
142142
$(GOLANGCI_LINT) run --fix
143143

144+
.PHONY: lint-config
145+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
146+
$(GOLANGCI_LINT) config verify
147+
144148
##@ Build
145149

146150
.PHONY: build
@@ -231,7 +235,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
231235
## Tool Versions
232236
KUSTOMIZE_VERSION ?= v5.5.0
233237
CONTROLLER_TOOLS_VERSION ?= v0.16.4
234-
ENVTEST_VERSION ?= release-0.19
238+
ENVTEST_VERSION := $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
235239
GOLANGCI_LINT_VERSION ?= v1.59.1
236240

237241
.PHONY: kustomize
@@ -244,6 +248,14 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
244248
$(CONTROLLER_GEN): $(LOCALBIN)
245249
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
246250

251+
.PHONY: setup-envtest
252+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
253+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
254+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
255+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
256+
exit 1; \
257+
}
258+
247259
.PHONY: envtest
248260
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
249261
$(ENVTEST): $(LOCALBIN)
@@ -311,7 +323,7 @@ ifeq (,$(shell which opm 2>/dev/null))
311323
set -e ;\
312324
mkdir -p $(dir $(OPM)) ;\
313325
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
314-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
326+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.55.0/$${OS}-$${ARCH}-opm ;\
315327
chmod +x $(OPM) ;\
316328
}
317329
else

api/v1/clustertoken_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package v1
1919
import (
2020
"time"
2121

22-
"github.com/google/go-github/v71/github"
22+
"github.com/google/go-github/v72/github"
2323
"github.com/isometry/github-token-manager/internal/ghapp"
2424
"k8s.io/apimachinery/pkg/api/meta"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

api/v1/permissions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package v1
22

33
import (
4-
"github.com/google/go-github/v71/github"
4+
"github.com/google/go-github/v72/github"
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
66
)
77

api/v1/token_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package v1
1919
import (
2020
"time"
2121

22-
"github.com/google/go-github/v71/github"
22+
"github.com/google/go-github/v72/github"
2323
"github.com/isometry/github-token-manager/internal/ghapp"
2424
"k8s.io/apimachinery/pkg/api/meta"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

cmd/manager/main.go

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"crypto/tls"
2121
"flag"
2222
"os"
23+
"path/filepath"
2324

2425
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2526
// to ensure that exec-entrypoint and run can make use of them.
@@ -29,6 +30,7 @@ import (
2930
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3031
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3132
ctrl "sigs.k8s.io/controller-runtime"
33+
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
3234
"sigs.k8s.io/controller-runtime/pkg/healthz"
3335
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3436
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
@@ -57,6 +59,8 @@ func init() {
5759

5860
func main() {
5961
var metricsAddr string
62+
var metricsCertPath, metricsCertName, metricsCertKey string
63+
var webhookCertPath, webhookCertName, webhookCertKey string
6064
var enableLeaderElection bool
6165
var probeAddr string
6266
var secureMetrics bool
@@ -70,6 +74,12 @@ func main() {
7074
"Enabling this will ensure there is only one active controller manager.")
7175
flag.BoolVar(&secureMetrics, "metrics-secure", true,
7276
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
77+
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
78+
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
79+
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
80+
flag.StringVar(&metricsCertPath, "metrics-cert-path", "", "The directory that contains the metrics server certificate.") //nolint:lll
81+
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
82+
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
7383
flag.BoolVar(&disableHTTP2, "disable-http2", false,
7484
"If set, HTTP/2 will be disabled for the metrics and webhook servers")
7585
opts := zap.Options{
@@ -88,8 +98,33 @@ func main() {
8898
tlsOpts = append(tlsOpts, forceHTTP11)
8999
}
90100

101+
// Create watchers for metrics and webhooks certificates
102+
var metricsCertWatcher, webhookCertWatcher *certwatcher.CertWatcher
103+
104+
// Initial webhook TLS options
105+
webhookTLSOpts := tlsOpts
106+
107+
if len(webhookCertPath) > 0 {
108+
setupLog.Info("Initializing webhook certificate watcher using provided certificates",
109+
"webhook-cert-path", webhookCertPath, "webhook-cert-name", webhookCertName, "webhook-cert-key", webhookCertKey)
110+
111+
var err error
112+
webhookCertWatcher, err = certwatcher.New(
113+
filepath.Join(webhookCertPath, webhookCertName),
114+
filepath.Join(webhookCertPath, webhookCertKey),
115+
)
116+
if err != nil {
117+
setupLog.Error(err, "Failed to initialize webhook certificate watcher")
118+
os.Exit(1)
119+
}
120+
121+
webhookTLSOpts = append(webhookTLSOpts, func(config *tls.Config) {
122+
config.GetCertificate = webhookCertWatcher.GetCertificate
123+
})
124+
}
125+
91126
webhookServer := webhook.NewServer(webhook.Options{
92-
TLSOpts: tlsOpts,
127+
TLSOpts: webhookTLSOpts,
93128
})
94129

95130
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
@@ -116,6 +151,25 @@ func main() {
116151
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
117152
}
118153

154+
if len(metricsCertPath) > 0 {
155+
setupLog.Info("Initializing metrics certificate watcher using provided certificates",
156+
"metrics-cert-path", metricsCertPath, "metrics-cert-name", metricsCertName, "metrics-cert-key", metricsCertKey)
157+
158+
var err error
159+
metricsCertWatcher, err = certwatcher.New(
160+
filepath.Join(metricsCertPath, metricsCertName),
161+
filepath.Join(metricsCertPath, metricsCertKey),
162+
)
163+
if err != nil {
164+
setupLog.Error(err, "Failed to initialize metrics certificate watcher")
165+
os.Exit(1)
166+
}
167+
168+
metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
169+
config.GetCertificate = metricsCertWatcher.GetCertificate
170+
})
171+
}
172+
119173
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
120174
Scheme: scheme,
121175
Metrics: metricsServerOptions,
@@ -158,6 +212,22 @@ func main() {
158212
}
159213
// +kubebuilder:scaffold:builder
160214

215+
if metricsCertWatcher != nil {
216+
setupLog.Info("Adding metrics certificate watcher to manager")
217+
if err := mgr.Add(metricsCertWatcher); err != nil {
218+
setupLog.Error(err, "Unable to add metrics certificate watcher to manager")
219+
os.Exit(1)
220+
}
221+
}
222+
223+
if webhookCertWatcher != nil {
224+
setupLog.Info("Adding webhook certificate watcher to manager")
225+
if err := mgr.Add(webhookCertWatcher); err != nil {
226+
setupLog.Error(err, "Unable to add webhook certificate watcher to manager")
227+
os.Exit(1)
228+
}
229+
}
230+
161231
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
162232
setupLog.Error(err, "unable to set up health check")
163233
os.Exit(1)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The following manifests contain a self-signed issuer CR and a metrics certificate CR.
2+
# More document can be found at https://docs.cert-manager.io
3+
apiVersion: cert-manager.io/v1
4+
kind: Certificate
5+
metadata:
6+
labels:
7+
app.kubernetes.io/name: github-token-manager
8+
app.kubernetes.io/managed-by: kustomize
9+
name: metrics-certs # this name should match the one appeared in kustomizeconfig.yaml
10+
namespace: system
11+
spec:
12+
dnsNames:
13+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
14+
# replacements in the config/default/kustomization.yaml file.
15+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
16+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
17+
issuerRef:
18+
kind: Issuer
19+
name: selfsigned-issuer
20+
secretName: metrics-server-cert
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The following manifests contain a self-signed issuer CR and a certificate CR.
2+
# More document can be found at https://docs.cert-manager.io
3+
apiVersion: cert-manager.io/v1
4+
kind: Certificate
5+
metadata:
6+
labels:
7+
app.kubernetes.io/name: github-token-manager
8+
app.kubernetes.io/managed-by: kustomize
9+
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
10+
namespace: system
11+
spec:
12+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
13+
# replacements in the config/default/kustomization.yaml file.
14+
dnsNames:
15+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
16+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
17+
issuerRef:
18+
kind: Issuer
19+
name: selfsigned-issuer
20+
secretName: webhook-server-cert

0 commit comments

Comments
 (0)