github.com/GoogleContainerTools/skaffold/v2@v2.13.2/integration/apply_test.go (about) 1 /* 2 Copyright 2021 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package integration 18 19 import ( 20 "fmt" 21 "testing" 22 23 "github.com/GoogleContainerTools/skaffold/v2/integration/skaffold" 24 "github.com/GoogleContainerTools/skaffold/v2/testutil" 25 ) 26 27 func TestDiagnoseRenderApply(t *testing.T) { 28 // This test verifies that `skaffold apply` can consume the output of both `skaffold render` and `skaffold diagnose`. 29 30 // 1. Run `skaffold diagnose --yaml-only` to resolve and combine skaffold configs for a multi-config project 31 // 2. Run `skaffold render` using this config to hydrate manifests 32 // 3. Run `skaffold apply` using the config from `diagnose` and the manifests from `render` to create resources on the cluster. 33 34 testutil.Run(t, "DiagnoseRenderApply", func(t *testutil.T) { 35 MarkIntegrationTest(t.T, NeedsGcp) 36 ns, client := SetupNamespace(t.T) 37 38 out := skaffold.Diagnose("--yaml-only").InDir("testdata/multi-config-pods").RunOrFailOutput(t.T) 39 40 tmpDir := testutil.NewTempDir(t.T) 41 tmpDir.Chdir() 42 43 tmpDir.Write("skaffold-diagnose.yaml", string(out)) 44 45 out = skaffold.Render("--digest-source=local", "-f", "skaffold-diagnose.yaml", "--platform", "linux/amd64,linux/arm64").InNs(ns.Name).RunOrFailOutput(t.T) 46 tmpDir.Write("render.yaml", string(out)) 47 48 skaffold.Apply("render.yaml", "-f", "skaffold-diagnose.yaml").InNs(ns.Name).RunOrFail(t.T) 49 50 pod1 := client.GetPod("module1") 51 t.CheckNotNil(pod1) 52 pod2 := client.GetPod("module2") 53 t.CheckNotNil(pod2) 54 }) 55 } 56 57 func TestRenderApplyHelmDeployment(t *testing.T) { 58 testutil.Run(t, "DiagnoseRenderApply", func(t *testutil.T) { 59 MarkIntegrationTest(t.T, NeedsGcp) 60 ns, client := SetupNamespace(t.T) 61 62 out := skaffold.Diagnose("--yaml-only").InDir("examples/helm-deployment").RunOrFailOutput(t.T) 63 64 tmpDir := testutil.NewTempDir(t.T) 65 tmpDir.Chdir() 66 67 tmpDir.Write("skaffold-diagnose.yaml", string(out)) 68 69 out = skaffold.Render("--digest-source=local", "-f", "skaffold-diagnose.yaml", "--platform", "linux/amd64,linux/arm64").InNs(ns.Name).RunOrFailOutput(t.T) 70 tmpDir.Write("render.yaml", string(out)) 71 72 skaffold.Apply("render.yaml", "-f", "skaffold-diagnose.yaml").InNs(ns.Name).RunOrFail(t.T) 73 74 depApp := client.GetDeployment("skaffold-helm") 75 t.CheckNotNil(depApp) 76 }) 77 } 78 79 // Ensure that an intentionally broken deployment fails the status check in `skaffold apply`. 80 func TestApplyStatusCheckFailure(t *testing.T) { 81 tests := []struct { 82 description string 83 profile string 84 }{ 85 { 86 description: "status check for deployment resources", 87 profile: "deployment", 88 }, 89 { 90 description: "status check for statefulset resources", 91 profile: "statefulset", 92 }, 93 //{ 94 // config connector resource status doesn't distinguish between resource that is making progress towards reconciling from one that is doomed. 95 // This is tracked in b/187759279 internally. The test currently passes due to status check timeout, it's not what we want to test, hence 96 // commenting this out at the moment. 97 // description: "status check for config connector resources", 98 // profile: "configconnector", 99 // }, 100 { 101 description: "status check for standalone pods", 102 profile: "pod", 103 }, 104 } 105 for _, test := range tests { 106 testutil.Run(t, test.description, func(t *testutil.T) { 107 MarkIntegrationTest(t.T, NeedsGcp) 108 ns, _ := SetupNamespace(t.T) 109 defer skaffold.Delete("-p", test.profile).InDir("testdata/apply").InNs(ns.Name).Run(t.T) 110 err := skaffold.Apply(fmt.Sprintf("%s.yaml", test.profile)).InDir("testdata/apply").InNs(ns.Name).Run(t.T) 111 t.CheckError(true, err) 112 }) 113 } 114 } 115 116 func TestApplyMultipleNamespaces(t *testing.T) { 117 testutil.Run(t, "TestApplyMultipleNamespaces", func(t *testutil.T) { 118 MarkIntegrationTest(t.T, NeedsGcp) 119 ns, client := SetupNamespace(t.T) 120 ns2, _ := SetupNamespace(t.T) 121 122 _, _, fErr := replaceInFile("namespace1", ns.Name, fmt.Sprintf("%s/skaffold.yaml", "testdata/helm-multi-namespaces")) 123 t.CheckNoError(fErr) 124 _, _, fErr = replaceInFile("namespace2", ns2.Name, fmt.Sprintf("%s/charts/templates/deployment.yaml", "testdata/helm-multi-namespaces")) 125 t.CheckNoError(fErr) 126 127 defer skaffold.Delete().InDir("testdata/helm-multi-namespaces").Run(t.T) 128 skaffold.Render("--digest-source=local", "--platform", "linux/amd64,linux/arm64", "--output", "render.yaml").InDir("testdata/helm-multi-namespaces").RunOrFail(t.T) 129 skaffold.Apply("render.yaml").InDir("testdata/helm-multi-namespaces").RunOrFail(t.T) 130 131 depApp := client.GetDeployment("skaffold-helm") 132 t.CheckNotNil(depApp) 133 }) 134 }