@@ -142,7 +142,7 @@ func TestK8SServiceSecurityContextAnnotationRenderCorrectly(t *testing.T) {
142142 t ,
143143 map [string ]string {
144144 "securityContext.privileged" : "true" ,
145- "securityContext.runAsUser" : "1000" ,
145+ "securityContext.runAsUser" : "1000" ,
146146 },
147147 )
148148 renderedContainers := deployment .Spec .Template .Spec .Containers
@@ -524,6 +524,58 @@ func TestK8SServiceWithContainerCommandHasCommandSpec(t *testing.T) {
524524 assert .Equal (t , appContainer .Command , []string {"echo" , "Hello world" })
525525}
526526
527+ // Test that omitting aws.irsa.role_arn does not render the IRSA vars
528+ func TestK8SServiceWithoutIRSA (t * testing.T ) {
529+ t .Parallel ()
530+
531+ deployment := renderK8SServiceDeploymentWithSetValues (
532+ t ,
533+ map [string ]string {},
534+ )
535+ renderedPodSpec := deployment .Spec .Template .Spec
536+ assert .Equal (t , len (renderedPodSpec .Volumes ), 0 )
537+ renderedPodContainers := renderedPodSpec .Containers
538+ require .Equal (t , len (renderedPodContainers ), 1 )
539+ appContainer := renderedPodContainers [0 ]
540+ assert .Equal (t , len (appContainer .Env ), 0 )
541+ }
542+
543+ // Test that setting aws.irsa.role_arn renders the IRSA vars
544+ func TestK8SServiceWithIRSA (t * testing.T ) {
545+ t .Parallel ()
546+
547+ testRoleArn := "arn:aws:iam::123456789012:role/test-role"
548+ deployment := renderK8SServiceDeploymentWithSetValues (
549+ t ,
550+ map [string ]string {
551+ "aws.irsa.role_arn" : testRoleArn ,
552+ },
553+ )
554+ renderedPodSpec := deployment .Spec .Template .Spec
555+
556+ // Verify projected volume
557+ require .Equal (t , len (renderedPodSpec .Volumes ), 1 )
558+ volume := renderedPodSpec .Volumes [0 ]
559+ assert .Equal (t , volume .Name , "aws-iam-token" )
560+ require .NotNil (t , volume .VolumeSource .Projected )
561+ projectedVolume := volume .VolumeSource .Projected
562+ require .Equal (t , len (projectedVolume .Sources ), 1 )
563+ projectedVolumeSource := projectedVolume .Sources [0 ]
564+ require .NotNil (t , projectedVolumeSource .ServiceAccountToken )
565+ assert .Equal (t , projectedVolumeSource .ServiceAccountToken .Audience , "sts.amazonaws.com" )
566+
567+ // Verify injected env vars
568+ renderedPodContainers := renderedPodSpec .Containers
569+ require .Equal (t , len (renderedPodContainers ), 1 )
570+ appContainer := renderedPodContainers [0 ]
571+ assert .Equal (t , len (appContainer .Env ), 2 )
572+ roleArnEnv := appContainer .Env [0 ]
573+ assert .Equal (t , roleArnEnv .Name , "AWS_ROLE_ARN" )
574+ assert .Equal (t , roleArnEnv .Value , testRoleArn )
575+ tokenEnv := appContainer .Env [1 ]
576+ assert .Equal (t , tokenEnv .Name , "AWS_WEB_IDENTITY_TOKEN_FILE" )
577+ assert .Equal (t , tokenEnv .Value , "/var/run/secrets/eks.amazonaws.com/serviceaccount/token" )
578+ }
527579
528580// Test that providing tls configuration to Ingress renders correctly
529581func TestK8SServiceIngressMultiCert (t * testing.T ) {
0 commit comments