-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Switch the keadm ctl client to client go and add the restful interface for restart pod. #5572
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
0d18440
to
c9c9019
Compare
for _, errMsg := range restartResponse.ErrMessages { | ||
fmt.Println(errMsg) | ||
} | ||
|
||
for _, containerID := range restartResponse.ContainerIds { | ||
fmt.Println(containerID) | ||
} |
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's not a friendly way to output messages, right?
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's not a friendly way to output messages, right?
What is the appropriate way to print the stopped container ID and the error message returned by the request here?
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.
Follow your logic, friendly information sample:
case 1. The pod 'aaa' restart failure, reason: <error-message>.
case 2. There are some containers of Pod 'bbb' that failed to restart, reason: <error-message>, containers container-1, container-2 have been restarted.
case 3. The pod 'ccc' restart successful.
You can handle these response error messages in package storage.
if err != nil {
message := fmt.Sprintf(xxxxxxxxx)
klog.Warning("[metaserver/reststorage] ", message)
restartResponse.ErrMessages = append(restartResponse.ErrMessages, message)
}
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.
Follow your logic, friendly information sample:
case 1. The pod 'aaa' restart failure, reason: <error-message>. case 2. There are some containers of Pod 'bbb' that failed to restart, reason: <error-message>, containers container-1, container-2 have been restarted. case 3. The pod 'ccc' restart successful.
You can handle these response error messages in package storage.
if err != nil { message := fmt.Sprintf(xxxxxxxxx) klog.Warning("[metaserver/reststorage] ", message) restartResponse.ErrMessages = append(restartResponse.ErrMessages, message) }
Done
if err != nil { | ||
return nil, err | ||
} | ||
ctx := context.TODO() |
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.
Is it better if the variable context is inputed by the caller?
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.
ok
Method: "GET", | ||
Path: "/" + CoreAPIPrefix + "/" + CoreAPIGroupVersion.Version + | ||
"/namespaces/" + podRequest.Namespace + "/pods", | ||
podList, err := kubeClient.CoreV1().Pods(metaV1.NamespaceAll).List(context.TODO(), metaV1.ListOptions{ |
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.
Is it better if the variable context is inputed by the caller?
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.
ok
47dc48f
to
e096c5c
Compare
} | ||
|
||
func (podRequest *PodRequest) GetPod(ctx context.Context) (*corev1.Pod, error) { | ||
select { |
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 use select here?
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 use select here?
Modified
} | ||
|
||
func (podRequest *PodRequest) GetPods(ctx context.Context) (*corev1.PodList, error) { | ||
select { |
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.
select?
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.
select?
Modified
7bf1a80
to
040f800
Compare
@@ -200,6 +201,46 @@ func (f *Factory) Patch(reqInfo *request.RequestInfo) http.Handler { | |||
return http.HandlerFunc(h) | |||
} | |||
|
|||
func (f *Factory) Restart(namespace string) http.Handler { |
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 can consider moving these special functions to a specific file for management, like: ext_pods_handler.go
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.
ext_pods_handler.go
ok
@@ -183,7 +183,11 @@ func (ls *MetaServer) BuildBasicHandler() http.Handler { | |||
case reqInfo.Verb == "list", reqInfo.Verb == "watch": | |||
ls.Factory.List().ServeHTTP(w, req) | |||
case reqInfo.Verb == "create": | |||
ls.Factory.Create(reqInfo).ServeHTTP(w, req) | |||
if reqInfo.Name == "restart" { |
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.
if reqInfo.SubResource == "restart"
?
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.
if reqInfo.SubResource == "restart"
?
The Subresource here is nil, Name is "restart".
5930cfb
to
56962c7
Compare
pkg/metaserver/constants.go
Outdated
@@ -59,6 +59,11 @@ type PatchInfo struct { | |||
Subresources []string | |||
} | |||
|
|||
type RestartInfo struct { |
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.
Defining structures in the constants.go is not good, you can add a file types.go to maintain them, the struct RestartResponse
can also be moved over to this file, it is not good that the keadm module depend on the metaserver module package.
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.
Done
56962c7
to
411f122
Compare
…e for restart pod. Signed-off-by: luomengY <2938893385@qq.com>
411f122
to
ee4de68
Compare
/lgtm |
…e for restart pod.
What type of PR is this?
/kind feature
What this PR does / why we need it:
1.switch the keadm ctl client to client go.
2.add the restful interface for restart pod.
POST:/api/v1/namespaces/{namespace}/pods/restart
body: ["pod-1","pod-2","pod-3"]
response: {"errMessages":[],"containerIds":[]}
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: