Skip to content

Commit

Permalink
checkIfImageExists
Browse files Browse the repository at this point in the history
  • Loading branch information
tedteng committed Aug 18, 2022
1 parent b50113d commit 193e80b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/admission/mutator/shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (s *shootMutator) isOwnedbyAliCloud(ctx context.Context, shoot *corev1beta1
if err != nil {
return false, err
}
if exist, err := shootECSClient.CheckIfImageExists(ctx, imageId); err != nil {
if exist, err := shootECSClient.CheckIfImageExists(imageId); err != nil {
return false, err
} else if exist {
return shootECSClient.CheckIfImageOwnedByAliCloud(imageId)
Expand Down
8 changes: 4 additions & 4 deletions pkg/admission/mutator/shoot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ var _ = Describe("Mutating Shoot", func() {
),

alicloudClientFactory.EXPECT().NewECSClient(regionId, accessKeyID, accessKeySecret).Return(ecsClient, nil),
ecsClient.EXPECT().CheckIfImageExists(ctx, imageId).Return(false, nil),
ecsClient.EXPECT().CheckIfImageExists(imageId).Return(false, nil),
)
err := mutator.Mutate(ctx, newShoot, nil)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -290,7 +290,7 @@ var _ = Describe("Mutating Shoot", func() {
),

alicloudClientFactory.EXPECT().NewECSClient(regionId, accessKeyID, accessKeySecret).Return(ecsClient, nil),
ecsClient.EXPECT().CheckIfImageExists(ctx, imageId).Return(false, nil),
ecsClient.EXPECT().CheckIfImageExists(imageId).Return(false, nil),
//ecsClient.EXPECT().CheckIfImageOwnedByAliCloud(imageId).Return(false, nil)
)
err := mutator.Mutate(ctx, newShoot, nil)
Expand Down Expand Up @@ -321,7 +321,7 @@ var _ = Describe("Mutating Shoot", func() {
),

alicloudClientFactory.EXPECT().NewECSClient(regionId, accessKeyID, accessKeySecret).Return(ecsClient, nil),
ecsClient.EXPECT().CheckIfImageExists(ctx, imageId).Return(true, nil),
ecsClient.EXPECT().CheckIfImageExists(imageId).Return(true, nil),
ecsClient.EXPECT().CheckIfImageOwnedByAliCloud(imageId).Return(true, nil),
)
err := mutator.Mutate(ctx, newShoot, nil)
Expand Down Expand Up @@ -368,7 +368,7 @@ var _ = Describe("Mutating Shoot", func() {
),

alicloudClientFactory.EXPECT().NewECSClient(regionId, accessKeyID, accessKeySecret).Return(ecsClient, nil),
ecsClient.EXPECT().CheckIfImageExists(ctx, imageId).Return(false, nil),
ecsClient.EXPECT().CheckIfImageExists(imageId).Return(false, nil),
)
err := mutator.Mutate(ctx, newShoot, oldShoot)
Expect(err).NotTo(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion pkg/alicloud/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (f *clientFactory) NewECSClient(region, accessKeyID, accessKeySecret string
}

// CheckIfImageExists checks whether given imageID can be accessed by the client.
func (c *ecsClient) CheckIfImageExists(ctx context.Context, imageID string) (bool, error) {
func (c *ecsClient) CheckIfImageExists(imageID string) (bool, error) {
request := ecs.CreateDescribeImagesRequest()
request.ImageId = imageID
request.SetScheme("HTTPS")
Expand Down
2 changes: 1 addition & 1 deletion pkg/alicloud/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type ecsClient struct {

// ECS is an interface which declares ECS related methods.
type ECS interface {
CheckIfImageExists(ctx context.Context, imageID string) (bool, error)
CheckIfImageExists(imageID string) (bool, error)
CheckIfImageOwnedByAliCloud(imageID string) (bool, error)
ShareImageToAccount(ctx context.Context, regionID, imageID, accountID string) error
GetSecurityGroup(name string) (*ecs.DescribeSecurityGroupsResponse, error)
Expand Down

0 comments on commit 193e80b

Please sign in to comment.