Skip to content

Commit da42594

Browse files
authored
feat: new gcs client using cloud client libraries (#9518)
* feat: new gcs client using cloud client libraries * feat: tests for new native client and changes in other places to make it work with new implementation
1 parent f4e1501 commit da42594

File tree

8 files changed

+874
-17
lines changed

8 files changed

+874
-17
lines changed

integration/remote_config_dependency_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,105 @@ requires:
120120
})
121121
}
122122
}
123+
124+
func TestRenderWithRemoteGCS(t *testing.T) {
125+
tests := []struct {
126+
description string
127+
configFile string
128+
args []string
129+
shouldErr bool
130+
expectedOutput string
131+
expectedErrMsg string
132+
}{
133+
{
134+
description: "download all repo with same folders from subfolder",
135+
configFile: `apiVersion: skaffold/v4beta11
136+
kind: Config
137+
requires:
138+
- googleCloudStorage:
139+
source: gs://skaffold-remote-dependency-e2e-tests/test1/*
140+
path: ./skaffold.yaml
141+
`,
142+
args: []string{"--tag", "fixed", "--default-repo=", "--digest-source", "tag"},
143+
expectedOutput: `apiVersion: v1
144+
kind: Pod
145+
metadata:
146+
name: getting-started
147+
spec:
148+
containers:
149+
- image: skaffold-example:fixed
150+
name: getting-started`,
151+
},
152+
{
153+
description: "download full repo with top sub folder",
154+
configFile: `apiVersion: skaffold/v4beta11
155+
kind: Config
156+
requires:
157+
- googleCloudStorage:
158+
source: gs://skaffold-remote-dependency-e2e-tests/test1
159+
path: ./test1/skaffold.yaml
160+
`,
161+
args: []string{"--tag", "fixed", "--default-repo=", "--digest-source", "tag"},
162+
expectedOutput: `apiVersion: v1
163+
kind: Pod
164+
metadata:
165+
name: getting-started
166+
spec:
167+
containers:
168+
- image: skaffold-example:fixed
169+
name: getting-started`,
170+
},
171+
{
172+
description: "download full repo with bucket name as top folder",
173+
configFile: `apiVersion: skaffold/v4beta11
174+
kind: Config
175+
requires:
176+
- googleCloudStorage:
177+
source: gs://skaffold-remote-dependency-e2e-tests
178+
path: ./skaffold-remote-dependency-e2e-tests/test1/skaffold.yaml
179+
`,
180+
args: []string{"--tag", "fixed", "--default-repo=", "--digest-source", "tag"},
181+
expectedOutput: `apiVersion: v1
182+
kind: Pod
183+
metadata:
184+
name: getting-started
185+
spec:
186+
containers:
187+
- image: skaffold-example:fixed
188+
name: getting-started`,
189+
},
190+
{
191+
description: "download only all yaml files across bucket",
192+
configFile: `apiVersion: skaffold/v4beta11
193+
kind: Config
194+
requires:
195+
- googleCloudStorage:
196+
source: gs://skaffold-remote-dependency-e2e-tests/test1/**.yaml
197+
path: ./skaffold.yaml
198+
`,
199+
args: []string{"--tag", "fixed", "--default-repo=", "--digest-source", "tag", "-p", "flat-structure"},
200+
expectedOutput: `apiVersion: v1
201+
kind: Pod
202+
metadata:
203+
name: getting-started
204+
spec:
205+
containers:
206+
- image: skaffold-example:fixed
207+
name: getting-started`,
208+
},
209+
}
210+
211+
for _, test := range tests {
212+
testutil.Run(t, test.description, func(t *testutil.T) {
213+
MarkIntegrationTest(t.T, NeedsGcp)
214+
tmpDirRemoteRepo := t.NewTempDir()
215+
tmpDirTest := t.NewTempDir()
216+
217+
tmpDirTest.Write("skaffold.yaml", test.configFile)
218+
args := append(test.args, "--remote-cache-dir", tmpDirRemoteRepo.Root())
219+
output, err := skaffold.Render(args...).InDir(tmpDirTest.Root()).RunWithCombinedOutput(t.T)
220+
t.CheckNoError(err)
221+
t.CheckDeepEqual(test.expectedOutput, string(output), testutil.YamlObj(t.T))
222+
})
223+
}
224+
}

pkg/skaffold/deploy/kubectl/kubectl_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"fmt"
2424
"io"
2525
"os"
26-
"path/filepath"
2726
"testing"
2827
"time"
2928

@@ -40,6 +39,11 @@ import (
4039
"github.com/GoogleContainerTools/skaffold/v2/testutil"
4140
)
4241

42+
type gcsClientMock struct{}
43+
44+
func (g gcsClientMock) DownloadRecursive(ctx context.Context, src, dst string) error {
45+
return nil
46+
}
4347
func TestKubectlV1RenderDeploy(t *testing.T) {
4448
tests := []struct {
4549
description string
@@ -520,13 +524,15 @@ func TestGCSManifests(t *testing.T) {
520524
RawK8s: []string{"gs://dev/deployment.yaml"},
521525
},
522526
commands: testutil.
523-
CmdRunOut(fmt.Sprintf("gsutil cp -r %s %s", "gs://dev/deployment.yaml", filepath.Join(manifest.ManifestTmpDir, manifest.ManifestsFromGCS)), "log").
524-
AndRun("kubectl --context kubecontext --namespace testNamespace apply -f -"),
527+
CmdRun("kubectl --context kubecontext --namespace testNamespace apply -f -"),
525528
}}
526529
for _, test := range tests {
527530
testutil.Run(t, test.description, func(t *testutil.T) {
528531
t.Override(&client.Client, deployutil.MockK8sClient)
529532
t.Override(&util.DefaultExecCommand, test.commands)
533+
t.Override(&manifest.GetGCSClient, func() manifest.GCSClient {
534+
return gcsClientMock{}
535+
})
530536
if err := os.MkdirAll(manifest.ManifestTmpDir, os.ModePerm); err != nil {
531537
t.Fatal(err)
532538
}

0 commit comments

Comments
 (0)