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

feat: Allow to continue template execution using "ignoreError" property #1550

Merged

Conversation

BenjaminDecreusefond
Copy link
Contributor

Hi @alfespa17 !

I'd like to propose this small change and add a new field to the Terrakube template. I change the Flow template in the API and added it to the Executor job.

However, I'd like your inputs about it, I think I'm missing the part where the data is transmitted from the API that parse the yaml to the Executor that use the content of the Yaml to run the Job. I tried to find it but I couldn't find the connection between the 2 components unfortunately. My guess is that the API set the job in the queue and the executor will pick'em for execute. I'm really not sure that the field ingore_error will be available in the Executor context. Could you explain me please ? :)

Regards

@alfespa17
Copy link
Member

This looks better, let me check the logic that you have changed, and I will let you know if it requires any additional change

@alfespa17
Copy link
Member

This is the part of the code that is parsing the YAML file

The job table has a field called "tcl" that has the base64 encoded yaml that will be executed when the job is running.

This is the service that parse the yaml into a java class:

FlowConfig temp = yaml.load(new String(Base64.getDecoder().decode(tcl)));

By the way TCL means "terrakube configuration language"

When the job is running it is checking the pending steps here

Optional<Flow> flow = Optional.ofNullable(tclService.getNextFlow(job));

Parsing the pending steps from here

And it validates the pending job parts here

Optional<Flow> flow = Optional.ofNullable(tclService.getNextFlow(job));

@BenjaminDecreusefond
Copy link
Contributor Author

I do follow you until there
Optional<Flow> flow = Optional.ofNullable(tclService.getNextFlow(job)); however I have trouble to understand why this on the plan seem to do nothing ? I don't understand what happens when we are using the terraformPlan type ?

@alfespa17
Copy link
Member

I do follow you until there Optional<Flow> flow = Optional.ofNullable(tclService.getNextFlow(job)); however I have trouble to understand why this on the plan seem to do nothing ? I don't understand what happens when we are using the terraformPlan type ?

All of those case are executing the same code:

                case terraformPlanDestroy:
                case terraformPlan:
                case terraformApply:
                case terraformDestroy:
                case customScripts:
                    if (executorService.execute(job, stepId, flow.get()) != null)
                        log.info("Executing Job {} Step Id {}", job.getId(), stepId);
                    else {
                        log.error("Error when sending context to executor marking job {} as failed, step count {}", job.getId(), job.getStep().size());
                        job.setStatus(JobStatus.failed);
                        jobRepository.save(job);
                        Step step = stepRepository.getReferenceById(UUID.fromString(stepId));
                        step.setName("Error sending to executor, check logs");
                        stepRepository.save(step);
                    }
                    break;

That is a way to reuse the case with the same logic that begins in if (executorService.execute(job, stepId, flow.get()) != null)

@BenjaminDecreusefond
Copy link
Contributor Author

BenjaminDecreusefond commented Nov 20, 2024

Okayy thank you @alfespa17 that's a Java trick ! I didn't know it !

I added the value to the ExecutorContext which should then allow the Executor code to retrieve the value, am I right ?

@alfespa17
Copy link
Member

Okayy thank you @alfespa17 that's a Java trick ! I didn't know it !

I added the value to the ExecutorContext which should then allow the Executor code to retrieve the value, am I right ?

I think your change should work just one small thing can you rename ignore_error to ignoreError so we use the same variable name standard?

@BenjaminDecreusefond
Copy link
Contributor Author

BenjaminDecreusefond commented Nov 21, 2024

Sure! Done ! :) @alfespa17

@alfespa17
Copy link
Member

I tested with this and it is working, it is ignoring the terraform plan error and it is running the script

flow:
- type: "terraformPlan"
  name: "Plan"
  step: 100
  ignoreError: true
  commands:
  - runtime: "BASH"
    priority: 100
    after: true
    script: |
      echo "Running after error"

image

@alfespa17 alfespa17 changed the title fix: Continue plan template on error feat: Allow to continue template execution using "ignoreError" property Nov 21, 2024
@alfespa17 alfespa17 merged commit 97e9832 into AzBuilder:main Nov 21, 2024
3 checks passed
@BenjaminDecreusefond
Copy link
Contributor Author

Hi @alfespa17 !

Would it be possible to have a release please ? :)

thanks ! :)

@alfespa17
Copy link
Member

You can check 2.24.0-beta.6 @BenjaminDecreusefond

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants