Skip to content

Commit

Permalink
Fix lint errors & Introduce lint workflow (#76)
Browse files Browse the repository at this point in the history
* Fix lint errors

* Add Actions workflow to lint Go code
  • Loading branch information
ordovicia authored Aug 7, 2024
1 parent cc0cf5b commit 88deef0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ jobs:
- uses: actions/checkout@v4
- run: make docker-build

lint-go:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- uses: golangci/golangci-lint-action@v6
with:
version: v1.59

lint-chart:
runs-on: ubuntu-latest
steps:
Expand Down
8 changes: 4 additions & 4 deletions webhooks/mutatepod_parts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/MakeNowJust/heredoc"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

// Volumes
Expand Down Expand Up @@ -54,7 +54,7 @@ func k8sSATokenVolume(
Path: K8sSATokenName,
},
}},
DefaultMode: pointer.Int32(defaultMode),
DefaultMode: ptr.To(defaultMode),
},
},
}
Expand All @@ -75,7 +75,7 @@ func (m *GCPWorkloadIdentityMutator) externalCredConfigVolume(defaultMode int32)
},
},
},
DefaultMode: pointer.Int32(defaultMode),
DefaultMode: ptr.To(defaultMode),
},
},
}
Expand All @@ -89,7 +89,7 @@ func gcloudSetupContainer(
) corev1.Container {
// for Restricted Profile in Pod Security Standards
securityContext := &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.Bool(false),
AllowPrivilegeEscalation: ptr.To(false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
Expand Down
22 changes: 11 additions & 11 deletions webhooks/mutatepod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

var _ = Describe("GCPWorkloadIdentityMutator.mutatePod", func() {
Expand All @@ -34,13 +34,13 @@ var _ = Describe("GCPWorkloadIdentityMutator.mutatePod", func() {
}
})
When("passed Pod has unparsed token expiration annotation", func() {
It("should reaise error", func() {
It("should raise error", func() {
idConfig := GCPWorkloadIdentityConfig{
WorkloadIdentityProvider: &workloadIdentityProviderFmt,
ServiceAccountEmail: pointer.StringPtr(fmt.Sprintf("sa@%s.iam.gserviceaccount.com", project)),
Audience: pointer.String("my-audience"),
TokenExpirationSeconds: pointer.Int64(10000),
RunAsUser: pointer.Int64(1000),
ServiceAccountEmail: ptr.To(fmt.Sprintf("sa@%s.iam.gserviceaccount.com", project)),
Audience: ptr.To("my-audience"),
TokenExpirationSeconds: ptr.To[int64](10000),
RunAsUser: ptr.To[int64](1000),
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -58,10 +58,10 @@ var _ = Describe("GCPWorkloadIdentityMutator.mutatePod", func() {
It("should replace reqiured fields and override configurations", func() {
idConfig := GCPWorkloadIdentityConfig{
WorkloadIdentityProvider: &workloadIdentityProviderFmt,
ServiceAccountEmail: pointer.StringPtr(fmt.Sprintf("sa@%s.iam.gserviceaccount.com", project)),
Audience: pointer.String("my-audience"),
TokenExpirationSeconds: pointer.Int64(10000),
RunAsUser: pointer.Int64(1000),
ServiceAccountEmail: ptr.To(fmt.Sprintf("sa@%s.iam.gserviceaccount.com", project)),
Audience: ptr.To("my-audience"),
TokenExpirationSeconds: ptr.To[int64](10000),
RunAsUser: ptr.To[int64](1000),
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -178,7 +178,7 @@ var _ = Describe("GCPWorkloadIdentityMutator.mutatePod", func() {
It("should mutate required fields", func() {
idConfig := GCPWorkloadIdentityConfig{
WorkloadIdentityProvider: &workloadIdentityProviderFmt,
ServiceAccountEmail: pointer.StringPtr(fmt.Sprintf("sa@%s.iam.gserviceaccount.com", project)),
ServiceAccountEmail: ptr.To(fmt.Sprintf("sa@%s.iam.gserviceaccount.com", project)),
}
pod := &corev1.Pod{
Spec: corev1.PodSpec{
Expand Down
6 changes: 5 additions & 1 deletion webhooks/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ func (m *GCPWorkloadIdentityMutator) SetupWithManager(ctx context.Context, mgr c
logger.Error(err, "Failed to get ServiceAccount informer")
return err
}
saInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{})

if _, err = saInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{}); err != nil {
logger.Error(err, "Failed to add event handler")
return err
}

// Inject logger, decoder, and client.
m.logger = mgr.GetLogger()
Expand Down

0 comments on commit 88deef0

Please sign in to comment.