-
Notifications
You must be signed in to change notification settings - Fork 503
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(units): state methods for unit agent/workload/container status #18138
Conversation
domain/application/types.go
Outdated
// and associated information. | ||
type CloudContainerStatusStatusInfo struct { | ||
StatusID CloudContainerStatusType | ||
Message string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make these last three fields into a type that is embedded in the different status types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the plan eventually. I wanted to let things like machine status, storage status etc emerge first so that we could make a more informed call if we wanted to introduce a top level domain status package with the aforementioned core type and any other required artefacts. Since this is the first cab off the rank, I was ok with doing it this way initially; it's only 3 attributes with no behaviour attached to them. I can introduce a suitable type here pending subsequent refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would only be useful if there is common logic around status that is useful when decomposed without StatusID
.
I'd prefer this to become a generic type. All statues should have the same shape.
type StatusInfo[StatusType any] struct {
StatusID StatusType
Message string
Data map[string]string
Since time.Time
}
type CloudContainerStatusStatusInfo = StatusInfo[CloudContainerStatusType]
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was deliberately avoiding optimising too much and introducing a generic status type until we had more use cases outside this domain. We already have status in core. The types that are defined here are purely to act as parameters to the calls to state. They are not used outside the application package. They are just DTOs with no behaviour. Any changes to how status is used outside this package needs to start with core status and be done holistically.
// saveStatusData saves the status key value data for the specified unit in the specified table. | ||
// It's called from each different SaveStatus method which previously has confirmed the unit UUID exists. | ||
func (st *ApplicationState) saveStatusData(ctx context.Context, tx *sqlair.TX, table, unitUUID string, data map[string]string) error { | ||
unit := coreUnit{ID: unitUUID} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name for this type is poor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming is hard. The struct holds just "core" or minimal attributes of a unit - uuid, name, life, net node uuid. Maybe "minimalUnit". I'll have a think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coreUnit is terrible because it clashes with similarly named coreunit (which you have as an aliased package in this very file) and the concept of "core" when it comes to juju.
Something like:
basicUnit
minimalUnit
unitIntrinsics
IDK. I wouldn't think about it to hard, it is an unexported concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already changed to minimalUnit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank-you for the changes. Happy to be second +1.
/merge |
Adds state methods for saving and deleting status for:
Due to the transition towards using UUID, the status methods take a unit UUID to work with. So a GetUnitUUID method is added to lookup UUID from the unit name - this will be used when the service logic is implemented.
Also adds a missing unit agent status enum for error.
QA steps
Just unit tests
Links
Jira card: JUJU-6777
Jira card: JUJU-6803