| 1 |
// Copyright 2020 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package krusty_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" |
| 10 |
) |
| 11 |
|
| 12 |
func TestPodDisruptionBudgetBasics(t *testing.T) { |
| 13 |
th := kusttest_test.MakeHarness(t) |
| 14 |
th.WriteF("pdbLiteral.yaml", ` |
| 15 |
apiVersion: policy/v1beta1 |
| 16 |
kind: PodDisruptionBudget |
| 17 |
metadata: |
| 18 |
name: pdbLiteral |
| 19 |
spec: |
| 20 |
maxUnavailable: 90 |
| 21 |
`) |
| 22 |
th.WriteF("pdbPercentage.yaml", ` |
| 23 |
apiVersion: policy/v1beta1 |
| 24 |
kind: PodDisruptionBudget |
| 25 |
metadata: |
| 26 |
name: pdbPercentage |
| 27 |
spec: |
| 28 |
maxUnavailable: 90% |
| 29 |
`) |
| 30 |
th.WriteK(".", ` |
| 31 |
resources: |
| 32 |
- pdbLiteral.yaml |
| 33 |
- pdbPercentage.yaml |
| 34 |
`) |
| 35 |
m := th.Run(".", th.MakeDefaultOptions()) |
| 36 |
// In a PodDisruptionBudget, the fields maxUnavailable |
| 37 |
// minAvailable are mutually exclusive, and both can hold |
| 38 |
// either an integer, i.e. 10, or string that has to be |
| 39 |
// an int followed by a percent sign, e.g. 10%. |
| 40 |
th.AssertActualEqualsExpected(m, ` |
| 41 |
apiVersion: policy/v1beta1 |
| 42 |
kind: PodDisruptionBudget |
| 43 |
metadata: |
| 44 |
name: pdbLiteral |
| 45 |
spec: |
| 46 |
maxUnavailable: 90 |
| 47 |
--- |
| 48 |
apiVersion: policy/v1beta1 |
| 49 |
kind: PodDisruptionBudget |
| 50 |
metadata: |
| 51 |
name: pdbPercentage |
| 52 |
spec: |
| 53 |
maxUnavailable: 90% |
| 54 |
`) |
| 55 |
} |
| 56 |
|
| 57 |
func TestPodDisruptionBudgetMerging(t *testing.T) { |
| 58 |
th := kusttest_test.MakeHarness(t) |
| 59 |
th.WriteF("pdb-patch.yaml", ` |
| 60 |
apiVersion: policy/v1beta1 |
| 61 |
kind: PodDisruptionBudget |
| 62 |
metadata: |
| 63 |
name: generic-pdb |
| 64 |
spec: |
| 65 |
maxUnavailable: 1 |
| 66 |
`) |
| 67 |
th.WriteF("my_file.yaml", ` |
| 68 |
apiVersion: policy/v1beta1 |
| 69 |
kind: PodDisruptionBudget |
| 70 |
metadata: |
| 71 |
name: championships-api |
| 72 |
labels: |
| 73 |
faceit-pdb: default |
| 74 |
spec: |
| 75 |
maxUnavailable: 100% |
| 76 |
--- |
| 77 |
apiVersion: policy/v1beta1 |
| 78 |
kind: PodDisruptionBudget |
| 79 |
metadata: |
| 80 |
name: championships-api-2 |
| 81 |
labels: |
| 82 |
faceit-pdb: default |
| 83 |
spec: |
| 84 |
maxUnavailable: 100% |
| 85 |
`) |
| 86 |
th.WriteK(".", ` |
| 87 |
patches: |
| 88 |
- path: pdb-patch.yaml |
| 89 |
target: |
| 90 |
kind: PodDisruptionBudget |
| 91 |
labelSelector: faceit-pdb=default |
| 92 |
|
| 93 |
resources: |
| 94 |
- my_file.yaml |
| 95 |
`) |
| 96 |
m := th.Run(".", th.MakeDefaultOptions()) |
| 97 |
// In a PodDisruptionBudget, the fields maxUnavailable |
| 98 |
// minAvailable are mutually exclusive, and both can hold |
| 99 |
// either an integer, i.e. 10, or string that has to be |
| 100 |
// an int followed by a percent sign, e.g. 10%. |
| 101 |
// In the former case - bare integer - they should NOT be quoted |
| 102 |
// as the api server will reject it. In the latter case with |
| 103 |
// the percent sign, quotes can be added and the API server will |
| 104 |
// accept it, but they don't have to be added. |
| 105 |
th.AssertActualEqualsExpected( |
| 106 |
m, ` |
| 107 |
apiVersion: policy/v1beta1 |
| 108 |
kind: PodDisruptionBudget |
| 109 |
metadata: |
| 110 |
labels: |
| 111 |
faceit-pdb: default |
| 112 |
name: championships-api |
| 113 |
spec: |
| 114 |
maxUnavailable: 1 |
| 115 |
--- |
| 116 |
apiVersion: policy/v1beta1 |
| 117 |
kind: PodDisruptionBudget |
| 118 |
metadata: |
| 119 |
labels: |
| 120 |
faceit-pdb: default |
| 121 |
name: championships-api-2 |
| 122 |
spec: |
| 123 |
maxUnavailable: 1 |
| 124 |
`) |
| 125 |
} |