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

Respect service type in environment and pipeline variable patching, add dry run #37

Merged
merged 18 commits into from
Oct 15, 2024

Conversation

tobias-richter
Copy link
Contributor

@tobias-richter tobias-richter commented Oct 11, 2024

I have detected a bug in the patching of the environment variables.
In the current implementation the check if an environment variable should be removed takes only the name into account but not the actual service type the variable is applied to.

Example

When we first apply the following environment variable:

- name: VARIABLE
  value: author variable
  type: string
  service: author

When removing the service and applying the environment variables with

- name: VARIABLE
  value: author variable
  type: string

This led to the state that two environment variables were present in the environment and the old author environment variable was not cleaned up.

I have now changed the implementation and we are now also using the applied service during envaluation what environment variables need to be updated / deleted.

Since the pipeline variables looked like they will also get additional service / steps soon (currently only build is available) I have also adjusted the logic for the pipeline variable update.

Since I have introduced a enum for possible environment variable services and due to the new added service support for pipeline variables I had to separate the environment variables from the pipeline variables.

I have now also added an optional --dry-run flag which allows a preview of what the environment / pipeline variable step will do.

* add dry run mode pipeline vars
* ensure default service value is not serialized for env-vars
* ensure that service type of pipeline variables is also evaluated in PartialEq
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format your code using rustfmt: cargo fmt

@github-actions github-actions bot dismissed their stale review October 11, 2024 18:40

Removing outdated review.

@tobias-richter tobias-richter marked this pull request as ready for review October 14, 2024 08:17
@BerSomBen
Copy link
Collaborator

Hi @tobias-richter,
I prepared a local setup to review this changes.

First I used the latest pippo version, to verify the issue described.
I added a Variable as described to a) a pipeline, b) an environment.
Then I modified the pipeline.yml accordingly and removed the service: author. Correct would be, to remove this Entry, and readd it with default Service. After the next pippo "pipeline variables set" The Service must be build and no longer author
But its not. So: I can confirm issue.

@BerSomBen
Copy link
Collaborator

Hi @tobias-richter,

when I use my unchanged working pippo.json that I used to confirm this issue on main, I ran into a "thread 'main' panicked"

     Running `target/debug/pippo -c pippo.json -p *** -e *** -i *** pipeline vars list`
thread 'main' panicked at src/errors.rs:46:84:
called `Result::unwrap()` on an `Err` value: Error("missing field `status`", line: 1, column: 573)
note: run with `RUST_BACKTRACE=1` environment variable to display a backt

@tobias-richter
Copy link
Contributor Author

Hi @tobias-richter,

when I use my unchanged working pippo.json that I used to confirm this issue on main, I ran into a "thread 'main' panicked"

     Running `target/debug/pippo -c pippo.json -p *** -e *** -i *** pipeline vars list`
thread 'main' panicked at src/errors.rs:46:84:
called `Result::unwrap()` on an `Err` value: Error("missing field `status`", line: 1, column: 573)
note: run with `RUST_BACKTRACE=1` environment variable to display a backt

@tobias-richter
Copy link
Contributor Author

Sorry, @BerSomBen accidentially closed the PR. I will get in touch with you. I also noticed that kind of issue in one of my environments when the environment variables where wrongly set.

@tobias-richter
Copy link
Contributor Author

@BerSomBen the error message is kind of confusing because what is actually the case is that you have a pipeline variable configured for "author" service which is not correct!
When parsing the response it is then failing with your error message:

      {
        "name": "VARIABLE",
        "value": "author variable",
        "type": "string",
        "service": "author",
        "status": "ready"
      },

I have assigned #38 to you in order to add more resilience in that case. But with that solution every invalid value would also get an "invalid" value when serializing or deserializing.

…l entry. Add warn message, if there are any invalid entries on CM already
src/models.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@BerSomBen BerSomBen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I reviewed the second PR and added tiny improvements to your branch. Please have a look and feel free to merge towards this branch.
When its merged, I'll update the review here

Benjamin Sommerfeld and others added 3 commits October 15, 2024 08:18
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format your code using rustfmt: cargo fmt

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot dismissed their stale review October 15, 2024 07:13

Removing outdated review.

@BerSomBen
Copy link
Collaborator

BerSomBen commented Oct 15, 2024

hi @tobias-richter ,

i reviewed and tested the changes and I'm fine with it!

If there is an invalid variable in the current CM Environment or Pipeline Variables, the next vars set run will lead to an Error that requires manual interaction:

❌ ERROR, invalid service type detected for variable 'VARIABLE: "invalid"'

Copy link
Collaborator

@BerSomBen BerSomBen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@tobias-richter tobias-richter merged commit 149f662 into main Oct 15, 2024
6 checks passed
@tobias-richter tobias-richter deleted the feature/use-service-property-in-env-vars-patching branch October 15, 2024 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants