Skip to content

Commit

Permalink
Review 5 changes
Browse files Browse the repository at this point in the history
Signed-off-by: Kanha gupta <[email protected]>
  • Loading branch information
kanha-gupta committed Apr 15, 2024
1 parent 1da8ca3 commit f9bae30
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ jobs:
path: log.tar.gz
retention-days: 30

conduct-connectivity-test:
run-post-installation-checks:
name: Test connectivity using 'antctl check' command
needs: [ build-antrea-coverage-image ]
runs-on: [ ubuntu-latest ]
Expand Down
17 changes: 4 additions & 13 deletions pkg/antctl/raw/check/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,24 @@ type Client struct {

func NewClient() (*Client, error) {
rules := clientcmd.NewDefaultClientConfigLoadingRules()

nonInteractiveClient := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, &clientcmd.ConfigOverrides{})

config, err := nonInteractiveClient.ClientConfig()
if err != nil {
return nil, err
}

rawConfig, err := nonInteractiveClient.RawConfig()
if err != nil {
return nil, err
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}

contextName := rawConfig.CurrentContext

clusterName := ""
if context, ok := rawConfig.Contexts[contextName]; ok {
clusterName = context.Cluster
}

return &Client{
clientSet: clientset,
config: config,
Expand All @@ -82,7 +75,6 @@ func (c *Client) DeploymentIsReady(ctx context.Context, namespace, deploymentNam
if err != nil {
return false, err
}

if deployment.Generation <= deployment.Status.ObservedGeneration {
for _, cond := range deployment.Status.Conditions {
if cond.Type == appsv1.DeploymentProgressing && cond.Reason == "ProgressDeadlineExceeded" {
Expand All @@ -103,7 +95,7 @@ func (c *Client) DeploymentIsReady(ctx context.Context, namespace, deploymentNam
return false, nil
}

func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string, command []string) (bytes.Buffer, error) {
func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string, command []string) (string, string, error) {
req := c.clientSet.CoreV1().RESTClient().Post().Resource("pods").Name(pod).Namespace(namespace).SubResource("exec")
req.VersionedParams(&corev1.PodExecOptions{
Command: command,
Expand All @@ -115,7 +107,7 @@ func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string
}, scheme.ParameterCodec)
exec, err := remotecommand.NewSPDYExecutor(c.config, "POST", req.URL())
if err != nil {
return bytes.Buffer{}, fmt.Errorf("error while creating executor: %w", err)
return "", "", fmt.Errorf("error while creating executor: %w", err)
}
var stdout, stderr bytes.Buffer
err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
Expand All @@ -125,8 +117,7 @@ func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string
Tty: false,
})
if err != nil {
return bytes.Buffer{}, fmt.Errorf("error in stream: %w", err)
return "", "", fmt.Errorf("error in stream: %w", err)
}
fmt.Fprint(&stdout, stderr.String())
return stdout, nil
return stdout.String(), stderr.String(), nil
}
Loading

0 comments on commit f9bae30

Please sign in to comment.