From c3998560c9f606251f9d5c1522871697be504582 Mon Sep 17 00:00:00 2001 From: Renzo Rojas Date: Wed, 20 Mar 2024 09:46:42 -0400 Subject: [PATCH] feat: extend `skaffold inspect config-dependencies add` to support GCB Repo v2 (#9349) --- .../inspect/configDependencies/add.go | 32 ++++++++++-- .../inspect/configDependencies/add_test.go | 51 +++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/pkg/skaffold/inspect/configDependencies/add.go b/pkg/skaffold/inspect/configDependencies/add.go index c3e853b66a0..210e2facafa 100644 --- a/pkg/skaffold/inspect/configDependencies/add.go +++ b/pkg/skaffold/inspect/configDependencies/add.go @@ -33,11 +33,12 @@ type configDependencyList struct { } type configDependencyEntry struct { - Names []string `json:"configs,omitempty"` - Path string `json:"path,omitempty"` - Git *git `json:"git,omitempty"` - GoogleCloudStorage *googleCloudStorage `json:"googleCloudStorage,omitempty"` - ActiveProfiles []activeProfile `json:"activeProfiles,omitempty"` + Names []string `json:"configs,omitempty"` + Path string `json:"path,omitempty"` + Git *git `json:"git,omitempty"` + GoogleCloudStorage *googleCloudStorage `json:"googleCloudStorage,omitempty"` + GoogleCloudBuildRepoV2 *googleCloudBuildRepoV2 `json:"googleCloudBuildRepoV2,omitempty"` + ActiveProfiles []activeProfile `json:"activeProfiles,omitempty"` } type git struct { @@ -53,6 +54,16 @@ type googleCloudStorage struct { Sync bool `json:"sync,omitempty"` } +type googleCloudBuildRepoV2 struct { + ProjectID string `json:"projectID"` + Region string `json:"region"` + Connection string `json:"connection"` + Repo string `json:"repo"` + Path string `json:"path,omitempty"` + Ref string `json:"ref,omitempty"` + Sync bool `json:"sync,omitempty"` +} + type activeProfile struct { Name string `json:"name"` ActivatedBy []string `json:"activatedBy,omitempty"` @@ -118,6 +129,17 @@ func convertToLatestConfigDependencies(cfgDepList configDependencyList) []latest Sync: &d.GoogleCloudStorage.Sync, } } + if d.GoogleCloudBuildRepoV2 != nil { + cd.GoogleCloudBuildRepoV2 = &latest.GoogleCloudBuildRepoV2Info{ + ProjectID: d.GoogleCloudBuildRepoV2.ProjectID, + Region: d.GoogleCloudBuildRepoV2.Region, + Connection: d.GoogleCloudBuildRepoV2.Connection, + Repo: d.GoogleCloudBuildRepoV2.Repo, + Path: d.GoogleCloudBuildRepoV2.Path, + Ref: d.GoogleCloudBuildRepoV2.Ref, + Sync: &d.GoogleCloudBuildRepoV2.Sync, + } + } var profileDep []latest.ProfileDependency for _, ap := range d.ActiveProfiles { profileDep = append(profileDep, latest.ProfileDependency{ diff --git a/pkg/skaffold/inspect/configDependencies/add_test.go b/pkg/skaffold/inspect/configDependencies/add_test.go index aa81410427b..fecf1cf28ca 100644 --- a/pkg/skaffold/inspect/configDependencies/add_test.go +++ b/pkg/skaffold/inspect/configDependencies/add_test.go @@ -180,6 +180,57 @@ apiVersion: %s kind: Config metadata: name: cfg1_1 +`, apiVersion, apiVersion), + }, + { + description: "adds GoogleCloudBuildRepoV2 remote config dependency", + config: fmt.Sprintf(`apiVersion: %s +kind: Config +metadata: + name: cfg1 +--- +apiVersion: %s +kind: Config +metadata: + name: cfg2 +`, apiVersion, apiVersion), + input: ` +{ + "dependencies": [ + { + "configs": ["c1"], + "googleCloudBuildRepoV2": { + "projectID": "k8s-skaffold", + "region": "us-central1", + "connection": "github-connection-e2e-tests", + "repo": "skaffold-getting-started", + "path": "skaffold.yaml", + "ref": "main" + } + } + ] +}`, + modules: []string{"cfg1"}, + expected: fmt.Sprintf(`apiVersion: %s +kind: Config +metadata: + name: cfg1 +requires: + - configs: + - c1 + googleCloudBuildRepoV2: + projectID: k8s-skaffold + region: us-central1 + connection: github-connection-e2e-tests + repo: skaffold-getting-started + path: skaffold.yaml + ref: main + sync: false +--- +apiVersion: %s +kind: Config +metadata: + name: cfg2 `, apiVersion, apiVersion), }, {