Skip to content

Commit

Permalink
Add not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhtc1202 committed May 27, 2021
1 parent a81af1a commit 8808feb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pkg/app/piped/cloudprovider/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["cloudprovider.go"],
importpath = "github.com/pipe-cd/pipe/pkg/app/piped/cloudprovider",
visibility = ["//visibility:public"],
)
24 changes: 24 additions & 0 deletions pkg/app/piped/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cloudprovider

import (
"errors"
)

var (
ErrNotFound = errors.New("not found")
ErrUnimplemented = errors.New("unimplemented")
)
1 change: 1 addition & 0 deletions pkg/app/piped/cloudprovider/ecs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
importpath = "github.com/pipe-cd/pipe/pkg/app/piped/cloudprovider/ecs",
visibility = ["//visibility:public"],
deps = [
"//pkg/app/piped/cloudprovider:go_default_library",
"//pkg/config:go_default_library",
"@com_github_aws_aws_sdk_go_v2//aws:go_default_library",
"@com_github_aws_aws_sdk_go_v2_config//:go_default_library",
Expand Down
6 changes: 4 additions & 2 deletions pkg/app/piped/cloudprovider/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"go.uber.org/zap"

"github.com/pipe-cd/pipe/pkg/app/piped/cloudprovider"
)

type client struct {
Expand Down Expand Up @@ -167,15 +169,15 @@ func (c *client) GetPrimaryTaskSet(ctx context.Context, service types.Service) (
return nil, fmt.Errorf("failed to get primary task set of service %s: %w", *service.ServiceName, err)
}
if len(output.Services) == 0 {
return nil, fmt.Errorf("failed to get primary task set of service %s: services not found", *service.ServiceName)
return nil, fmt.Errorf("failed to get primary task set of service %s: services empty", *service.ServiceName)
}
taskSets := output.Services[0].TaskSets
for _, taskSet := range taskSets {
if aws.ToString(taskSet.Status) == "PRIMARY" {
return &taskSet, nil
}
}
return nil, nil
return nil, cloudprovider.ErrNotFound
}

func (c *client) DeleteTaskSet(ctx context.Context, service types.Service, taskSet types.TaskSet) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/executor/ecs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
importpath = "github.com/pipe-cd/pipe/pkg/app/piped/executor/ecs",
visibility = ["//visibility:public"],
deps = [
"//pkg/app/piped/cloudprovider:go_default_library",
"//pkg/app/piped/cloudprovider/ecs:go_default_library",
"//pkg/app/piped/deploysource:go_default_library",
"//pkg/app/piped/executor:go_default_library",
Expand Down
5 changes: 4 additions & 1 deletion pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package ecs

import (
"context"
"errors"

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

"github.com/pipe-cd/pipe/pkg/app/piped/cloudprovider"
provider "github.com/pipe-cd/pipe/pkg/app/piped/cloudprovider/ecs"
"github.com/pipe-cd/pipe/pkg/app/piped/deploysource"
"github.com/pipe-cd/pipe/pkg/app/piped/executor"
Expand Down Expand Up @@ -143,7 +145,8 @@ func build(ctx context.Context, in *executor.Input, client provider.Client, task

// Get current PRIMARY task set.
prevPrimaryTaskSet, err := client.GetPrimaryTaskSet(ctx, *service)
if err != nil {
// Ignore error in case it's not found error, the prevPrimaryTaskSet doesn't exist for newly created Service.
if err != nil && !errors.Is(err, cloudprovider.ErrNotFound) {
in.LogPersister.Errorf("Failed to create ECS task set %s: %v", *serviceDefinition.ServiceName, err)
return false
}
Expand Down

0 comments on commit 8808feb

Please sign in to comment.