github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/topgun/k8s/dns_proxy_test.go (about)

     1  package k8s_test
     2  
     3  import (
     4  	"log"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/ginkgo/extensions/table"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("DNS Resolution", func() {
    12  
    13  	var atc Endpoint
    14  
    15  	BeforeEach(func() {
    16  		setReleaseNameAndNamespace("dp")
    17  	})
    18  
    19  	AfterEach(func() {
    20  		cleanupReleases()
    21  		atc.Close()
    22  	})
    23  
    24  	var fullAddress = func() string {
    25  		return releaseName + "-web." + namespace + ".svc.cluster.local:8080/api/v1/info"
    26  	}
    27  
    28  	var shortAddress = func() string {
    29  		return releaseName + "-web:8080/api/v1/info"
    30  	}
    31  
    32  	type Case struct {
    33  		// args
    34  		enableDnsProxy  string
    35  		dnsServer       string
    36  		addressFunction func() string
    37  
    38  		// expectations
    39  		shouldWork bool
    40  	}
    41  
    42  	const containerdRuntime = "containerd"
    43  	const guardianRuntime = "guardian"
    44  
    45  	var setupDeployment = func(runtime string, dnsProxyEnable, dnsServer string) {
    46  		args := []string{
    47  			`--set=worker.replicas=1`,
    48  			`--set-string=concourse.worker.runtime=` + runtime,
    49  		}
    50  		switch {
    51  		case runtime == containerdRuntime:
    52  			args = append(args, `--set-string=concourse.worker.containerd.dnsProxyEnable=`+dnsProxyEnable)
    53  			if dnsServer != "" {
    54  				args = append(args,
    55  					`--set=worker.env[0].name=CONCOURSE_CONTAINERD_DNS_SERVER`,
    56  					`--set=worker.env[0].value=`+dnsServer)
    57  			}
    58  		case runtime == guardianRuntime:
    59  			args = append(args, `--set-string=concourse.worker.garden.dnsProxyEnable=`+dnsProxyEnable)
    60  			if dnsServer != "" {
    61  				args = append(args,
    62  					`--set=worker.env[0].name=CONCOURSE_GARDEN_DNS_SERVER`,
    63  					`--set=worker.env[0].value=`+dnsServer)
    64  			}
    65  		default:
    66  			log.Fatalf("Invalid runtime type %s. Test aborted.", runtime)
    67  			return
    68  		}
    69  
    70  		deployConcourseChart(releaseName, args...)
    71  		atc = waitAndLogin(namespace, releaseName+"-web")
    72  	}
    73  
    74  	expectedDnsProxyBehaviour := func(runtime string) {
    75  		DescribeTable("different proxy settings",
    76  			func(c Case) {
    77  				setupDeployment(runtime, c.enableDnsProxy, c.dnsServer)
    78  
    79  				sess := fly.Start("execute", "-c", "tasks/dns-proxy-task.yml", "-v", "url="+c.addressFunction())
    80  				<-sess.Exited
    81  
    82  				if !c.shouldWork {
    83  					Expect(sess.ExitCode()).ToNot(BeZero())
    84  					return
    85  				}
    86  
    87  				Expect(sess.ExitCode()).To(BeZero())
    88  			},
    89  			Entry("Proxy Enabled, with full service name", Case{
    90  				enableDnsProxy:  "true",
    91  				addressFunction: fullAddress,
    92  				shouldWork:      true,
    93  			}),
    94  			Entry("Proxy Enabled, with short service name", Case{
    95  				enableDnsProxy:  "true",
    96  				addressFunction: shortAddress,
    97  				shouldWork:      false,
    98  			}),
    99  			Entry("Proxy Disabled, with full service name", Case{
   100  				enableDnsProxy:  "false",
   101  				addressFunction: fullAddress,
   102  				shouldWork:      true,
   103  			}),
   104  			Entry("Proxy Disabled, with short service name", Case{
   105  				enableDnsProxy:  "false",
   106  				addressFunction: shortAddress,
   107  				shouldWork:      true,
   108  			}),
   109  			Entry("Adding extra dns server, with Proxy Disabled and full address", Case{
   110  				enableDnsProxy:  "false",
   111  				dnsServer:       "8.8.8.8",
   112  				addressFunction: fullAddress,
   113  				shouldWork:      false,
   114  			}),
   115  			Entry("Adding extra dns server, with Proxy Enabled and full address", Case{
   116  				enableDnsProxy:  "true",
   117  				dnsServer:       "8.8.8.8",
   118  				addressFunction: fullAddress,
   119  				shouldWork:      false,
   120  			}),
   121  		)
   122  	}
   123  
   124  	Context("with gdn backend", func() {
   125  		expectedDnsProxyBehaviour(guardianRuntime)
   126  	})
   127  
   128  	Context("with containerd backend", func() {
   129  		expectedDnsProxyBehaviour(containerdRuntime)
   130  	})
   131  })