Skip to content

Commit 5bc0965

Browse files
committed
format with gofumpt
1 parent 86e8b9b commit 5bc0965

File tree

8 files changed

+15
-68
lines changed

8 files changed

+15
-68
lines changed

.golangci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ linters:
4141
- examples$
4242
formatters:
4343
enable:
44-
- gofmt
44+
- gofumpt
4545
- goimports
46+
settings:
47+
gofumpt:
48+
extra-rules: true
4649
exclusions:
4750
generated: lax
4851
paths:

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ help:
5050
@echo ""
5151
@echo "Code Quality:"
5252
@echo " lint - Run golangci-lint (same as CI)"
53-
@echo " fmt - Run go fmt"
53+
@echo " fmt - Run gofumpt formatting"
5454
@echo " vet - Run go vet"
5555
@echo " test - Run tests with coverage"
5656
@echo " check - Run all code quality checks (fmt, vet, lint, test)"
@@ -141,10 +141,10 @@ lint:
141141
@echo "Running golangci-lint..."
142142
golangci-lint run
143143

144-
# Run go fmt
144+
# Run gofumpt formatting
145145
fmt:
146-
@echo "Running go fmt..."
147-
go fmt ./...
146+
@echo "Running gofumpt formatting..."
147+
$(shell go env GOPATH)/bin/gofumpt -w .
148148

149149
# Run go vet
150150
vet:

internal/reconciler/fastlycertificatesync/fastly.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func joinErrors(errs []error) error {
3535
}
3636

