Skip to content

Commit

Permalink
Merge branch 'master' into k8s-plugin-sync-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Warashi authored Dec 18, 2024
2 parents 3c0a57d + 7cf95df commit 63c8d77
Show file tree
Hide file tree
Showing 43 changed files with 119 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
env:
GO_VERSION: 1.22.4
NODE_VERSION: 16.13.0
GOLANGCI_LINT_VERSION: v1.46.2
GOLANGCI_LINT_VERSION: v1.62.2

jobs:
go:
Expand Down
11 changes: 5 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
run:
timeout: 15m
skip-files:
- ^.*\.(pb|y)\.go$
skip-dirs:
- "vendor$"
- "pkg/app/piped/executor/analysis/mannwhitney"

linters:
disable-all: true
enable:
- depguard
- exportloopref
- gocritic
- goimports
- gosimple
Expand All @@ -28,6 +22,11 @@ linters:
# - gosec

issues:
exclude-files:
- ^.*\.(pb|y)\.go$
exclude-dirs:
- "vendor$"
- "pkg/app/piped/executor/analysis/mannwhitney"
exclude-rules:
- linters:
- staticcheck
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ run/site:

.PHONY: lint/go
lint/go: FIX ?= false
lint/go: VERSION ?= sha256:fb70c9b2e6d0763141f057abcafde7f88d5e4bb3b5882d6b14bc79382f04481c #v1.55.2
lint/go: FLAGS ?= --rm --platform linux/amd64 -e GOCACHE=/repo/.cache/go-build -e GOLANGCI_LINT_CACHE=/repo/.cache/golangci-lint -v ${PWD}:/repo -w /repo -it
lint/go: VERSION ?= sha256:4e53bfe25ef2f1e14a95da42d694211080f40d118730541ce1513a83cf7587ec # v1.62.2
lint/go: FLAGS ?= --rm -e GOCACHE=/repo/.cache/go-build -e GOLANGCI_LINT_CACHE=/repo/.cache/golangci-lint -v ${PWD}:/repo -w /repo -it
lint/go:
ifeq ($(FIX),true)
docker run ${FLAGS} golangci/golangci-lint@${VERSION} golangci-lint run -v --fix
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.4
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v29 v29.0.3
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
Expand All @@ -50,7 +51,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
go.uber.org/atomic v1.7.0
go.uber.org/atomic v1.11.0
go.uber.org/zap v1.19.1
golang.org/x/crypto v0.25.0
golang.org/x/mod v0.22.0
Expand Down Expand Up @@ -126,7 +127,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,9 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/pipectl/cmd/initialize/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *command) run(ctx context.Context, input cli.Input) error {
return generateConfig(ctx, input, p)
}

