Skip to content

Commit 2314f90

Browse files
committed
fix: finalize was missing from the octx context
On-behalf-of: Gergely Brautigam <gergely.brautigam@sap.com> Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
1 parent e32615a commit 2314f90

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ COPY main.go main.go
1414
COPY api/ api/
1515
COPY controllers/ controllers/
1616
COPY pkg/ pkg/
17-
COPY internal/ internal/
1817

1918
# Build
2019
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

controllers/componentversion_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func (r *ComponentVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req
166166

167167
return ctrl.Result{}, nil
168168
}
169+
defer octx.Finalize()
169170

170171
// reconcile the version before calling reconcile func
171172
update, version, err := r.checkVersion(ctx, octx, obj)

controllers/mutation_reconcile_looper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ func (m *MutationReconcileLooper) fetchDataFromComponentVersion(ctx context.Cont
307307
if err != nil {
308308
return nil, fmt.Errorf("failed to create authenticated client: %w", err)
309309
}
310+
defer octx.Finalize()
310311

311312
if obj.ResourceRef == nil {
312313
return nil, fmt.Errorf("no resource ref found for %s", key)
@@ -375,6 +376,7 @@ func (m *MutationReconcileLooper) createSubstitutionRulesForLocalization(
375376
if err != nil {
376377
return nil, fmt.Errorf("failed to create authenticated client: %w", err)
377378
}
379+
defer octx.Finalize()
378380

379381
compvers, err := m.OCMClient.GetComponentVersion(ctx, octx, cv.GetRepositoryURL(), cv.Spec.Component, cv.Status.ReconciledVersion)
380382
if err != nil {

controllers/resource_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func (r *ResourceReconciler) reconcile(
194194

195195
return ctrl.Result{}, nil
196196
}
197+
defer octx.Finalize()
197198

198199
reader, digest, size, err := r.OCMClient.GetResource(ctx, octx, componentVersion, obj.Spec.SourceRef.ResourceRef)
199200
if err != nil {

main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"flag"
5+
"net/http"
6+
_ "net/http/pprof"
57
"os"
68
"time"
79

@@ -55,6 +57,7 @@ func main() {
5557
eventsAddr string
5658
enableLeaderElection bool
5759
probeAddr string
60+
pprofAddr string
5861
ociRegistryAddr string
5962
ociRegistryCertSecretName string
6063
ociRegistryInsecureSkipVerify bool
@@ -74,6 +77,12 @@ func main() {
7477
":8081",
7578
"The address the probe endpoint binds to.",
7679
)
80+
flag.StringVar(
81+
&pprofAddr,
82+
"pprof-bind-address",
83+
"", // :6060
84+
"The address the pprof endpoint binds to. Set to empty string to disable.",
85+
)
7786
flag.StringVar(
7887
&ociRegistryAddr,
7988
"oci-registry-addr",
@@ -155,6 +164,15 @@ func main() {
155164

156165
ctx := ctrl.SetupSignalHandler()
157166

167+
if pprofAddr != "" {
168+
setupLog.Info("starting pprof server", "address", pprofAddr)
169+
go func() {
170+
if err := http.ListenAndServe(pprofAddr, nil); err != nil {
171+
setupLog.Error(err, "pprof server failed")
172+
}
173+
}()
174+
}
175+
158176
setupLog.Info("starting manager")
159177
if err := mgr.Start(ctx); err != nil {
160178
setupLog.Error(err, "problem running manager")

pkg/snapshot/tar.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,15 @@ func buildTar(artifactPath, sourceDir string) error {
7272
}
7373
f, err := os.Open(p)
7474
if err != nil {
75-
f.Close()
76-
7775
return err
7876
}
79-
if _, err := io.Copy(tw, f); err != nil {
80-
f.Close()
77+
defer f.Close()
8178

79+
if _, err := io.Copy(tw, f); err != nil {
8280
return err
8381
}
8482

85-
return f.Close()
83+
return nil
8684
}); err != nil {
8785
tw.Close()
8886
tf.Close()

0 commit comments

Comments
 (0)