3737
func (l *Logic) getFastlyPrivateKeyExists(ctx *Context) (bool, error) {
38-
3938
_, secret, err := getCertificateAndTLSSecretFromSubject(ctx)
4039
if err != nil {
4140
return false, fmt.Errorf("failed to get TLS secret from context: %w", err)
@@ -91,7 +90,6 @@ func (l *Logic) getFastlyPrivateKeyExists(ctx *Context) (bool, error) {
9190
}
9291

9392
func (l *Logic) createFastlyPrivateKey(ctx *Context) error {
94-
9593
_, secret, err := getCertificateAndTLSSecretFromSubject(ctx)
9694
if err != nil {
9795
return fmt.Errorf("failed to get TLS secret from context: %w", err)
@@ -115,7 +113,6 @@ func (l *Logic) createFastlyPrivateKey(ctx *Context) error {
115113
}
116114

117115
func (l *Logic) getFastlyCertificateStatus(ctx *Context) (CertificateStatus, error) {
118-
119116
fastlyCertificate, err := l.getFastlyCertificateMatchingSubject(ctx)
120117
if err != nil {
121118
return "", fmt.Errorf("failed to get Fastly certificate matching subject: %w", err)
@@ -142,7 +139,6 @@ func (l *Logic) getFastlyCertificateStatus(ctx *Context) (CertificateStatus, err
142139

143140
// Get the Fastly certificate whose details match the certificate referenced by the subject
144141
func (l *Logic) getFastlyCertificateMatchingSubject(ctx *Context) (*fastly.CustomTLSCertificate, error) {
145-
146142
subjectCertificate := &cmv1.Certificate{}
147143
if err := ctx.Client.Client.Get(ctx, types.NamespacedName{Name: ctx.Subject.Spec.CertificateName, Namespace: ctx.Subject.Namespace}, subjectCertificate); err != nil {
148144
return nil, fmt.Errorf("failed to get certificate of name %s and namespace %s: %w", ctx.Subject.Spec.CertificateName, ctx.Subject.Namespace, err)
@@ -184,7 +180,6 @@ func (l *Logic) getFastlyCertificateMatchingSubject(ctx *Context) (*fastly.Custo
184180
}
185181

186182
func (l *Logic) createFastlyCertificate(ctx *Context) error {
187-
188183
subjectCertificate, tlsSecret, err := getCertificateAndTLSSecretFromSubject(ctx)
189184
if err != nil {
190185
return fmt.Errorf("failed to get TLS secret from context: %w", err)
@@ -241,7 +236,6 @@ func (l *Logic) updateFastlyCertificate(ctx *Context) error {
241236
}
242237

243238
func (l *Logic) isFastlyCertificateStale(ctx *Context, fastlyCertificate *fastly.CustomTLSCertificate) (bool, error) {
244-
245239
subjectCertificate, tlsSecret, err := getCertificateAndTLSSecretFromSubject(ctx)
246240
if err != nil {
247241
return false, fmt.Errorf("failed to get TLS secret from context: %w", err)
@@ -272,7 +266,6 @@ func (l *Logic) isFastlyCertificateStale(ctx *Context, fastlyCertificate *fastly
272266
}
273267

274268
func (l *Logic) getFastlyTLSActivationState(ctx *Context) ([]TLSActivationData, []string, error) {
275-
276269
missingTLSActivationData := []TLSActivationData{}
277270
extraTLSActivationIDs := []string{}
278271

internal/reconciler/fastlycertificatesync/fastly_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,7 @@ rI/pIULoTkGajE0uXlIlG0k=
26022602
}
26032603

26042604
// Helper function to generate a full page of certificates
2605-
func generateCertPage(pageNum int, count int) []*fastly.CustomTLSCertificate {
2605+
func generateCertPage(pageNum, count int) []*fastly.CustomTLSCertificate {
26062606
certs := make([]*fastly.CustomTLSCertificate, count)
26072607
for i := 0; i < count; i++ {
26082608
certs[i] = &fastly.CustomTLSCertificate{

internal/reconciler/fastlycertificatesync/helper.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func getCertificateAndTLSSecretFromSubject(ctx *Context) (*cmv1.Certificate, *co
5252

5353
// GetPublicKeySHA1FromPEM calculates the SHA1 hash of the public key derived from a PEM-encoded private key
5454
func getPublicKeySHA1FromPEM(keyPEM []byte) (string, error) {
55-
5655
// Decode the PEM block
5756
block, _ := pem.Decode(keyPEM)
5857
if block == nil {

internal/reconciler/fastlycertificatesync/helper_test.go

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package fastlycertificatesync
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/hex"
67
"strings"
78
"testing"
89

9-
"bytes"
10-
1110
cmv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
1211
cmmetav1 "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
1312
"github.com/fastly-operator/api/v1alpha1"
@@ -37,36 +36,6 @@ func createTestContext() *Context {
3736
}
3837
}
3938

40-
// Helper to create a certificate with specific conditions
41-
func createCertificateWithConditions(conditions []cmv1.CertificateCondition) *cmv1.Certificate {
42-
return &cmv1.Certificate{
43-
ObjectMeta: metav1.ObjectMeta{
44-
Name: "test-certificate",
45-
Namespace: "test-namespace",
46-
},
47-
Spec: cmv1.CertificateSpec{
48-
SecretName: "test-secret",
49-
},
50-
Status: cmv1.CertificateStatus{
51-
Conditions: conditions,
52-
},
53-
}
54-
}
55-
56-
// Helper to create a mock secret
57-
func createTestSecret() *corev1.Secret {
58-
return &corev1.Secret{
59-
ObjectMeta: metav1.ObjectMeta{
60-
Name: "test-secret",
61-
Namespace: "test-namespace",
62-
},
63-
Data: map[string][]byte{
64-
"tls.crt": []byte("test-cert-data"),
65-
"tls.key": []byte("test-key-data"),
66-
},
67-
}
68-
}
69-
7039
func TestIsSubjectReadyForReconciliation(t *testing.T) {
7140
tests := []struct {
7241
name string
@@ -801,22 +770,6 @@ MIICACertificateDataHere
801770
expectedError: "secret test-namespace/test-secret does not contain tls.crt",
802771
description: "Should return error when secret has nil data in production mode",
803772
},
804-
{
805-
name: "empty_tls_crt_value_production_mode",
806-
secret: &corev1.Secret{
807-
ObjectMeta: metav1.ObjectMeta{
808-
Name: "test-secret",
809-
Namespace: "test-namespace",
810-
},
811-
Data: map[string][]byte{
812-
"tls.crt": []byte{}, // Empty but present
813-
"tls.key": []byte("dummy-key-data"),
814-
},
815-
},
816-
hackLocalReconciliation: false,
817-
expectedPEM: []byte{}, // Should return empty byte slice, not error
818-
description: "Should return empty PEM when tls.crt is empty but present in production mode",
819-
},
820773
{
821774
name: "empty_ca_crt_value_local_mode",
822775
secret: &corev1.Secret{
@@ -826,8 +779,8 @@ MIICACertificateDataHere
826779
},
827780
Data: map[string][]byte{
828781
"tls.crt": dummyCertPEM,
829-
"ca.crt": []byte{}, // Empty but present
830782
"tls.key": []byte("dummy-key-data"),
783+
"ca.crt": {},
831784
},
832785
},
833786
hackLocalReconciliation: true,

internal/reconciler/fastlycertificatesync/logic.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import (
2929

3030
type Context = genrec.Context[*v1alpha1.FastlyCertificateSync, *Config]
3131

32-
type CertificateStatus string
33-
type TLSActivationState string
32+
type (
33+
CertificateStatus string
34+
TLSActivationState string
35+
)
3436

3537
const (
3638
CertificateStatusMissing CertificateStatus = "Missing"
@@ -135,7 +137,6 @@ func (l *Logic) ConfigureController(cb *builder.Builder, cluster cluster.Cluster
135137
for _, fastlyCertificateSync := range all.Items {
136138
// reconcile fastlyCertificateSync resources that are referenced by the watched certificate
137139
if (object.GetName() == fastlyCertificateSync.Spec.CertificateName) && (object.GetNamespace() == fastlyCertificateSync.GetNamespace()) {
138-
139140
res = append(res, reconcile.Request{
140141
NamespacedName: types.NamespacedName{
141142
Name: fastlyCertificateSync.GetName(),
@@ -221,7 +222,6 @@ func (l *Logic) ObserveResources(ctx *Context) (genrec.Resources, error) {
221222
}
222223

223224
func (l *Logic) ApplyUnmanaged(ctx *Context) error {
224-
225225
if !l.SubjectReadyForReconciliation {
226226
ctx.Log.Info("Subject is not ready for reconciliation, skipping")
227227
return nil

internal/reconciler/fastlycertificatesync/metrics.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
)
66

77
func (l *Logic) ReconcileComplete(c *Context, rs genrec.ReconciliationStatus, err error) {
8-
98
if c.Subject == nil {
109
return
1110
}

0 commit comments

Comments
 (0)