Skip to content

Commit

Permalink
Merge pull request #197 from kubefirst/fix_create_bucket_ssl_useast1
Browse files Browse the repository at this point in the history
fix-create-bucket-ssl-us-east1
  • Loading branch information
pagottoo committed Aug 8, 2022
2 parents 28cc6fe + 0afee7f commit cff506c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
33 changes: 26 additions & 7 deletions internal/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,38 @@ func DestroyBucketsInUse(destroyBuckets bool) {
func CreateBucket(dryRun bool, name string) {
log.Println("createBucketCalled")

s3Client := s3.New(GetAWSSession())
sess, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Region: aws.String(viper.GetString("aws.region")),
},
Profile: viper.GetString("aws.profile"),
})

if err != nil {
log.Println("failed to attempt bucket creation ", err.Error())
os.Exit(1)
}

s3Client := s3.New(sess)

log.Println("creating", "bucket", name)

regionName := viper.GetString("aws.region")
log.Println("region is ", regionName)

if !dryRun {
_, err := s3Client.CreateBucket(&s3.CreateBucketInput{
Bucket: &name,
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
LocationConstraint: aws.String(regionName),
},
})
if regionName == "us-east-1" {
_, err = s3Client.CreateBucket(&s3.CreateBucketInput{
Bucket: &name,
})
} else {
_, err = s3Client.CreateBucket(&s3.CreateBucketInput{
Bucket: &name,
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
LocationConstraint: aws.String(regionName),
},
})
}
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
Expand Down
7 changes: 4 additions & 3 deletions internal/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ func getItemsToBackup(apiGroup string, apiVersion string, resourceType string, n

// GetBackupCertificates create a backup of Certificates on AWS S3 in yaml files
func GetBackupCertificates() (string, error) {
config := configs.ReadConfig()
namespaces := getNamespacesToBackupSSL()
log.Println("GetBackupCertificates called")

bucketName := fmt.Sprintf("k1-%s", viper.GetString("aws.hostedzonename"))
//path := "cert-manager"
aws.CreateBucket(false, bucketName)

config := configs.ReadConfig()
namespaces := getNamespacesToBackupSSL()

log.Println("getting certificates")
certificates, err := getItemsToBackup("cert-manager.io", "v1", "certificates", namespaces, "")
if err != nil {
Expand Down

0 comments on commit cff506c

Please sign in to comment.