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
Implement GraphQL query for pods #2280
Conversation
ff0a582
to
4000107
Compare
4000107
to
a3be8db
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.
LGTM, but please refer to my comments.
return nil, nil | ||
} | ||
|
||
containerStates := c.containerStatusesToGQLContainerStates(in.Status.ContainerStatuses) |
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.
Maybe would be better if all logic for extracting statuses would be in separate package, eg. k8s/status/pod.go
. What do you think about that @michal-hudy?
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.
Sure, I agree 😄
tests/ui-api-layer-acceptance-tests/internal/domain/k8s/pod_test.go
Outdated
Show resolved
Hide resolved
return c.getWaitingContainerState(nil) | ||
} | ||
|
||
func (c *podConverter) podToGQLJSON(in *v1.Pod) (gqlschema.JSON, error) { |
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.
Probably name podSpecificToGQLJSON
would be better.
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 that suggest only the PodSpec field of Pod is being converted while we want to convert whole Pod?
return containerStates | ||
} | ||
|
||
func (c *podConverter) getWaitingContainerState(in *v1.ContainerStateWaiting) gqlschema.ContainerState { |
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.
Export logic responsible for extracting status to separate package, please see how it is created in servicecatalog
domain.
var reason, message *string | ||
|
||
if in.Reason != "" { | ||
tmp := in.Reason |
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.
tmp
is not needed. Fix also in other places 😄
} | ||
} | ||
|
||
var reason, 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.
Why reason
and message
are pointers?
|
||
jsonByte, err := json.Marshal(in) | ||
if err != nil { | ||
return nil, err |
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.
Add context
var jsonMap map[string]interface{} | ||
err = json.Unmarshal(jsonByte, &jsonMap) | ||
if err != nil { | ||
return nil, err |
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.
Add context, also in other places
|
||
type ContainerState { | ||
state: ContainerStateType! | ||
reason: 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.
Return empty string
if reason
or message
is not provided. Kubernetes API also returns empty string
reason: String!
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.
Small changes 😄
|
||
type PodExtractor struct{} | ||
|
||
func (ext *PodExtractor) ContainerStatusesToGQLContainerStates(in []v1.ContainerStatus) []gqlschema.ContainerState { |
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.
Hm... this is state extractor, not status ;) My bad, I suggested moving it to status
.
So move it to state
package and rename method to States
and it will be ContainerExtractor
:)
type PodExtractor struct{} | ||
|
||
func (ext *PodExtractor) ContainerStatusesToGQLContainerStates(in []v1.ContainerStatus) []gqlschema.ContainerState { | ||
containerStates := []gqlschema.ContainerState{} |
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 already know the size of the slice
containerStates := make([]gqlschema.ContainerState, len(in))
|
||
type containerState struct { | ||
State containerStateType `json:"state"` | ||
Reason *string `json:"reason"` |
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 is not a pointer
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.
LGTM
* readme update * Update development/README.md Co-Authored-By: Maja Kurcius <maja.kurcius@sap.com> * Update development/README.md Co-Authored-By: Maja Kurcius <maja.kurcius@sap.com> Co-authored-by: Maja Kurcius <maja.kurcius@sap.com>
Description
Changes proposed in this pull request:
Related issue(s)
#2000