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

chore(containers): refactor deployment #754

Draft
wants to merge 8 commits into
base: feature/application-management
Choose a base branch
from

Conversation

lusergit
Copy link
Collaborator

@lusergit lusergit commented Dec 4, 2024

During the development of the containers feature we were prioritizing speed over project structure. This PR aims to refactor the existing code to be more comprehensible and understandable. The main changes are the new *.Deployment resources and the containers resources placement

Containers structure

Each resources represented in the db has its own folder in the backend/lib/edgehog/containers folder, containing the changes, the manual actions and all the things needed for that particular resource. Each resource now has a Deployment module, representing the many to many relation between the resource and the devices.

Deployments

  • Each resource has a Deployment module, which is the many_to_many relation between the resource and the device.
  • Each deployment has a :state attribute, representing the current state of the resource on the device. The state is updated trough the trigger handler and does not enforce a particular transition system between the states. This is done because we might lose some messages in the communication with the device and this way the backend can cope with the situation rather than throwing errors and not handling the situation correctly.
  • The deployment is responsible, upon its creation, to send to astarte the appropriate messages to actually build the resources. The first two states of each deployment are the same for all resources:
    • :created means the resources has been created in the database
    • :sent means that the backend has correctly sent to astarte the informations for the device to create the resource, will then be astarte responsible to actually send the informations to the device itself.

@lusergit
Copy link
Collaborator Author

lusergit commented Dec 4, 2024

Tests will not pass for now as the infrastructure is not complete yet

@lusergit lusergit force-pushed the chore/refactor-deployment branch 4 times, most recently from aeb462f to a7b9556 Compare December 5, 2024 14:27
@lusergit lusergit marked this pull request as ready for review December 5, 2024 14:36
@lusergit lusergit force-pushed the chore/refactor-deployment branch 2 times, most recently from 7d244f6 to dbd3464 Compare December 5, 2024 16:39
@lusergit lusergit marked this pull request as draft December 6, 2024 09:28
@lusergit lusergit force-pushed the chore/refactor-deployment branch 5 times, most recently from acd3ce3 to 4b1c9b7 Compare December 19, 2024 11:46
@lusergit lusergit force-pushed the chore/refactor-deployment branch 2 times, most recently from 21640d9 to 2680b1e Compare December 20, 2024 17:01
```
mix ash.gen.resource Edgehog.Containers.Image.Deployment \
    --default-actions read,create,update,destroy \
    --uuid-primary-key id \
    --attribute pulled:boolean:required:public \
    --relationship belongs_to:image:Edgehog.Containers.Image \
    --relationship belongs_to:device:Edgehog.Devices.Device \
    --timestamps
```

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
```
mix ash.gen.resource Edgehog.Containers.Container.Deployment
     --default-actions read,create,update,destroy
     --uuid-primary-key id
     --attribute status:Edgehog.Containers.Container.Status:required:public
     --relationship belongs_to:container:Edgehog.Containers.Container
     --relationship belongs_to:device:Edgehog.Devices.Device
     --timestamps
```

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
```
mix ash.gen.resource Edgehog.Containers.Network.Deployment
    --default-actions read,create,update,destroy
    --uuid-primary-key id
    --attribute created:boolean:required:public
    --relationship belongs_to:container:Edgehog.Containers.Network
    --relationship belongs_to:device:Edgehog.Devices.Device
    --timestamps
```

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
```
mix ash.gen.resource Edgehog.Containers.Volume.Deployment
    --default-actions read,create,update,destroy
    --uuid-primary-key id
    --attribute created:boolean:required:public
    --relationship belongs_to:container:Edgehog.Containers.Volume
    --relationship belongs_to:device:Edgehog.Devices.Device
    --timestamps
```

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
moving containers resources to appropriate subfolders, refactoring
according to the rest of the project structure

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
Setting up generated resources

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
@lusergit lusergit force-pushed the chore/refactor-deployment branch 5 times, most recently from 782716f to f4d7dc5 Compare February 3, 2025 09:41
The new `*.Deployment` resources are being used

Moves the deployment logic to the `*.Deployment` resources and sets them
as state machines, signaling errors when single resources are not
deployed correctly

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
generated migrations for the new structure and resources with
```
mix ash_postgers.gen_migrations deployment_refactor
```

Signed-off-by: Luca Zaninotto <luca.zaninotto@secomind.com>
@lusergit lusergit force-pushed the chore/refactor-deployment branch from 6a686fa to f56110f Compare February 4, 2025 14:48
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.

1 participant