Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Image URI CfnOutput Not Working #231

Open
Wildhammer opened this issue Feb 8, 2024 · 2 comments
Open

Docker Image URI CfnOutput Not Working #231

Wildhammer opened this issue Feb 8, 2024 · 2 comments
Labels
bug Something isn't working effort/medium 1 week tops priority/p2 Dependent on community feedback. PR's are welcome :)

Comments

@Wildhammer
Copy link

Description of the bug:

I want to create a docker image using CDK DockerImageAsset and pass the image URI to the cronjob tutorial example as an environment variable. My intention is to ultimately use the image URI for creating my service pods.

Reproduction Steps:

Just modify the example code at cdk8s-awscdk-resolver and add cdk code for building an image. Then use the CfnOutput for imageUri same way as bucket name is passed in the example:

import * as aws from 'aws-cdk-lib';
import * as k8s from 'cdk8s';
import * as kplus from 'cdk8s-plus-27';

import { AwsCdkResolver } from '@cdk8s/awscdk-resolver';
import { DockerImageAsset } from 'aws-cdk-lib/aws-ecr-assets';
import { CfnOutput } from 'aws-cdk-lib';

const awsApp = new aws.App();
const stack = new aws.Stack(awsApp, 'aws');

const k8sApp = new k8s.App({ resolvers: [new AwsCdkResolver()] });
const manifest = new k8s.Chart(k8sApp, 'Manifest');

const bucket = new aws.aws_s3.Bucket(stack, 'Bucket');
const bucketName = new aws.CfnOutput(stack, 'BucketName', {
  value: bucket.bucketName,
});

const image = new DockerImageAsset(stack, 'Image', {
  directory: 'app',
});
const imageUri = new CfnOutput(stack, 'imageUri', { value: image.imageUri });

new kplus.CronJob(manifest, 'CronJob', {
  schedule: k8s.Cron.daily(),
  containers: [{
    image: 'job',
    envVariables: {
      // directly passing the value of the `CfnOutput` containing 
      // the deploy time bucket name
      BUCKET_NAME: kplus.EnvValue.fromValue(bucketName.value),
      IMAGE_NAME: kplus.EnvValue.fromValue(imageUri.value)
    }
 }]
});

awsApp.synth();
k8sApp.synth();

Error Log:

Error: Failed serializing construct at path 'Manifest/CronJob/Resource' with name 'manifest-cronjob-c86481e8': Error: Unable to find output defined for ${Token[TOKEN.28]} (Inspected stacks: )

Environment:

  • ^0.0.57:
  • MacOS:

Other:

I tried creating an iam role and passing the role name as env variable. That seemed to work fine.


This is 🐛 Bug Report

@Wildhammer Wildhammer added bug Something isn't working needs-triage Priority and effort undetermined yet labels Feb 8, 2024
@iliapolo iliapolo added effort/medium 1 week tops priority/p2 Dependent on community feedback. PR's are welcome :) and removed needs-triage Priority and effort undetermined yet labels Jun 3, 2024
@jfalkenstein
Copy link

I'm encountering this too. I did a little debugging and it appears as if the issue is the tokens for the docker image uri isn't a "Reference" like most other CfnOutput values are. Instead, it's a FnSub:

image

In this case, the evaluation of IsReference() resolves to false and the output isn't resolved.

@jfalkenstein
Copy link

I think a short-term hacky solution to this would be save the image uri to an SSM parameter and then set the CfnOutput value to the SSM Parameter's .value attribute. Thus, the output wouldn't be a FnSub but instead would be just a normal reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working effort/medium 1 week tops priority/p2 Dependent on community feedback. PR's are welcome :)
Projects
None yet
Development

No branches or pull requests

3 participants