mirror of
https://github.com/storytold/irsa-manager.git
synced 2026-10-09 00:09:43 +00:00
bugfix s3 bucket name
This commit is contained in:
+2
-10
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"os"
|
||||
@@ -26,7 +25,6 @@ import (
|
||||
// to ensure that exec-entrypoint and run can make use of them.
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
|
||||
awsclient "github.com/kkb0318/irsa-manager/internal/client"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
@@ -124,15 +122,9 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
awsClient, err := awsclient.NewAwsClientFactory(context.TODO())
|
||||
if err != nil {
|
||||
setupLog.Error(err, "unable to start manager")
|
||||
os.Exit(1)
|
||||
}
|
||||
if err = (&controller.IRSASetupReconciler{
|
||||
Client: mgr.GetClient(),
|
||||
Scheme: mgr.GetScheme(),
|
||||
AwsClient: awsClient,
|
||||
Client: mgr.GetClient(),
|
||||
Scheme: mgr.GetScheme(),
|
||||
}).SetupWithManager(mgr); err != nil {
|
||||
setupLog.Error(err, "unable to create controller", "controller", "IRSASetup")
|
||||
os.Exit(1)
|
||||
|
||||
@@ -113,6 +113,7 @@ func (a *AwsS3Client) PutObjectPublic(ctx context.Context, input ObjectInput) er
|
||||
// CreateBucketPublic creates a new S3 bucket with public access settings in the specified region.
|
||||
// The function configures the bucket to have its ownership controlled by the bucket creator.
|
||||
func (a *AwsS3Client) CreateBucketPublic(ctx context.Context) error {
|
||||
log.Printf("creating S3 bucket... Name: %s, Region: %s \n", a.bucketName, a.Region())
|
||||
bucket := aws.String(a.bucketName)
|
||||
_, err := a.Client.CreateBucket(ctx, &s3.CreateBucketInput{
|
||||
Bucket: bucket,
|
||||
|
||||
@@ -3,8 +3,11 @@ package client
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
|
||||
"github.com/aws/aws-sdk-go-v2/service/iam"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||
@@ -35,6 +38,12 @@ func NewAwsClientFactory(ctx context.Context) (*AwsClientFactory, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to load SDK config, %w", err)
|
||||
}
|
||||
roleArn := os.Getenv("AWS_ROLE_ARN")
|
||||
if roleArn != "" {
|
||||
stsSvc := sts.NewFromConfig(cfg)
|
||||
creds := stscreds.NewAssumeRoleProvider(stsSvc, roleArn)
|
||||
cfg.Credentials = aws.NewCredentialsCache(creds)
|
||||
}
|
||||
return &AwsClientFactory{config: cfg}, nil
|
||||
}
|
||||
|
||||
@@ -50,10 +59,10 @@ func (a *AwsClientFactory) StsClient() *AwsStsClient {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AwsClientFactory) S3Client(bucketName, region string) *AwsS3Client {
|
||||
func (a *AwsClientFactory) S3Client(region, bucketName string) *AwsS3Client {
|
||||
return &AwsS3Client{
|
||||
s3.NewFromConfig(a.config),
|
||||
region,
|
||||
bucketName,
|
||||
Client: s3.NewFromConfig(a.config),
|
||||
region: region,
|
||||
bucketName: bucketName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,11 @@ func (r *IRSASetupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
|
||||
if err := r.Get(ctx, req.NamespacedName, obj); err != nil {
|
||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||
}
|
||||
awsClient, err := awsclient.NewAwsClientFactory(ctx)
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
r.AwsClient = awsClient
|
||||
kubeClient, err := kubernetes.NewKubernetesClient(r.Client, kubernetes.Owner{Field: "irsa-manager"})
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
@@ -128,10 +133,13 @@ func (r *IRSASetupReconciler) reconcileDelete(ctx context.Context, obj *irsav1al
|
||||
// - If the self-hosted setup was previously attempted but failed, or if it's being run for the first time, it will attempt to create all necessary resources. This includes the creation of key pairs, JWKs, OIDC IDP configurations, and Kubernetes secrets.
|
||||
// - The function enforces a 'force update' strategy in case of failures related to kubernetes Secrets creation or OIDC setup. This means it starts from scratch to ensure all components are correctly configured.
|
||||
func reconcileSelfhosted(ctx context.Context, obj *irsav1alpha1.IRSASetup, awsClient awsclient.AwsClient, kubeClient *kubernetes.KubernetesClient) error {
|
||||
log := ctrllog.FromContext(ctx)
|
||||
if irsav1alpha1.IsSelfHostedReadyConditionTrue(*obj) {
|
||||
// Selfhosted Setup have already succeeded
|
||||
log.Info("the self-hosted resources have already set up")
|
||||
return nil
|
||||
}
|
||||
log.Info("the self-hosted resources are setting up")
|
||||
keyPair, err := selfhosted.CreateKeyPair()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -181,6 +189,7 @@ func reconcileSelfhosted(ctx context.Context, obj *irsav1alpha1.IRSASetup, awsCl
|
||||
return err
|
||||
}
|
||||
*obj = irsav1alpha1.SetupSelfHostedStatusReady(*obj, string(irsav1alpha1.SelfHostedReasonReady), "successfully setup resources for self-hosted")
|
||||
log.Info("the self-hosted resources have successfully set up")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -15,18 +15,20 @@ type AwsS3IdPFactory struct {
|
||||
jwksFileName string
|
||||
}
|
||||
|
||||
func NewAwsS3IdpFactory(ctx context.Context,
|
||||
region, bucketName string,
|
||||
func NewAwsS3IdpFactory(
|
||||
ctx context.Context,
|
||||
region,
|
||||
bucketName string,
|
||||
jwk *selfhosted.JWK,
|
||||
jwksFileName string,
|
||||
awsClient awsclient.AwsClient,
|
||||
) (*AwsS3IdPFactory, error) {
|
||||
return &AwsS3IdPFactory{
|
||||
region,
|
||||
bucketName,
|
||||
awsClient,
|
||||
jwk,
|
||||
jwksFileName,
|
||||
region: region,
|
||||
bucketName: bucketName,
|
||||
awsClient: awsClient,
|
||||
jwk: jwk,
|
||||
jwksFileName: jwksFileName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user