...

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

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

     1  package externaltest
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/linkerd/linkerd2/pkg/k8s"
    10  	"github.com/linkerd/linkerd2/pkg/tls"
    11  	"github.com/linkerd/linkerd2/testutil"
    12  )
    13  
    14  //////////////////////
    15  ///   TEST SETUP   ///
    16  //////////////////////
    17  
    18  var (
    19  	TestHelper *testutil.TestHelper
    20  )
    21  
    22  func TestMain(m *testing.M) {
    23  	TestHelper = testutil.NewTestHelper()
    24  	os.Exit(m.Run())
    25  }
    26  
    27  //////////////////////
    28  /// TEST EXECUTION ///
    29  //////////////////////
    30  
    31  // TestInstallLinkerd will install the linkerd control plane to be used in the rest of
    32  // the deep suite tests
    33  func TestInstallLinkerd(t *testing.T) {
    34  
    35  	err := TestHelper.CreateControlPlaneNamespaceIfNotExists(context.Background(), TestHelper.GetLinkerdNamespace())
    36  	if err != nil {
    37  		testutil.AnnotatedFatalf(t, fmt.Sprintf("failed to create %s namespace", TestHelper.GetLinkerdNamespace()),
    38  			"failed to create %s namespace: %s", TestHelper.GetLinkerdNamespace(), err)
    39  	}
    40  
    41  	identity := fmt.Sprintf("identity.%s.%s", TestHelper.GetLinkerdNamespace(), TestHelper.GetClusterDomain())
    42  
    43  	root, err := tls.GenerateRootCAWithDefaults(identity)
    44  	if err != nil {
    45  		testutil.AnnotatedFatal(t, "error generating root CA", err)
    46  	}
    47  
    48  	// instead of passing the roots and key around we generate
    49  	// two secrets here. The second one will be used in the
    50  	// external_issuer_test to update the first one and trigger
    51  	// cert rotation in the identity service. That allows us
    52  	// to generated the certs on the fly and use custom domain.
    53  	if err = TestHelper.CreateTLSSecret(
    54  		k8s.IdentityIssuerSecretName,
    55  		root.Cred.Crt.EncodeCertificatePEM(),
    56  		root.Cred.Crt.EncodeCertificatePEM(),
    57  		root.Cred.EncodePrivateKeyPEM()); err != nil {
    58  		testutil.AnnotatedFatal(t, "error creating TLS secret", err)
    59  	}
    60  
    61  	crt2, err := root.GenerateCA(identity, -1)
    62  	if err != nil {
    63  		testutil.AnnotatedFatal(t, "error generating CA", err)
    64  	}
    65  
    66  	if err = TestHelper.CreateTLSSecret(
    67  		k8s.IdentityIssuerSecretName+"-new",
    68  		root.Cred.Crt.EncodeCertificatePEM(),
    69  		crt2.Cred.EncodeCertificatePEM(),
    70  		crt2.Cred.EncodePrivateKeyPEM()); err != nil {
    71  		testutil.AnnotatedFatal(t, "error creating TLS secret (-new)", err)
    72  	}
    73  
    74  	// Install CRDs
    75  	cmd := []string{
    76  		"install",
    77  		"--crds",
    78  		"--controller-log-level", "debug",
    79  		"--set", fmt.Sprintf("proxy.image.version=%s", TestHelper.GetVersion()),
    80  		"--set", "heartbeatSchedule=1 2 3 4 5",
    81  		"--identity-issuance-lifetime=15s",
    82  		"--identity-external-issuer=true",
    83  	}
    84  
    85  	// Pipe cmd & args to `linkerd`
    86  	out, err := TestHelper.LinkerdRun(cmd...)
    87  	if err != nil {
    88  		testutil.AnnotatedFatal(t, "'linkerd install --crds' command failed", err)
    89  	}
    90  
    91  	out, err = TestHelper.KubectlApplyWithArgs(out)
    92  	if err != nil {
    93  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
    94  			"'kubectl apply' command failed\n%s", out)
    95  	}
    96  
    97  	// Install control-plane with a short cert lifetime to put some pressure on
    98  	// the CSR request, response code path.
    99  	cmd = []string{
   100  		"install",
   101  		"--controller-log-level", "debug",
   102  		"--set", fmt.Sprintf("proxy.image.version=%s", TestHelper.GetVersion()),
   103  		"--set", "heartbeatSchedule=1 2 3 4 5",
   104  		"--identity-issuance-lifetime=15s",
   105  		"--identity-external-issuer=true",
   106  	}
   107  
   108  	// Pipe cmd & args to `linkerd`
   109  	out, err = TestHelper.LinkerdRun(cmd...)
   110  	if err != nil {
   111  		testutil.AnnotatedFatal(t, "'linkerd install' command failed", err)
   112  	}
   113  
   114  	out, err = TestHelper.KubectlApplyWithArgs(out)
   115  	if err != nil {
   116  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
   117  			"'kubectl apply' command failed\n%s", out)
   118  	}
   119  
   120  	TestHelper.WaitRollout(t, testutil.LinkerdDeployReplicasEdge)
   121  }
   122  
   123  // TestInstallViz will install the viz extension to be used by the rest of the
   124  // tests in the viz suite
   125  func TestInstallViz(t *testing.T) {
   126  	// Install external prometheus
   127  	out, err := TestHelper.LinkerdRun("inject", "testdata/external_prometheus.yaml", "--manual")
   128  	if err != nil {
   129  		testutil.AnnotatedFatalf(t, "'linkerd inject' command failed", "'linkerd inject' command failed: %s", err)
   130  	}
   131  
   132  	out, err = TestHelper.KubectlApply(out, "")
   133  	if err != nil {
   134  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
   135  			"kubectl apply command failed\n%s", out)
   136  	}
   137  
   138  	cmd := []string{
   139  		"viz",
   140  		"install",
   141  		"--set", fmt.Sprintf("namespace=%s", TestHelper.GetVizNamespace()),
   142  		"--set", "prometheusUrl=http://prometheus.external-prometheus.svc.cluster.local:9090",
   143  		"--set", "prometheus.enabled=false",
   144  	}
   145  
   146  	out, err = TestHelper.LinkerdRun(cmd...)
   147  	if err != nil {
   148  		testutil.AnnotatedFatal(t, "'linkerd viz install' command failed", err)
   149  	}
   150  
   151  	out, err = TestHelper.KubectlApplyWithArgs(out)
   152  	if err != nil {
   153  		testutil.AnnotatedFatalf(t, "'kubectl apply' command failed",
   154  			"'kubectl apply' command failed\n%s", out)
   155  	}
   156  
   157  	expectedDeployments := make(map[string]testutil.DeploySpec, len(testutil.LinkerdVizDeployReplicas))
   158  	for k, v := range testutil.LinkerdVizDeployReplicas {
   159  		if k == "prometheus" {
   160  			v = testutil.DeploySpec{Namespace: "external-prometheus", Replicas: 1}
   161  		}
   162  
   163  		expectedDeployments[k] = v
   164  	}
   165  	TestHelper.WaitRollout(t, expectedDeployments)
   166  
   167  }
   168  
   169  func TestCheckVizWithExternalPrometheus(t *testing.T) {
   170  	if err := TestHelper.TestCheck(); err != nil {
   171  		t.Fatalf("'linkerd check' command failed: %s", err)
   172  	}
   173  }
   174  

View as plain text