...

Source file src/github.com/linkerd/linkerd2/test/integration/deep/install_test.go

Documentation: github.com/linkerd/linkerd2/test/integration/deep

     1  package deeptest
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/linkerd/linkerd2/testutil"
    10  )
    11  
    12  //////////////////////
    13  ///   TEST SETUP   ///
    14  //////////////////////
    15  
    16  var (
    17  	TestHelper *testutil.TestHelper
    18  )
    19  
    20  func TestMain(m *testing.M) {
    21  	TestHelper = testutil.NewTestHelper()
    22  	os.Exit(m.Run())
    23  }
    24  
    25  func TestInstallCalico(t *testing.T) {
    26  	if !TestHelper.CNI() {
    27  		return
    28  	}
    29  
    30  	out, err := TestHelper.Kubectl("", []string{"apply", "-f", "https://k3d.io/v5.1.0/usage/advanced/calico.yaml"}...)
    31  	if err != nil {
    32  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
    33  			"kubectl apply command failed\n%s", out)
    34  	}
    35  
    36  	time.Sleep(10 * time.Second)
    37  	o, err := TestHelper.Kubectl("", "--namespace=kube-system", "wait", "--for=condition=available", "--timeout=120s", "deploy/calico-kube-controllers")
    38  	if err != nil {
    39  		testutil.AnnotatedFatalf(t, "failed to wait for condition=available for calico resources",
    40  			"failed to wait for condition=available for calico resources: %s: %s", err, o)
    41  	}
    42  }
    43  
    44  func TestInstallCNIPlugin(t *testing.T) {
    45  	if !TestHelper.CNI() {
    46  		return
    47  	}
    48  
    49  	// install the CNI plugin in the cluster
    50  	var (
    51  		cmd  = "install-cni"
    52  		args = []string{
    53  			"--use-wait-flag",
    54  			"--cni-log-level=debug",
    55  			// For Flannel (k3d's default CNI) the following settings are required.
    56  			// For Calico the default ones are fine.
    57  			// "--dest-cni-net-dir=/var/lib/rancher/k3s/agent/etc/cni/net.d",
    58  			// "--dest-cni-bin-dir=/bin",
    59  		}
    60  	)
    61  
    62  	exec := append([]string{cmd}, args...)
    63  	out, err := TestHelper.LinkerdRun(exec...)
    64  	if err != nil {
    65  		testutil.AnnotatedFatal(t, "'linkerd install-cni' command failed", err)
    66  	}
    67  
    68  	out, err = TestHelper.KubectlApply(out, "")
    69  	if err != nil {
    70  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
    71  			"'kubectl apply' command failed\n%s", out)
    72  	}
    73  
    74  	// perform a linkerd check with --linkerd-cni-enabled
    75  	timeout := time.Minute
    76  	err = testutil.RetryFor(timeout, func() error {
    77  		out, err = TestHelper.LinkerdRun("check", "--pre", "--linkerd-cni-enabled", "--wait=60m")
    78  		if err != nil {
    79  			return err
    80  		}
    81  		return nil
    82  	})
    83  	if err != nil {
    84  		testutil.AnnotatedFatal(t, fmt.Sprintf("'linkerd check' command timed-out (%s)", timeout), err)
    85  	}
    86  }
    87  
    88  // TestInstall will install the linkerd control plane to be used in the rest of
    89  // the deep suite tests.
    90  func TestInstall(t *testing.T) {
    91  	// Install CRDs
    92  	cmd := []string{
    93  		"install",
    94  		"--crds",
    95  		"--controller-log-level", "debug",
    96  		"--set", fmt.Sprintf("proxy.image.version=%s", TestHelper.GetVersion()),
    97  		"--set", "heartbeatSchedule=1 2 3 4 5",
    98  	}
    99  
   100  	// Pipe cmd & args to `linkerd`
   101  	out, err := TestHelper.LinkerdRun(cmd...)
   102  	if err != nil {
   103  		testutil.AnnotatedFatal(t, "'linkerd install' command failed", err)
   104  	}
   105  
   106  	out, err = TestHelper.KubectlApplyWithArgs(out)
   107  	if err != nil {
   108  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
   109  			"'kubectl apply' command failed\n%s", out)
   110  	}
   111  
   112  	// Install control-plane
   113  	cmd = []string{
   114  		"install",
   115  		"--controller-log-level", "debug",
   116  		"--set", fmt.Sprintf("proxy.image.version=%s", TestHelper.GetVersion()),
   117  		"--set", "heartbeatSchedule=1 2 3 4 5",
   118  	}
   119  
   120  	// If testing deep suite with CNI, set --cni-enabled to true
   121  	if TestHelper.CNI() {
   122  		cmd = append(cmd, "--linkerd-cni-enabled")
   123  	}
   124  
   125  	if TestHelper.NativeSidecar() {
   126  		cmd = append(cmd, "--set", "proxy.nativeSidecar=true")
   127  	}
   128  
   129  	if TestHelper.DualStack() {
   130  		cmd = append(cmd, "--set", "disableIPv6=false")
   131  	}
   132  
   133  	// Pipe cmd & args to `linkerd`
   134  	out, err = TestHelper.LinkerdRun(cmd...)
   135  	if err != nil {
   136  		testutil.AnnotatedFatal(t, "'linkerd install' command failed", err)
   137  	}
   138  
   139  	out, err = TestHelper.KubectlApplyWithArgs(out)
   140  	if err != nil {
   141  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
   142  			"'kubectl apply' command failed\n%s", out)
   143  	}
   144  
   145  	out, err = TestHelper.LinkerdRun("check", "--wait=3m")
   146  	if err != nil {
   147  		testutil.AnnotatedFatalf(t, "'linkerd check' command failed",
   148  			"'linkerd check' command failed\n%s", out)
   149  	}
   150  }
   151  

View as plain text