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(cloud-init): Implement upcoming cloud-init WSL support #506

Merged
merged 31 commits into from
Apr 19, 2024

Conversation

EduardGomezEscandell
Copy link
Contributor

@EduardGomezEscandell EduardGomezEscandell commented Jan 23, 2024

Cloud-init will, at some point, be able to pick up files from specified locations in the Windows file-system. The plan is for UP4W’s agent to receive cloud-init files from Landscape and put them at the appropriate location.

Furthermore, system-wide config (Pro token and Landscape) must be written as well.


UDENG-2112

@EduardGomezEscandell EduardGomezEscandell changed the title feat(cloud-init): Implement support for upcoming cloud-init WSL support feat(cloud-init): Implement upcoming cloud-init WSL support Jan 23, 2024
@EduardGomezEscandell EduardGomezEscandell changed the base branch from main to landscape-refactor-tests January 25, 2024 13:05
@EduardGomezEscandell
Copy link
Contributor Author

EduardGomezEscandell commented Jan 25, 2024

User creation after install is left for a follow-up pull request (#584).

@EduardGomezEscandell EduardGomezEscandell self-assigned this Jan 29, 2024
@EduardGomezEscandell EduardGomezEscandell changed the base branch from landscape-refactor-tests to config-notify January 29, 2024 16:42
EduardGomezEscandell added a commit that referenced this pull request Jan 30, 2024
This PR concerns the Landscape service package tests that tested the
execution of commands comming from the server. It is motivated by the
attempt at adding new tests in PR #506 regarding cloud-init integration.

These tests where sub-par for two reasons:
1. They were structured in a way that was hard to read
2. They had very little granularity: only one success and one failure
test case per command.

Adding new tests was quite hard, defeating the purpose of table testing.
With this new structure, adding test cases is much simpler, so I added
quite a few of them.

A side effect of this PR is that the executor tests can no longer be ran
without the mock. We were never running them anyways so I decided
against maitaining unused code.
Base automatically changed from config-notify to main February 1, 2024 08:45
EduardGomezEscandell added a commit that referenced this pull request Feb 1, 2024
I want cloud-init & landscape to be pinged by the config every time
something changes. However, I don't want these two utilities to be
dependencies of config. If anything, I want the dependency the other way
around! Cloud-init and Landscape should import config.

So I must somehow call these utilities from the config without importing
them. My solution: callbacks. Any utility can now wait on config changes
by using:

```go
conf.Notify(func() {
    fmt.Println("Hello, world")
})
```
and this function will be called every time the config is changed (via
GUI, registry, or any future methods).

This is used in Landscape #515 and Cloud-init #506.
@EduardGomezEscandell EduardGomezEscandell changed the base branch from main to create-ubuntupro-dir February 1, 2024 12:25
Base automatically changed from create-ubuntupro-dir to main February 1, 2024 13:24
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

Attention: Patch coverage is 92.45283% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 87.57%. Comparing base (f2eddb6) to head (d3426c8).

Files Patch % Lines
windows-agent/internal/cloudinit/cloudinit.go 90.16% 8 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #506      +/-   ##
==========================================
+ Coverage   87.24%   87.57%   +0.33%     
==========================================
  Files          97       99       +2     
  Lines        6224     6344     +120     
==========================================
+ Hits         5430     5556     +126     
+ Misses        624      623       -1     
+ Partials      170      165       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EduardGomezEscandell EduardGomezEscandell force-pushed the landscape-cloud-init branch 4 times, most recently from c947aeb to 231a507 Compare February 9, 2024 08:33
@EduardGomezEscandell EduardGomezEscandell changed the base branch from main to fix-config-notify February 9, 2024 08:33
@EduardGomezEscandell EduardGomezEscandell force-pushed the landscape-cloud-init branch 2 times, most recently from 565d35f to f731532 Compare February 9, 2024 11:36
@EduardGomezEscandell EduardGomezEscandell marked this pull request as ready for review February 9, 2024 13:58
@EduardGomezEscandell EduardGomezEscandell requested a review from a team as a code owner February 9, 2024 13:58
That function is about agent data, not user's.
it's about cloud-init failing to remove a file,
not to write it.
There is no specific reason to split that writing.
Also, less lines for codecov to complain about.
Since we are passing nearby the codecov is unhappy
on the testcases definitions we touched on in this PR.
- Removing common golden;
- Generating new goldens for each error case -- even if they are equal
- Renaming Notify into Update;
- Renaming golden directory - to match the new test case name
- Asserting on the goldens instead of on err.
- There is no tc.wantErr anymore.
It's implied that if New returns an error, the other return value shouldn't be used,

yet it's good to return nil so any naive attempt to use it would panic instead of behaving unpredicatably.
What that does even mean?
That only returns an error if writeAgentData does so.
that could be for a number of errors, all serialization-related.
If we returned a usable object under such circunstance
and registered it to be notified of changes in the agent's config, silent failures would be logged on update, while the agent would stay ill-running.
And replace it by a want string.
All cases, since cloudinit is now the provisioning method.
We still run the end-to-end test workflow to assert that all artifacts can be built.
We force both closures to run by writing into the registry mock.
That mock defers notifying the registry watcher of the changes.
The information finally hits cloud-init and we assert on the produced agent.yaml against the goldens herein introduced.
Still need to find a way other than time-based programming
to give cloudinit time to write the agent.yaml
It'd be safe today to do so, but might not be tomorrow.
The good practice is always to not touch the returned object if err is not nil.
@CarlosNihelton
Copy link
Contributor

Rebased over latest main to solve merge conflicts. Only the last commit is new.

Copy link
Collaborator

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

[APPROVED!!!] Nice work on getting that landed, we are ready for the cloud-init delivery area :)

@CarlosNihelton CarlosNihelton merged commit a60b370 into main Apr 19, 2024
35 checks passed
@CarlosNihelton CarlosNihelton deleted the landscape-cloud-init branch April 19, 2024 15:47
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.

3 participants