...

Source file src/sigs.k8s.io/kustomize/api/krusty/chartinflatorplugin_test.go

Documentation: sigs.k8s.io/kustomize/api/krusty

     1  // +build notravis
     2  
     3  // Copyright 2019 The Kubernetes Authors.
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  // Disabled on travis, because don't want to install helm on travis.
     7  
     8  package krusty_test
     9  
    10  import (
    11  	"regexp"
    12  	"testing"
    13  
    14  	kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
    15  )
    16  
    17  // This is an example of using a helm chart as a base,
    18  // inflating it and then customizing it with a nameprefix
    19  // applied to all its resources.
    20  //
    21  // The helm chart used is downloaded from
    22  //   https://github.com/helm/charts/tree/master/stable/minecraft
    23  // with each test run, so it's a bit brittle as that
    24  // chart could change obviously and break the test.
    25  //
    26  // This test requires having the helm binary on the PATH.
    27  //
    28  // TODO: Download and inflate the chart, and check that
    29  // in for the test.
    30  func TestChartInflatorPlugin(t *testing.T) {
    31  	th := kusttest_test.MakeEnhancedHarness(t).
    32  		PrepExecPlugin("someteam.example.com", "v1", "ChartInflator")
    33  	defer th.Reset()
    34  
    35  	th.WriteK(".", `
    36  generators:
    37  - chartInflator.yaml
    38  namePrefix: LOOOOOOOONG-
    39  `)
    40  
    41  	th.WriteF("./chartInflator.yaml", `
    42  apiVersion: someteam.example.com/v1
    43  kind: ChartInflator
    44  metadata:
    45    name: notImportantHere
    46  chartName: minecraft
    47  `)
    48  
    49  	m := th.Run(".", th.MakeOptionsPluginsEnabled())
    50  	chartName := regexp.MustCompile("chart: minecraft-[0-9.]+")
    51  	th.AssertActualEqualsExpectedWithTweak(m,
    52  		func(x []byte) []byte {
    53  			return chartName.ReplaceAll(x, []byte("chart: minecraft-SOMEVERSION"))
    54  		}, `
    55  apiVersion: v1
    56  data:
    57    rcon-password: Q0hBTkdFTUUh
    58  kind: Secret
    59  metadata:
    60    labels:
    61      app: release-name-minecraft
    62      chart: minecraft-SOMEVERSION
    63      heritage: Tiller
    64      release: release-name
    65    name: LOOOOOOOONG-release-name-minecraft
    66  type: Opaque
    67  ---
    68  apiVersion: v1
    69  kind: PersistentVolumeClaim
    70  metadata:
    71    annotations:
    72      volume.alpha.kubernetes.io/storage-class: default
    73    labels:
    74      app: release-name-minecraft
    75      chart: minecraft-SOMEVERSION
    76      heritage: Tiller
    77      release: release-name
    78    name: LOOOOOOOONG-release-name-minecraft-datadir
    79  spec:
    80    accessModes:
    81    - ReadWriteOnce
    82    resources:
    83      requests:
    84        storage: 1Gi
    85  ---
    86  apiVersion: v1
    87  kind: Service
    88  metadata:
    89    labels:
    90      app: release-name-minecraft
    91      chart: minecraft-SOMEVERSION
    92      heritage: Tiller
    93      release: release-name
    94    name: LOOOOOOOONG-release-name-minecraft
    95  spec:
    96    ports:
    97    - name: minecraft
    98      port: 25565
    99      protocol: TCP
   100      targetPort: minecraft
   101    selector:
   102      app: release-name-minecraft
   103    type: LoadBalancer
   104  `)
   105  }
   106  

View as plain text