-
Notifications
You must be signed in to change notification settings - Fork 60
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
recipe: exec hook implementation #1932
base: main
Are you sure you want to change the base?
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.
Minor changes requested, rest of the change looks good.
Move it out of draft once the changes are done.
Container string | ||
} | ||
|
||
// Parameters that are of interest are hook -- name, namespace, |
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 you want to document the function, then start the comment with the function name.
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
Stderr: errBuf, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error executing command: %s", errBuf.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.
ensure command is also printed
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
return fmt.Errorf("error executing command: %s", errBuf.String()) | ||
} | ||
|
||
log.Info("executed exec command successfully", "pod", execPod.PodName, "namespace", execPod.Namespace, "command", execPod.Command, |
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.
Might have to move to debug log but can be done in the next PR
*/ | ||
if e.Hook.LabelSelector != nil { | ||
eps, err := e.getExecPodsUsingLabelSelector(client, log) | ||
if err != nil { |
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 possible that the user provides both labelSelector and NameSelector but only one of them match with the pods. We should ignore errors in the collection stage and execute on whatever was found.
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
|
||
cmd, err := covertCommandToStringArray(e.Hook.Op.Command) | ||
if err != nil { | ||
log.Error(err, "error occurred during exec hook execution") |
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.
Print the command and also a return is missing
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
|
||
cmd, err := covertCommandToStringArray(e.Hook.Op.Command) | ||
if err != nil { | ||
log.Error(err, "error occurred during exec hook execution") |
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.
same comment as above here. And maybe we should factor out the common parts of these two functions.
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
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/remotecommand" | ||
"k8s.io/kubectl/pkg/scheme" |
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.
check if this is the right scheme pkg to use. I was thinking it would be under controller-runtime
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.
Updated, please check if the approach is fine.
Also, rename the file json_util_test.go to check_hook_test.go |
e832659
to
9b7729d
Compare
Incorporating review comments Fixing capture issue Signed-off-by: Annaraya Narasagond <[email protected]>
Adding unit test for hooks_factory. Adding unit test for exec hooks using fake client. Signed-off-by: Annaraya Narasagond <[email protected]>
For hook type "exec", commands can be provided which needs to be executed on the Pods as part of recipe workflow. Based on the either labelSelector or nameSelector, pods can be selected. If both are provided, OR logic will apply. Kubernetes core client is used in order to execute the command on the pods. The required permissions were added as part of #1946