func generateConfig(ctx context.Context, input cli.Input, p prompt.Prompt) error {
func generateConfig(_ context.Context, _ cli.Input, p prompt.Prompt) error {
// user's inputs
var (
platform string
Expand Down
14 changes: 7 additions & 7 deletions pkg/app/piped/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ type controller struct {
// workingDirRemovalCh is used to single-threaded removal of working directory.
workingDirRemovalCh chan string

workspaceDir string
syncInternal time.Duration
gracePeriod time.Duration
logger *zap.Logger
workspaceDir string
syncInternal time.Duration
gracePeriod time.Duration
logger *zap.Logger
tracerProvider trace.TracerProvider
}

Expand Down Expand Up @@ -194,9 +194,9 @@ func NewController(

workingDirRemovalCh: make(chan string),

syncInternal: 10 * time.Second,
gracePeriod: gracePeriod,
logger: lg,
syncInternal: 10 * time.Second,
gracePeriod: gracePeriod,
logger: lg,
tracerProvider: tracerProvider,
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/piped/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (s *scheduler) Run(ctx context.Context) error {
case model.DeploymentStatus_DEPLOYMENT_FAILURE, model.DeploymentStatus_DEPLOYMENT_CANCELLED:
span.SetStatus(codes.Error, statusReason)
}

span.End()
}()

Expand Down Expand Up @@ -785,8 +785,8 @@ func (s *scheduler) reportDeploymentCompleted(ctx context.Context, status model.
}

// getApplicationNotificationMentions returns the list of users groups who should be mentioned in the notification.
func (p *scheduler) getApplicationNotificationMentions(event model.NotificationEventType) ([]string, []string, error) {
n, ok := p.metadataStore.Shared().Get(model.MetadataKeyDeploymentNotification)
func (s *scheduler) getApplicationNotificationMentions(event model.NotificationEventType) ([]string, []string, error) {
n, ok := s.metadataStore.Shared().Get(model.MetadataKeyDeploymentNotification)
if !ok {
return []string{}, []string{}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/piped/controller/skipstage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/pipe-cd/pipecd/pkg/config"
"github.com/pipe-cd/pipecd/pkg/git"
"github.com/pipe-cd/pipecd/pkg/git/gittest"
"github.com/stretchr/testify/assert"
)

func TestSkipByCommitMessagePrefixes(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/piped/controller/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
"context"
"hash/fnv"

"github.com/pipe-cd/pipecd/pkg/model"
"go.opentelemetry.io/otel/trace"

"github.com/pipe-cd/pipecd/pkg/model"
)

func newContextWithDeploymentSpan(ctx context.Context, deployment *model.Deployment) context.Context {
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/piped/controller/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ package controller
import (
"testing"

"github.com/pipe-cd/pipecd/pkg/model"
"github.com/stretchr/testify/assert"

"github.com/pipe-cd/pipecd/pkg/model"
)

func TestDeploymentTraceID(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/piped/driftdetector/ecs/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"strings"
"time"

"go.uber.org/zap"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"go.uber.org/zap"

"github.com/pipe-cd/pipecd/pkg/app/piped/livestatestore/ecs"
provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/ecs"
"github.com/pipe-cd/pipecd/pkg/app/piped/sourceprocesser"
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/piped/driftdetector/ecs/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/stretchr/testify/assert"

provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/ecs"
"github.com/pipe-cd/pipecd/pkg/diff"
"github.com/stretchr/testify/assert"
)

func TestIgnoreParameters(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/piped/driftdetector/lambda/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/lambda/types"
"github.com/stretchr/testify/assert"

provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/lambda"
"github.com/pipe-cd/pipecd/pkg/diff"
"github.com/stretchr/testify/assert"
)

func TestIgnoreAndSortParameters(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/piped/livestatereporter/ecs/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (
"fmt"
"time"

"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/pipe-cd/pipecd/pkg/app/piped/livestatestore/ecs"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
"github.com/pipe-cd/pipecd/pkg/config"
"github.com/pipe-cd/pipecd/pkg/model"
"go.uber.org/zap"
"google.golang.org/grpc"
)

type applicationLister interface {
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/piped/livestatereporter/lambda/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (
"fmt"
"time"

"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/pipe-cd/pipecd/pkg/app/piped/livestatestore/lambda"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
"github.com/pipe-cd/pipecd/pkg/config"
"github.com/pipe-cd/pipecd/pkg/model"
"go.uber.org/zap"
"google.golang.org/grpc"
)

type applicationLister interface {
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/piped/livestatestore/ecs/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package ecs
import (
"context"
"fmt"
"sync/atomic"
"time"

"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"go.uber.org/atomic"
"go.uber.org/zap"

provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/ecs"
Expand Down Expand Up @@ -80,19 +80,19 @@ func (s *store) run(ctx context.Context) error {
}

// Use the application ID tag as the key.
appId := ""
appID := ""
for _, tag := range service.Tags {
if *tag.Key == provider.LabelApplication {
appId = *tag.Value
appID = *tag.Value
break
}
}
if appId == "" {
if appID == "" {
// Skip a service which is not managed by PipeCD.
continue
}

apps[appId] = app{
apps[appID] = app{
ecsManifests: provider.ECSManifests{
ServiceDefinition: service,
TaskDefinition: primaryTaskDef,
Expand Down
8 changes: 4 additions & 4 deletions pkg/app/piped/livestatestore/lambda/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package lambda
import (
"context"
"fmt"
"sync/atomic"
"time"

"github.com/aws/aws-sdk-go-v2/service/lambda"
"go.uber.org/atomic"
"go.uber.org/zap"

"github.com/aws/aws-sdk-go-v2/service/lambda"
provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/lambda"
"github.com/pipe-cd/pipecd/pkg/model"
)
Expand Down Expand Up @@ -59,13 +59,13 @@ func (s *store) run(ctx context.Context) error {
return fmt.Errorf("failed to get Lambda function %s: %w", *funcCfg.FunctionName, err)
}

appId, ok := f.Tags[provider.LabelApplication]
appID, ok := f.Tags[provider.LabelApplication]
if !ok {
// Skip a function not managed by PipeCD.
continue
}

apps[appId] = app{
apps[appID] = app{
functionManifest: convertToManifest(f),
states: []*model.LambdaResourceState{
provider.MakeFunctionResourceState(f.Configuration),
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/piped/livestatestore/lambda/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lambda"
"github.com/aws/aws-sdk-go-v2/service/lambda/types"
provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/lambda"
"github.com/stretchr/testify/assert"

provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/lambda"
)

func TestConvertToManifest(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/planpreview/ecsdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"

"github.com/aws/aws-sdk-go-v2/service/ecs/types"

"github.com/pipe-cd/pipecd/pkg/app/piped/deploysource"
provider "github.com/pipe-cd/pipecd/pkg/app/piped/platformprovider/ecs"
"github.com/pipe-cd/pipecd/pkg/diff"
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/platformprovider/ecs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/require"
)

//nolint:unparam // appDir always be "testdata/", but it may be changed in the future.
func loadManifests(appDir, taskDefFile, serviceDefFile string) (ECSManifests, error) {
taskDef, err := LoadTaskDefinition(appDir, taskDefFile)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/piped/platformprovider/ecs/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

"github.com/aws/aws-sdk-go-v2/service/ecs/types"

"github.com/pipe-cd/pipecd/pkg/model"
)

Expand Down Expand Up @@ -108,14 +109,14 @@ func makeTaskResourceState(task *types.Task, parentArn string) *model.ECSResourc
}

taskArnParts := strings.Split(*task.TaskArn, "/")
taskId := taskArnParts[len(taskArnParts)-1]
taskID := taskArnParts[len(taskArnParts)-1]

createdAt := task.CreatedAt.Unix()
return &model.ECSResourceState{
Id: *task.TaskArn,
OwnerIds: []string{parentArn},
ParentIds: []string{parentArn},
Name: taskId,
Name: taskID,

Kind: "Task",

Expand Down
6 changes: 3 additions & 3 deletions pkg/app/piped/platformprovider/ecs/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestMakeServiceResourceState(t *testing.T) {
t.Parallel()
service := &types.Service{
Status: &tc.status,
// Folowing fields are required to avoid nil pointer panic.
// Following fields are required to avoid nil pointer panic.
ServiceArn: aws.String("test-service-arn"),
ClusterArn: aws.String("test-cluster-arn"),
ServiceName: aws.String("test-service-name"),
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestMakeTaskSetResourceState(t *testing.T) {
now := time.Now()
taskSet := &types.TaskSet{
Status: &tc.status,
// Folowing fields are required to avoid nil pointer panic.
// Following fields are required to avoid nil pointer panic.
TaskSetArn: aws.String("test-task-set-arn"),
Id: aws.String("test-task-set-id"),
ServiceArn: aws.String("test-service-arn"),
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestMakeTaskResourceState(t *testing.T) {
now := time.Now()
task := &types.Task{
HealthStatus: tc.healthStatus,
// Folowing fields are required to avoid nil pointer panic.
// Following fields are required to avoid nil pointer panic.
LastStatus: aws.String("test-last-status"),
TaskArn: aws.String("arn:aws:ecs:region:account-id:task/test-cluster/test-task-id"),
CreatedAt: aws.Time(now),
Expand Down
Loading

0 comments on commit 63c8d77

Please sign in to comment.