mirror of
https://github.com/storytold/irsa-manager.git
synced 2026-10-23 08:05:25 +00:00
bugfix s3 bucket name
This commit is contained in:
+2
-10
@@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"flag"
|
"flag"
|
||||||
"os"
|
"os"
|
||||||
@@ -26,7 +25,6 @@ import (
|
|||||||
// to ensure that exec-entrypoint and run can make use of them.
|
// to ensure that exec-entrypoint and run can make use of them.
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
|
|
||||||
awsclient "github.com/kkb0318/irsa-manager/internal/client"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
@@ -124,15 +122,9 @@ func main() {
|
|||||||
os.Exit(1)
|
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{
|
if err = (&controller.IRSASetupReconciler{
|
||||||
Client: mgr.GetClient(),
|
Client: mgr.GetClient(),
|
||||||
Scheme: mgr.GetScheme(),
|
Scheme: mgr.GetScheme(),
|
||||||
AwsClient: awsClient,
|
|
||||||
}).SetupWithManager(mgr); err != nil {
|
}).SetupWithManager(mgr); err != nil {
|
||||||
setupLog.Error(err, "unable to create controller", "controller", "IRSASetup")
|
setupLog.Error(err, "unable to create controller", "controller", "IRSASetup")
|
||||||
os.Exit(1)
|
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.
|
// 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.
|
// The function configures the bucket to have its ownership controlled by the bucket creator.
|
||||||
func (a *AwsS3Client) CreateBucketPublic(ctx context.Context) error {
|
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)
|
bucket := aws.String(a.bucketName)
|
||||||
_, err := a.Client.CreateBucket(ctx, &s3.CreateBucketInput{
|
_, err := a.Client.CreateBucket(ctx, &s3.CreateBucketInput{
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"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/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/iam"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/sts"
|
"github.com/aws/aws-sdk-go-v2/service/sts"
|
||||||
@@ -35,6 +38,12 @@ func NewAwsClientFactory(ctx context.Context) (*AwsClientFactory, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to load SDK config, %w", err)
|
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
|
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{
|
return &AwsS3Client{
|
||||||
s3.NewFromConfig(a.config),
|
Client: s3.NewFromConfig(a.config),
|
||||||
region,
|
region: region,
|
||||||
bucketName,
|
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 {
|
if err := r.Get(ctx, req.NamespacedName, obj); err != nil {
|
||||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
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"})
|
kubeClient, err := kubernetes.NewKubernetesClient(r.Client, kubernetes.Owner{Field: "irsa-manager"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctrl.Result{}, err
|
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.
|
// - 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.
|
// - 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 {
|
func reconcileSelfhosted(ctx context.Context, obj *irsav1alpha1.IRSASetup, awsClient awsclient.AwsClient, kubeClient *kubernetes.KubernetesClient) error {
|
||||||
|
log := ctrllog.FromContext(ctx)
|
||||||
if irsav1alpha1.IsSelfHostedReadyConditionTrue(*obj) {
|
if irsav1alpha1.IsSelfHostedReadyConditionTrue(*obj) {
|
||||||
// Selfhosted Setup have already succeeded
|
// Selfhosted Setup have already succeeded
|
||||||
|
log.Info("the self-hosted resources have already set up")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
log.Info("the self-hosted resources are setting up")
|
||||||
keyPair, err := selfhosted.CreateKeyPair()
|
keyPair, err := selfhosted.CreateKeyPair()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -181,6 +189,7 @@ func reconcileSelfhosted(ctx context.Context, obj *irsav1alpha1.IRSASetup, awsCl
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*obj = irsav1alpha1.SetupSelfHostedStatusReady(*obj, string(irsav1alpha1.SelfHostedReasonReady), "successfully setup resources for self-hosted")
|
*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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,18 +15,20 @@ type AwsS3IdPFactory struct {
|
|||||||
jwksFileName string
|
jwksFileName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAwsS3IdpFactory(ctx context.Context,
|
func NewAwsS3IdpFactory(
|
||||||
region, bucketName string,
|
ctx context.Context,
|
||||||
|
region,
|
||||||
|
bucketName string,
|
||||||
jwk *selfhosted.JWK,
|
jwk *selfhosted.JWK,
|
||||||
jwksFileName string,
|
jwksFileName string,
|
||||||
awsClient awsclient.AwsClient,
|
awsClient awsclient.AwsClient,
|
||||||
) (*AwsS3IdPFactory, error) {
|
) (*AwsS3IdPFactory, error) {
|
||||||
return &AwsS3IdPFactory{
|
return &AwsS3IdPFactory{
|
||||||
region,
|
region: region,
|
||||||
bucketName,
|
bucketName: bucketName,
|
||||||
awsClient,
|
awsClient: awsClient,
|
||||||
jwk,
|
jwk: jwk,
|
||||||
jwksFileName,
|
jwksFileName: jwksFileName,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user