Skip to content

Commit 07a296f

Browse files
invidianDongsu Park
andcommitted
pkg/cloud/services/s3: initial commit
This commit adds initial implementation of S3 service, which will be used to store bootstrap data for nodes, which do not support pulling them from Secret Manager, like ones using Ignition as bootstrap system. This commit also adds a function for creating a real S3 client similar to other functions in this package. Co-authored-by: Dongsu Park <[email protected]> Signed-off-by: Mateusz Gozdek <[email protected]>
1 parent a897f04 commit 07a296f

File tree

10 files changed

+6823
-0
lines changed

10 files changed

+6823
-0
lines changed

pkg/cloud/scope/clients.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
"github.com/aws/aws-sdk-go/service/iam/iamiface"
3535
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
3636
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi/resourcegroupstaggingapiiface"
37+
"github.com/aws/aws-sdk-go/service/s3"
38+
"github.com/aws/aws-sdk-go/service/s3/s3iface"
3739
"github.com/aws/aws-sdk-go/service/secretsmanager"
3840
"github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface"
3941
"github.com/aws/aws-sdk-go/service/sqs"
@@ -182,6 +184,16 @@ func NewSSMClient(scopeUser cloud.ScopeUsage, session cloud.Session, logger clou
182184
return ssmClient
183185
}
184186

187+
// NewS3Client creates a new S3 API client for a given session.
188+
func NewS3Client(scopeUser cloud.ScopeUsage, session cloud.Session, logger cloud.Logger, target runtime.Object) s3iface.S3API {
189+
s3Client := s3.New(session.Session(), aws.NewConfig().WithLogLevel(awslogs.GetAWSLogLevel(logger)).WithLogger(awslogs.NewWrapLogr(logger)))
190+
s3Client.Handlers.Build.PushFrontNamed(getUserAgentHandler())
191+
s3Client.Handlers.CompleteAttempt.PushFront(awsmetrics.CaptureRequestMetrics(scopeUser.ControllerName()))
192+
s3Client.Handlers.Complete.PushBack(recordAWSPermissionsIssue(target))
193+
194+
return s3Client
195+
}
196+
185197
func recordAWSPermissionsIssue(target runtime.Object) func(r *request.Request) {
186198
return func(r *request.Request) {
187199
if awsErr, ok := r.Error.(awserr.Error); ok {

pkg/cloud/services/interfaces.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ type SecurityGroupInterface interface {
102102
DeleteSecurityGroups() error
103103
ReconcileSecurityGroups() error
104104
}
105+
106+
// ObjectStoreInterface encapsulates the methods exposed to the machine actuator.
107+
type ObjectStoreInterface interface {
108+
DeleteBucket() error
109+
ReconcileBucket() error
110+
Delete(m *scope.MachineScope) error
111+
Create(m *scope.MachineScope, data []byte) (objectURL string, err error)
112+
}

pkg/cloud/services/mock_services/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ limitations under the License.
1919
//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt ec2_interface_mock.go > _ec2_interface_mock.go && mv _ec2_interface_mock.go ec2_interface_mock.go"
2020
//go:generate ../../../../hack/tools/bin/mockgen -destination secretsmanager_machine_interface_mock.go -package mock_services sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services SecretInterface
2121
//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt secretsmanager_machine_interface_mock.go > _secretsmanager_machine_interface_mock.go && mv _secretsmanager_machine_interface_mock.go secretsmanager_machine_interface_mock.go"
22+
//go:generate ../../../../hack/tools/bin/mockgen -destination objectstore_machine_interface_mock.go -package mock_services sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services ObjectStoreInterface
23+
//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt objectstore_machine_interface_mock.go > _objectstore_machine_interface_mock.go && mv _objectstore_machine_interface_mock.go objectstore_machine_interface_mock.go"
2224
//go:generate ../../../../hack/tools/bin/mockgen -destination autoscaling_interface_mock.go -package mock_services sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services ASGInterface
2325
//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt autoscaling_interface_mock.go > _autoscaling_interface_mock.go && mv _autoscaling_interface_mock.go autoscaling_interface_mock.go"
2426
//go:generate ../../../../hack/tools/bin/mockgen -destination elb_interface_mock.go -package mock_services sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services ELBInterface

pkg/cloud/services/mock_services/objectstore_machine_interface_mock.go

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Run go generate to regenerate this mock.
18+
//go:generate ../../../../../hack/tools/bin/mockgen -destination s3api_mock.go -package mock_s3iface github.com/aws/aws-sdk-go/service/s3/s3iface S3API
19+
//go:generate /usr/bin/env bash -c "cat ../../../../../hack/boilerplate/boilerplate.generatego.txt s3api_mock.go > _s3api_mock.go && mv _s3api_mock.go s3api_mock.go"
20+
package mock_s3iface //nolint

0 commit comments

Comments
 (0)