Skip to content

Commit

Permalink
Enable Post installation Connectivity tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kanha gupta <[email protected]>

Enable Post installation Connectivity tests

Signed-off-by: Kanha gupta <[email protected]>

Enable Post installation Connectivity tests

Signed-off-by: Kanha gupta <[email protected]>

Enable Post installation Connectivity tests

Signed-off-by: Kanha gupta <[email protected]>

Enable Post installation Connectivity tests

Signed-off-by: Kanha gupta <[email protected]>

Enable Post installation Connectivity tests

Signed-off-by: Kanha gupta <[email protected]>

Pod to pod working, same and different nodes and Internet connectivity
  • Loading branch information
kanha-gupta committed Mar 21, 2024
1 parent 0886d74 commit 2ef9eaa
Show file tree
Hide file tree
Showing 5 changed files with 877 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,60 @@ jobs:
path: log.tar.gz
retention-days: 30

conduct-connectivity-test:
name: Test connectivity using antctl test command
needs: [build-antrea-coverage-image]
runs-on: [ubuntu-latest]
steps:
- name: Free disk space
run: |
sudo apt-get clean
df -h
- uses: actions/checkout@v4
with:
show-progress: false
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Download Antrea image from previous job
uses: actions/download-artifact@v4
with:
name: antrea-ubuntu-cov
- name: Load Antrea image
run: |
docker load -i antrea-ubuntu.tar
- name: Install Kind
run: |
KIND_VERSION=$(head -n1 ./ci/kind/version)
curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64
chmod +x ./kind
sudo mv kind /usr/local/bin
- name: Create Kind Cluster
run: |
cat <<EOF > kind-config.yml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
disableDefaultCNI: true
podSubnet: 10.10.0.0/16
nodes:
- role: control-plane
- role: worker
- role: worker
EOF
kind create cluster --config kind-config.yml
- 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
run: |
make antctl
sudo cp bin/antctl-linux /usr/local/bin/antctl
- name: run antctl command
run: |
antctl test
test-e2e-encap-all-features-enabled:
name: E2e tests on a Kind cluster on Linux with all features enabled
needs: [build-antrea-coverage-image]
Expand Down
6 changes: 6 additions & 0 deletions pkg/antctl/antctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"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 @@ -639,6 +640,11 @@ $ antctl get podmulticaststats pod -n namespace`,
},
},
rawCommands: []rawCommand{
{
cobraCommand: test.Command,
supportAgent: true,
supportController: true,
},
{
cobraCommand: supportbundle.Command,
supportAgent: true,
Expand Down
188 changes: 188 additions & 0 deletions pkg/antctl/raw/test/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// Copyright 2024 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package test

import (
"bytes"
"context"
"fmt"

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/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)

type Client struct {
Clientset kubernetes.Interface
Config *rest.Config
RawConfig clientcmdapi.Config
contextName string
}

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

if kubeconfig != "" {
rules.ExplicitPath = kubeconfig
}

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

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
}

if contextName == "" {
contextName = rawConfig.CurrentContext
}

return &Client{
Clientset: clientset,
Config: config,
RawConfig: rawConfig,
contextName: contextName,
}, nil
}

func (c *Client) ContextName() (name string) {
return c.contextName
}

func (c *Client) ClusterName() (name string) {
if context, ok := c.RawConfig.Contexts[c.ContextName()]; ok {
name = context.Cluster
}
return
}

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) DeleteService(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error {
return c.Clientset.CoreV1().Services(namespace).Delete(ctx, name, opts)
}

func (c *Client) GetService(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.Service, error) {
return c.Clientset.CoreV1().Services(namespace).Get(ctx, name, 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) DeleteDeployment(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error {
return c.Clientset.AppsV1().Deployments(namespace).Delete(ctx, name, opts)
}

func (c *Client) DeploymentIsReady(ctx context.Context, namespace, deployment string) error {
d, err := c.GetDeployment(ctx, namespace, deployment, metav1.GetOptions{})
if err != nil {
return err
}

if d == nil {
return fmt.Errorf("deployment is not available")
}

if d.Status.Replicas == 0 {
return fmt.Errorf("replicas count is zero")
}

if d.Status.AvailableReplicas != d.Status.Replicas {
return fmt.Errorf("only %d of %d replicas are available", d.Status.AvailableReplicas, d.Status.Replicas)
}

if d.Status.ReadyReplicas != d.Status.Replicas {
return fmt.Errorf("only %d of %d replicas are ready", d.Status.ReadyReplicas, d.Status.Replicas)
}

if d.Status.UpdatedReplicas != d.Status.Replicas {
return fmt.Errorf("only %d of %d replicas are up-to-date", d.Status.UpdatedReplicas, d.Status.Replicas)
}

return 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) DeletePod(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error {
return c.Clientset.CoreV1().Pods(namespace).Delete(ctx, name, 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) {
result, err := c.execInPod(ctx, ExecParameters{
Namespace: namespace,
Pod: pod,
Container: container,
Command: command,
})
if err != nil {
return bytes.Buffer{}, 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)
}

func (c *Client) DeleteDaemonSet(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error {
return c.Clientset.AppsV1().DaemonSets(namespace).Delete(ctx, name, opts)
}

type Kind int

func (c *Client) ListNodes(ctx context.Context, options metav1.ListOptions) (*corev1.NodeList, error) {
return c.Clientset.CoreV1().Nodes().List(ctx, options)
}
Loading

0 comments on commit 2ef9eaa

Please sign in to comment.