Skip to content

Commit

Permalink
Review 4 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 4, 2024
1 parent 75aff65 commit 1da8ca3
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 247 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ jobs:
retention-days: 30

conduct-connectivity-test:
name: Test connectivity using antctl test command
name: Test connectivity using 'antctl check' command
needs: [ build-antrea-coverage-image ]
runs-on: [ ubuntu-latest ]
steps:
Expand Down Expand Up @@ -770,14 +770,14 @@ jobs:
- name: Create Kind Cluster
run: |
kind create cluster --config ci/kind/config-3nodes.yml
- name: load docker image into kind
- name: Load docker image into kind
run: |
kind load docker-image antrea/antrea-controller-ubuntu-coverage:latest antrea/antrea-agent-ubuntu-coverage:latest
kubectl apply -f build/yamls/antrea.yml
- name: build antctl binaries
- name: Build antctl binary
run: |
make antctl-linux
- name: run antctl command
- name: Run antctl command
run: |
./bin/antctl-linux check installation
Expand Down
4 changes: 2 additions & 2 deletions pkg/antctl/antctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"antrea.io/antrea/pkg/agent/apiserver/handlers/podinterface"
"antrea.io/antrea/pkg/agent/apiserver/handlers/serviceexternalip"
fallbackversion "antrea.io/antrea/pkg/antctl/fallback/version"
checkinstallation "antrea.io/antrea/pkg/antctl/raw/check/installation"
"antrea.io/antrea/pkg/antctl/raw/featuregates"
"antrea.io/antrea/pkg/antctl/raw/multicluster"
"antrea.io/antrea/pkg/antctl/raw/proxy"
"antrea.io/antrea/pkg/antctl/raw/set"
"antrea.io/antrea/pkg/antctl/raw/supportbundle"
"antrea.io/antrea/pkg/antctl/raw/test"
"antrea.io/antrea/pkg/antctl/raw/traceflow"
"antrea.io/antrea/pkg/antctl/raw/upgrade/apistorage"
"antrea.io/antrea/pkg/antctl/transform/addressgroup"
Expand Down Expand Up @@ -641,7 +641,7 @@ $ antctl get podmulticaststats pod -n namespace`,
},
rawCommands: []rawCommand{
{
cobraCommand: test.Command(),
cobraCommand: checkinstallation.Command(),
supportAgent: false,
supportController: false,
commandGroup: check,
Expand Down
78 changes: 14 additions & 64 deletions pkg/antctl/raw/test/client.go → pkg/antctl/raw/check/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package test
package check

import (
"bytes"
"context"
"fmt"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/remotecommand"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/remotecommand"
)

type Client struct {
Expand All @@ -37,11 +35,6 @@ type Client struct {
clusterName string
}

type ExecResult struct {
Stdout bytes.Buffer
Stderr bytes.Buffer
}

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

Expand Down Expand Up @@ -76,24 +69,16 @@ func NewClient() (*Client, error) {
}, nil
}

func (c *Client) ClusterName() (name string) {
return c.clusterName
func (c *Client) GetClientSet() kubernetes.Interface {
return c.clientSet
}

func (c *Client) CreateService(ctx context.Context, namespace string, service *corev1.Service, opts metav1.CreateOptions) (*corev1.Service, error) {
return c.clientSet.CoreV1().Services(namespace).Create(ctx, service, opts)
}

func (c *Client) CreateDeployment(ctx context.Context, namespace string, deployment *appsv1.Deployment, opts metav1.CreateOptions) (*appsv1.Deployment, error) {
return c.clientSet.AppsV1().Deployments(namespace).Create(ctx, deployment, opts)
}

func (c *Client) GetDeployment(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*appsv1.Deployment, error) {
return c.clientSet.AppsV1().Deployments(namespace).Get(ctx, name, opts)
func (c *Client) ClusterName() (name string) {
return c.clusterName
}

func (c *Client) DeploymentIsReady(ctx context.Context, namespace, deploymentName string) (bool, error) {
deployment, err := c.GetDeployment(ctx, namespace, deploymentName, metav1.GetOptions{})
deployment, err := c.clientSet.AppsV1().Deployments(namespace).Get(ctx, deploymentName, metav1.GetOptions{})
if err != nil {
return false, err
}
Expand All @@ -118,65 +103,30 @@ func (c *Client) DeploymentIsReady(ctx context.Context, namespace, deploymentNam
return false, nil
}

func (c *Client) CreateNamespace(ctx context.Context, namespace string, opts metav1.CreateOptions) (*corev1.Namespace, error) {
return c.clientSet.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, opts)
}

func (c *Client) GetNamespace(ctx context.Context, namespace string, options metav1.GetOptions) (*corev1.Namespace, error) {
return c.clientSet.CoreV1().Namespaces().Get(ctx, namespace, options)
}

func (c *Client) DeleteNamespace(ctx context.Context, namespace string, opts metav1.DeleteOptions) error {
return c.clientSet.CoreV1().Namespaces().Delete(ctx, namespace, opts)
}

func (c *Client) ListPods(ctx context.Context, namespace string, options metav1.ListOptions) (*corev1.PodList, error) {
return c.clientSet.CoreV1().Pods(namespace).List(ctx, options)
}

func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string, command []string) (bytes.Buffer, error) {
req := c.clientSet.CoreV1().RESTClient().Post().Resource("pods").Name(pod).Namespace(namespace).SubResource("exec")

scheme := runtime.NewScheme()
if err := corev1.AddToScheme(scheme); err != nil {
return bytes.Buffer{}, fmt.Errorf("error adding to scheme: %w", err)
}

parameterCodec := runtime.NewParameterCodec(scheme)

req.VersionedParams(&corev1.PodExecOptions{
Command: command,
Container: container,
Stdin: false,
Stdout: true,
Stderr: true,
TTY: false,
}, parameterCodec)

}, 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)
}

result := &ExecResult{}

var stdout, stderr bytes.Buffer
err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{
Stdin: nil,
Stdout: &result.Stdout,
Stderr: &result.Stderr,
Stdout: &stdout,
Stderr: &stderr,
Tty: false,
})
if err != nil {
return bytes.Buffer{}, fmt.Errorf("error in stream: %w", err)
}

if errString := result.Stderr.String(); errString != "" {
return bytes.Buffer{}, fmt.Errorf("command failed: %s", errString)
}

return result.Stdout, nil
}

func (c *Client) GetDaemonSet(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*appsv1.DaemonSet, error) {
return c.clientSet.AppsV1().DaemonSets(namespace).Get(ctx, name, opts)
fmt.Fprint(&stdout, stderr.String())
return stdout, nil
}
Loading

0 comments on commit 1da8ca3

Please sign in to comment.