Skip to content

Commit e7f7421

Browse files
committed
Merge branch 'sh-support-google-universe-domain' into 'main'
Add support for Google Cloud Service universe domain See merge request https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/6338 Merged-by: Stan Hu <stanhu@gmail.com> Approved-by: Sam Roque-Worcel <sroque-worcel@gitlab.com> Approved-by: Axel von Bertoldi <avonbertoldi@gitlab.com>
2 parents 35ccc46 + 2f17a9f commit e7f7421

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

cache/gcsv2/adapter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func (a *gcsAdapter) presignURL(ctx context.Context, method string, contentType
7979
options = append(options, option.WithoutAuthentication())
8080
}
8181

82+
if a.config.UniverseDomain != "" {
83+
options = append(options, option.WithUniverseDomain(a.config.UniverseDomain))
84+
}
85+
8286
client, err := storage.NewClient(ctx, options...)
8387
if err != nil {
8488
return nil, fmt.Errorf("creating storage client: %w", err)

common/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ type CacheGCSConfig struct {
11951195
CacheGCSCredentials
11961196
CredentialsFile string `toml:"CredentialsFile,omitempty" long:"credentials-file" env:"GOOGLE_APPLICATION_CREDENTIALS" description:"File with GCP credentials, containing AccessID and PrivateKey"`
11971197
BucketName string `toml:"BucketName,omitempty" long:"bucket-name" env:"CACHE_GCS_BUCKET_NAME" description:"Name of the bucket where cache will be stored"`
1198+
UniverseDomain string `toml:"UniverseDomain,omitempty" long:"universe-domain" env:"CACHE_GCS_UNIVERSE_DOMAIN" description:"Universe Domain for GCS requests (e.g., googleapis.com for public cloud, or a custom universe domain)"`
11981199
}
11991200

12001201
type CacheS3Config struct {

common/config_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,54 @@ import (
2222
"gitlab.com/gitlab-org/gitlab-runner/helpers/process"
2323
)
2424

25+
func TestCacheGCSConfig_UniverseDomain(t *testing.T) {
26+
tests := map[string]struct {
27+
config string
28+
expectedDomain string
29+
validateConfig func(t *testing.T, config *Config)
30+
}{
31+
"universe domain not set": {
32+
config: `
33+
[[runners]]
34+
[runners.cache.gcs]
35+
BucketName = "test-bucket"
36+
`,
37+
expectedDomain: "",
38+
},
39+
"universe domain set to googleapis.com": {
40+
config: `
41+
[[runners]]
42+
[runners.cache.gcs]
43+
BucketName = "test-bucket"
44+
UniverseDomain = "googleapis.com"
45+
`,
46+
expectedDomain: "googleapis.com",
47+
},
48+
"universe domain set to custom universe": {
49+
config: `
50+
[[runners]]
51+
[runners.cache.gcs]
52+
BucketName = "test-bucket"
53+
UniverseDomain = "custom.universe.com"
54+
`,
55+
expectedDomain: "custom.universe.com",
56+
},
57+
}
58+
59+
for name, tt := range tests {
60+
t.Run(name, func(t *testing.T) {
61+
cfg := NewConfig()
62+
_, err := toml.Decode(tt.config, cfg)
63+
assert.NoError(t, err)
64+
65+
require.Len(t, cfg.Runners, 1)
66+
require.NotNil(t, cfg.Runners[0].Cache)
67+
require.NotNil(t, cfg.Runners[0].Cache.GCS)
68+
assert.Equal(t, tt.expectedDomain, cfg.Runners[0].Cache.GCS.UniverseDomain)
69+
})
70+
}
71+
}
72+
2573
func TestCacheS3Config_AuthType(t *testing.T) {
2674
tests := map[string]struct {
2775
s3 CacheS3Config
@@ -2593,6 +2641,36 @@ func TestConfig_Masked(t *testing.T) {
25932641
},
25942642
},
25952643
},
2644+
"cache gcs universe domain": {
2645+
input: &Config{
2646+
Runners: []*RunnerConfig{
2647+
{
2648+
RunnerSettings: RunnerSettings{
2649+
Cache: &CacheConfig{
2650+
GCS: &CacheGCSConfig{
2651+
BucketName: "test-bucket",
2652+
UniverseDomain: "googleapis.com",
2653+
},
2654+
},
2655+
},
2656+
},
2657+
},
2658+
},
2659+
expected: &Config{
2660+
Runners: []*RunnerConfig{
2661+
{
2662+
RunnerSettings: RunnerSettings{
2663+
Cache: &CacheConfig{
2664+
GCS: &CacheGCSConfig{
2665+
BucketName: "test-bucket",
2666+
UniverseDomain: "googleapis.com",
2667+
},
2668+
},
2669+
},
2670+
},
2671+
},
2672+
},
2673+
},
25962674
"cache azure account key": {
25972675
input: &Config{
25982676
Runners: []*RunnerConfig{

0 commit comments

Comments
 (0)