Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions cmd/nodeadm/sync_artifacts/sync_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/aws/eks-hybrid/internal/aws"
"github.com/aws/eks-hybrid/internal/cli"
"github.com/aws/eks-hybrid/internal/logger"
"github.com/aws/eks-hybrid/internal/ssm"
)

const syncArtifactsHelpText = `Examples:
Expand Down Expand Up @@ -211,8 +210,7 @@ func (d *Downloader) collectArtifacts() ([]ArtifactInfo, error) {
}

// SSM artifacts
ssmInstaller := ssm.NewSSMInstaller(d.Logger, d.Region)
installerURL, err := d.getSSMInstallerURL(ssmInstaller)
installerURL, err := d.getSSMInstallerURL()
if err == nil {
// Add the main SSM installer
artifacts = append(artifacts, ArtifactInfo{
Expand Down Expand Up @@ -303,16 +301,21 @@ func (d *Downloader) streamToS3(ctx context.Context, svc *s3.Client, url, s3Key
return errors.Wrap(err, "uploading to S3 using manager")
}

func (d *Downloader) getSSMInstallerURL(ssmInstaller ssm.Source) (string, error) {
// We need to use reflection or a type assertion to get the URL builder
// For now, let's construct the URL directly using the same logic as SSM source
func (d *Downloader) getSSMInstallerURL() (string, error) {
// Construct the URL directly using the same logic as SSM source
variant, err := d.detectPlatformVariant()
if err != nil {
return "", err
}

platform := fmt.Sprintf("%v_%v", variant, d.Arch)
return fmt.Sprintf("https://amazon-ssm-%v.s3.%v.amazonaws.com/latest/%v/ssm-setup-cli", d.Region, d.Region, platform), nil
dnsSuffix := d.AwsSource.RegionInfo.DnsSuffix
Comment thread
tatlat marked this conversation as resolved.
if dnsSuffix == "" {
partition := aws.GetPartitionFromRegionFallback(d.Region)
dnsSuffix = aws.GetPartitionDNSSuffix(partition)
}

platform := fmt.Sprintf("%s_%s", variant, d.Arch)
return fmt.Sprintf("https://amazon-ssm-%s.s3.%s.%s/latest/%s/ssm-setup-cli", d.Region, d.Region, dnsSuffix, platform), nil
}

func (d *Downloader) detectPlatformVariant() (string, error) {
Expand All @@ -326,9 +329,15 @@ func (d *Downloader) detectPlatformVariant() (string, error) {
}

func (d *Downloader) generateCustomManifest(artifacts []ArtifactInfo) error {
dnsSuffix := d.AwsSource.RegionInfo.DnsSuffix
if dnsSuffix == "" {
partition := aws.GetPartitionFromRegionFallback(d.Region)
dnsSuffix = aws.GetPartitionDNSSuffix(partition)
}

// Create base S3 URL
baseS3URL := fmt.Sprintf("https://%s.s3.%s.amazonaws.com/%s/%d",
d.S3Bucket, d.Region, strings.TrimSuffix(d.S3Prefix, "/"), d.SyncTimestamp)
baseS3URL := fmt.Sprintf("https://%s.s3.%s.%s/%s/%d",
d.S3Bucket, d.Region, dnsSuffix, strings.TrimSuffix(d.S3Prefix, "/"), d.SyncTimestamp)

// Build artifact list with custom S3 URIs
var eksArtifacts []aws.Artifact
Expand Down
12 changes: 9 additions & 3 deletions internal/aws/ecr/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"github.com/aws/eks-hybrid/internal/system"
)

const hybridServicesDomain = "amazonaws.com"

// Returns the base64 encoded authorization token string for ECR of the format "AWS:XXXXX"
func GetAuthorizationToken(awsConfig *aws.Config) (string, error) {
ecrClient := ecr.NewFromConfig(*awsConfig)
Expand All @@ -42,7 +40,15 @@ func GetEKSRegistry(region string, regionConfig *awsinternal.RegionData) (ECRReg
}

func GetEKSHybridRegistry(region string, regionConfig *awsinternal.RegionData) (ECRRegistry, error) {
return getEksRegistryWithServiceDomainAndRegionConfig(region, hybridServicesDomain, regionConfig)
var servicesDomain string

if regionConfig != nil && regionConfig.DnsSuffix != "" {
servicesDomain = regionConfig.DnsSuffix
} else {
partition := awsinternal.GetPartitionFromRegionFallback(region)
servicesDomain = awsinternal.GetPartitionDNSSuffix(partition)
}
return getEksRegistryWithServiceDomainAndRegionConfig(region, servicesDomain, regionConfig)
}

func getEksRegistryWithServiceDomainAndRegionConfig(region, servicesDomain string, regionConfig *awsinternal.RegionData) (ECRRegistry, error) {
Expand Down
6 changes: 5 additions & 1 deletion internal/flows/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func (i *Installer) installCredentialProcess(ctx context.Context) error {
return err
}
case creds.SsmCredentialProvider:
ssmInstaller := ssm.NewSSMInstaller(i.Logger, i.SsmRegion)
ssmInstaller := ssm.NewSSMInstaller(
i.Logger,
i.SsmRegion,
ssm.WithDnsSuffix(i.AwsSource.RegionInfo.DnsSuffix),
)

i.Logger.Info("Installing SSM agent installer...")
if err := ssm.Install(ctx, ssm.InstallOptions{
Expand Down
6 changes: 5 additions & 1 deletion internal/flows/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ func (u *Upgrader) upgradeCredentialProvider(ctx context.Context) error {
}
case creds.SsmCredentialProvider:
nodeConfig := u.NodeProvider.GetNodeConfig()
ssmInstaller := ssm.NewSSMInstaller(u.Logger, nodeConfig.Spec.Cluster.Region)
ssmInstaller := ssm.NewSSMInstaller(
u.Logger,
nodeConfig.Spec.Cluster.Region,
ssm.WithDnsSuffix(u.AwsSource.RegionInfo.DnsSuffix),
)

u.Logger.Info("Upgrading SSM agent installer...")
if err := ssm.Upgrade(ctx, ssm.InstallOptions{
Expand Down
22 changes: 19 additions & 3 deletions internal/ssm/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"go.uber.org/zap"

awsinternal "github.com/aws/eks-hybrid/internal/aws"
"github.com/aws/eks-hybrid/internal/util"
)

Expand Down Expand Up @@ -78,6 +79,14 @@ func WithPublicKey(key string) SSMInstallerOption {
}
}

// WithDnsSuffix allows setting the DNS suffix from manifest data
// This takes precedence over region-based partition detection
func WithDnsSuffix(dnsSuffix string) SSMInstallerOption {
return func(s *ssmInstallerSource) {
s.dnsSuffix = dnsSuffix
}
}

// SSMInstaller provides a Source that retrieves the SSM installer from the official
// release endpoint.
func NewSSMInstaller(logger *zap.Logger, region string, opts ...SSMInstallerOption) Source {
Expand All @@ -99,6 +108,7 @@ func NewSSMInstaller(logger *zap.Logger, region string, opts ...SSMInstallerOpti

type ssmInstallerSource struct {
region string
dnsSuffix string // DNS suffix from manifest (optional, falls back to region-based detection)
logger *zap.Logger
buildSSMURL func() (string, error)
publicKey string
Expand Down Expand Up @@ -135,15 +145,21 @@ func (s ssmInstallerSource) PublicKey() string {
return s.publicKey
}

// Rename existing buildSSMURL to defaultBuildSSMURL
// defaultBuildSSMURL builds the SSM installer URL with partition-aware DNS suffix
func (s ssmInstallerSource) defaultBuildSSMURL() (string, error) {
variant, err := detectPlatformVariant()
if err != nil {
return "", err
}

platform := fmt.Sprintf("%v_%v", variant, runtime.GOARCH)
return fmt.Sprintf("https://amazon-ssm-%v.s3.%v.amazonaws.com/latest/%v/ssm-setup-cli", s.region, s.region, platform), nil
dnsSuffix := s.dnsSuffix
if dnsSuffix == "" {
partition := awsinternal.GetPartitionFromRegionFallback(s.region)
dnsSuffix = awsinternal.GetPartitionDNSSuffix(partition)
}

platform := fmt.Sprintf("%s_%s", variant, runtime.GOARCH)
return fmt.Sprintf("https://amazon-ssm-%s.s3.%s.%s/latest/%s/ssm-setup-cli", s.region, s.region, dnsSuffix, platform), nil
}

// detectPlatformVariant returns a portion of the SSM installers URL that is dependent on the
Expand Down
Loading