Skip to content

Commit c33a488

Browse files
fixed the linter warnings (#40)
1 parent 891efd6 commit c33a488

File tree

8 files changed

+29
-27
lines changed

8 files changed

+29
-27
lines changed

internal/controller/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ type Config struct {
1919
LogicalEnvironment string
2020
PhysicalEnvironment string
2121
Cluster string
22-
APIToken string
23-
BaseURL string
24-
GHAppID string
25-
GHInstallID string
26-
GHAppPrivateKey string
27-
Organization string
22+
//nolint:gosec
23+
APIToken string
24+
BaseURL string
25+
GHAppID string
26+
GHInstallID string
27+
GHAppPrivateKey string
28+
Organization string
2829
}
2930

3031
// ValidTemplate verifies that at least one placeholder is present

internal/controller/controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"time"
1111

1212
"github.com/github/deployment-tracker/pkg/deploymentrecord"
13-
"github.com/github/deployment-tracker/pkg/image"
14-
"github.com/github/deployment-tracker/pkg/metrics"
13+
"github.com/github/deployment-tracker/pkg/dtmetrics"
14+
"github.com/github/deployment-tracker/pkg/ociutil"
1515
"k8s.io/apimachinery/pkg/runtime/schema"
1616
"k8s.io/apimachinery/pkg/types"
1717
amcache "k8s.io/apimachinery/pkg/util/cache"
@@ -271,14 +271,14 @@ func (c *Controller) processNextItem(ctx context.Context) bool {
271271
dur := time.Since(start)
272272

273273
if err == nil {
274-
metrics.EventsProcessedOk.WithLabelValues(event.EventType).Inc()
275-
metrics.EventsProcessedTimer.WithLabelValues("ok").Observe(dur.Seconds())
274+
dtmetrics.EventsProcessedOk.WithLabelValues(event.EventType).Inc()
275+
dtmetrics.EventsProcessedTimer.WithLabelValues("ok").Observe(dur.Seconds())
276276

277277
c.workqueue.Forget(event)
278278
return true
279279
}
280-
metrics.EventsProcessedTimer.WithLabelValues("failed").Observe(dur.Seconds())
281-
metrics.EventsProcessedFailed.WithLabelValues(event.EventType).Inc()
280+
dtmetrics.EventsProcessedTimer.WithLabelValues("failed").Observe(dur.Seconds())
281+
dtmetrics.EventsProcessedFailed.WithLabelValues(event.EventType).Inc()
282282

283283
// Requeue on error with rate limiting
284284
slog.Error("Failed to process event, requeuing",
@@ -443,7 +443,7 @@ func (c *Controller) recordContainer(ctx context.Context, pod *corev1.Pod, conta
443443
}
444444

445445
// Extract image name and tag
446-
imageName, version := image.ExtractName(container.Image)
446+
imageName, version := ociutil.ExtractName(container.Image)
447447

448448
// Create deployment record
449449
record := deploymentrecord.NewDeploymentRecord(
@@ -676,14 +676,14 @@ func getContainerDigest(pod *corev1.Pod, containerName string) string {
676676
// Check regular container statuses
677677
for _, status := range pod.Status.ContainerStatuses {
678678
if status.Name == containerName {
679-
return image.ExtractDigest(status.ImageID)
679+
return ociutil.ExtractDigest(status.ImageID)
680680
}
681681
}
682682

683683
// Check init container statuses
684684
for _, status := range pod.Status.InitContainerStatuses {
685685
if status.Name == containerName {
686-
return image.ExtractDigest(status.ImageID)
686+
return ociutil.ExtractDigest(status.ImageID)
687687
}
688688
}
689689

pkg/deploymentrecord/client.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"time"
1818

1919
"github.com/bradleyfalzon/ghinstallation/v2"
20-
"github.com/github/deployment-tracker/pkg/metrics"
20+
"github.com/github/deployment-tracker/pkg/dtmetrics"
2121
"golang.org/x/time/rate"
2222
)
2323

@@ -211,17 +211,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
211211
}
212212

213213
start := time.Now()
214+
// nolint: gosec
214215
resp, err := c.httpClient.Do(req)
215216
dur := time.Since(start)
216-
metrics.PostDeploymentRecordTimer.Observe(dur.Seconds())
217+
dtmetrics.PostDeploymentRecordTimer.Observe(dur.Seconds())
217218
if err != nil {
218219
lastErr = fmt.Errorf("post request failed: %w", err)
219220

220221
slog.Warn("recoverable error, re-trying",
221222
"attempt", attempt,
222223
"retries", c.retries,
223224
"error", lastErr)
224-
metrics.PostDeploymentRecordSoftFail.Inc()
225+
dtmetrics.PostDeploymentRecordSoftFail.Inc()
225226
continue
226227
}
227228

@@ -230,7 +231,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
230231
resp.Body.Close()
231232

232233
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
233-
metrics.PostDeploymentRecordOk.Inc()
234+
dtmetrics.PostDeploymentRecordOk.Inc()
234235
return nil
235236
}
236237

@@ -239,16 +240,16 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
239240
// Don't retry on client errors (4xx) except for 429
240241
// (rate limit)
241242
if resp.StatusCode >= 400 && resp.StatusCode < 500 && resp.StatusCode != 429 {
242-
metrics.PostDeploymentRecordClientError.Inc()
243+
dtmetrics.PostDeploymentRecordClientError.Inc()
243244
slog.Warn("client error, aborting",
244245
"attempt", attempt,
245246
"error", lastErr)
246247
return &ClientError{err: lastErr}
247248
}
248-
metrics.PostDeploymentRecordSoftFail.Inc()
249+
dtmetrics.PostDeploymentRecordSoftFail.Inc()
249250
}
250251

251-
metrics.PostDeploymentRecordHardFail.Inc()
252+
dtmetrics.PostDeploymentRecordHardFail.Inc()
252253
slog.Error("all retries exhausted",
253254
"count", c.retries,
254255
"error", lastErr)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package metrics
1+
package dtmetrics
22

33
import (
44
"github.com/prometheus/client_golang/prometheus"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package image
1+
package ociutil
22

33
// ExtractDigest extracts the digest from an ImageID.
44
// ImageID format is typically: docker-pullable://image@sha256:abc123...
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package image
1+
package ociutil
22

33
import (
44
"testing"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package image
1+
package ociutil
22

33
import (
44
"strings"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package image
1+
package ociutil
22

33
import (
44
"testing"

0 commit comments

Comments
 (0)