-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add managed
field in Cluster resources
#2366
Conversation
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.
Some initial comments.
PD: Add UT tests for the frontend and e2e if possible
@@ -715,6 +716,9 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do | |||
end) | |||
end | |||
|
|||
defp parse_managed(%{managed: true}), do: true |
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.
Wouldn't be better to include managed
as required field in the payload and here simply passing that value, as we would always heve it?
@@ -20,7 +20,8 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do | |||
type: %Schema{type: :string}, | |||
role: %Schema{type: :string}, | |||
status: %Schema{type: :string}, | |||
fail_count: %Schema{type: :integer} | |||
fail_count: %Schema{type: :integer}, | |||
managed: %Schema{type: :boolean} |
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.
We don't want to include this field in the v1
.
We want to include it in the v2
.
In fact, we need to remove it in the v1
in the view
code
test/support/factory.ex
Outdated
@@ -450,7 +450,8 @@ defmodule Trento.Factory do | |||
id: Faker.Pokemon.name(), | |||
role: "Stopped", | |||
status: Faker.Pokemon.name(), | |||
type: "ocf::heartbeat:Dummy" | |||
type: "ocf::heartbeat:Dummy", | |||
managed: Enum.random([false, true]) |
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.
This looks like a good moment to create the cluster_resource
factory and use it.
What do you 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.
You don't need this change. Here what you need to do is to use the factory itself
45a0207
to
25438ca
Compare
25438ca
to
824c447
Compare
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.
Hey @EMaksy
Some comments. We need to rethink some new things you did
fe5f2d3
to
1700dff
Compare
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.
|> Map.put(:stopped_resources, adapt_resources(stopped_resources)) | ||
end | ||
|
||
defp adapt_details(%{nodes: nodes} = details) do |
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.
@rtorrero Is this new entry needed?
I mean, the stopped_resources
would be always there, so adapt_resources
would return an empty list in any case.
Or do I miss something?
If you remove this, you could remove the adapt_nodes
function as it is used only in one place, and we don't want to hide a simple Enum.map
into a function
end | ||
|
||
defp adapt_node(node) do | ||
adapted_resources = adapt_resources(node[:resources] || []) |
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.
@rtorrero Mostly the same here. Is it not the resources
field always coming?
You could get it in the function signature, and not use this ugly thing.
If it is compulsory, use Map.get(node, :resources, [])
at least
test/support/factory.ex
Outdated
@@ -450,7 +450,8 @@ defmodule Trento.Factory do | |||
id: Faker.Pokemon.name(), | |||
role: "Stopped", | |||
status: Faker.Pokemon.name(), | |||
type: "ocf::heartbeat:Dummy" | |||
type: "ocf::heartbeat:Dummy", | |||
managed: Enum.random([false, true]) |
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.
You don't need this change. Here what you need to do is to use the factory itself
@@ -40,6 +41,14 @@ defmodule TrentoWeb.V1.ClusterViewTest do | |||
refute Access.get(node, :nameserver_actual_role) | |||
refute Access.get(node, :indexserver_actual_role) | |||
refute Access.get(node, :status) | |||
|
|||
Enum.each(details.stopped_resources, fn stopped_resource -> | |||
refute Map.has_key?(stopped_resource, :managed) |
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.
Why not Access.get
here? Just for consistency
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.
couldn't Access.get
return a falsy boolean? (causing the test to pass when it shouldn't)
A Map.has_key?
seems also semantically more correct to me.
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.
It was more about consistency, not having Access
above and Map.has_key?
here.
I would be fine having has_key?
in both.
Anyway, it was a detail
}, | ||
{ | ||
status: 'Online', | ||
resources: [{ managed: true }, { managed: false }], |
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 we should use the clusterResourceFactory
here
@@ -177,3 +192,10 @@ export const WithRunningExecution = { | |||
lastExecution: { data: checksExecutionRunningFactory.build() }, | |||
}, | |||
}; | |||
|
|||
export const WithUnmanagedResources = { |
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.
Not really nice with the Host currently not registered
, but hey...
e782f8e
to
aa047e9
Compare
expectedResource.forEach(({ key, title }) => { | ||
expect(screen.getByText(title)).toBeInTheDocument(); | ||
resources.forEach((resource) => { | ||
let value; |
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 put a let instead of const, as otherwise eslint complains about nested ternary operator. Maybe there is a better way ?
{ attributes: hanaClusterAttributes, resources: hanaClusterResources }, | ||
] = hanaClusterDetailsNodesFactory.buildList(1); | ||
|
||
const scenarios = [ |
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.
Any more ideas for additional scenarios?
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.
Description
This PR adds:
adapt_v1
function)Frontend Preview:
Checkout storybook "Unmanaged Node Resources"
Add count of unmanaged resources when a node is online but has unmanaged resources
Add Managed column in Node details view
How was this tested?