Skip to content

Commit f26b041

Browse files
authored
Merge pull request #2512 from lizardruss/pull-secrets-upgrade
fix: add pull secret config for images during v5->v6 schema upgrade
2 parents 94cde72 + 25edaa3 commit f26b041

6 files changed

Lines changed: 82 additions & 6 deletions

File tree

e2e/tests/pullsecret/pullsecrets.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package pullsecret
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/base64"
7+
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
68
"github.com/onsi/ginkgo/v2"
9+
"gopkg.in/yaml.v3"
710
"os"
811
"sort"
912

@@ -96,4 +99,28 @@ var _ = DevSpaceDescribe("pullsecret", func() {
9699
framework.ExpectEqual(serviceAccount.ImagePullSecrets[1].Name, "merged-secret")
97100
framework.ExpectEqual(serviceAccount.ImagePullSecrets[2].Name, "test-secret")
98101
})
102+
103+
ginkgo.It("should create pullsecrets for v1beta11 images", func() {
104+
tempDir, err := framework.CopyToTempDir("tests/pullsecret/testdata/v1-upgrade")
105+
framework.ExpectNoError(err)
106+
defer framework.CleanupTempDir(initialDir, tempDir)
107+
108+
// create a new print command
109+
configBuffer := &bytes.Buffer{}
110+
printCmd := &cmd.PrintCmd{
111+
GlobalFlags: &flags.GlobalFlags{},
112+
Out: configBuffer,
113+
SkipInfo: true,
114+
}
115+
116+
err = printCmd.Run(f)
117+
framework.ExpectNoError(err)
118+
119+
latestConfig := &latest.Config{}
120+
err = yaml.Unmarshal(configBuffer.Bytes(), latestConfig)
121+
framework.ExpectNoError(err)
122+
framework.ExpectEqual(len(latestConfig.PullSecrets), 2)
123+
framework.ExpectEqual(latestConfig.PullSecrets["app"].Registry, "registry1.example.com")
124+
framework.ExpectEqual(latestConfig.PullSecrets["skip"].Registry, "registry2.example.com")
125+
})
99126
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: v1beta11
2+
name: pullsecrets-upgrade
3+
images:
4+
app:
5+
image: registry1.example.com/username/image1
6+
skip:
7+
image: registry2.example.com/username/image2
8+
build:
9+
disabled: true

pkg/devspace/config/versions/v1beta11/upgrade.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"path"
66
"strings"
77

8+
"github.com/loft-sh/devspace/pkg/devspace/pullsecrets"
9+
810
"github.com/loft-sh/devspace/pkg/util/ptr"
911

1012
"github.com/loft-sh/devspace/pkg/devspace/config/versions/config"
@@ -177,9 +179,10 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
177179
// pull secrets
178180
pullSecrets := []string{}
179181
nextConfig.PullSecrets = map[string]*next.PullSecretConfig{}
182+
pullSecretsByRegistry := map[string]*next.PullSecretConfig{}
180183
for idx, pullSecret := range c.PullSecrets {
181184
pullSecretName := fmt.Sprintf("pull-secret-%d", idx)
182-
nextConfig.PullSecrets[pullSecretName] = &next.PullSecretConfig{
185+
pullSecretConfig := &next.PullSecretConfig{
183186
Name: pullSecretName,
184187
Registry: pullSecret.Registry,
185188
Username: pullSecret.Username,
@@ -188,13 +191,50 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
188191
Secret: pullSecret.Secret,
189192
ServiceAccounts: pullSecret.ServiceAccounts,
190193
}
194+
nextConfig.PullSecrets[pullSecretName] = pullSecretConfig
195+
pullSecretsByRegistry[pullSecret.Registry] = pullSecretConfig
196+
191197
if pullSecret.Disabled {
192198
continue
193199
}
194200

195201
pullSecrets = append(pullSecrets, pullSecretName)
196202
}
197203

204+
// Add pull secrets for images for backwards compatibility
205+
for k, image := range c.Images {
206+
registryURL, err := pullsecrets.GetRegistryFromImageName(image.Image)
207+
if err != nil {
208+
return nil, err
209+
}
210+
211+
if registryURL == "" {
212+
// Skip
213+
continue
214+
}
215+
216+
if image.CreatePullSecret != nil && !*image.CreatePullSecret {
217+
// Disabled
218+
continue
219+
}
220+
221+
if pullSecretsByRegistry[registryURL] != nil {
222+
// Already configured
223+
continue
224+
}
225+
226+
// Create a default pull secret config for images without pull secrets.
227+
pullSecretName := encoding.Convert(k)
228+
pullSecretConfig := &next.PullSecretConfig{
229+
Name: pullSecretName,
230+
Registry: registryURL,
231+
}
232+
nextConfig.PullSecrets[pullSecretName] = pullSecretConfig
233+
pullSecretsByRegistry[registryURL] = pullSecretConfig
234+
235+
pullSecrets = append(pullSecrets, pullSecretName)
236+
}
237+
198238
// use a pretty simple pipeline which was used by DevSpace before
199239
if len(pullSecrets) > 0 {
200240
deployPipeline += fmt.Sprintf("ensure_pull_secrets %s\n", strings.Join(pullSecrets, " "))

pkg/devspace/dependency/util/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
)
88

99
func TestSwitchURLType(t *testing.T) {
10-
httpURL := "https://github.com/loft-sh/devspace.git"
11-
sshURL := "git@github.com:loft-sh/devspace.git"
10+
httpURL := "https://github.com/devspace-sh/devspace.git"
11+
sshURL := "git@github.com:devspace-sh/devspace.git"
1212

1313
assert.Equal(t, sshURL, switchURLType(httpURL))
1414
assert.Equal(t, httpURL, switchURLType(sshURL))

pkg/devspace/server/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
// UIRepository is the repository containing the devspace UI
26-
const UIRepository = "https://github.com/loft-sh/devspace"
26+
const UIRepository = "https://github.com/devspace-sh/devspace"
2727

2828
// UIDownloadBaseURL is the base url where to look for the ui
2929
const UIDownloadBaseURL = UIRepository + "/releases/download"

pkg/devspace/services/inject/inject.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
// DevSpaceHelperRepository is the repository containing the devspace helper
34-
const DevSpaceHelperRepository = "https://github.com/loft-sh/devspace"
34+
const DevSpaceHelperRepository = "https://github.com/devspace-sh/devspace"
3535

3636
// DevSpaceHelperBaseURL is the base url where to look for the sync helper
3737
const DevSpaceHelperBaseURL = DevSpaceHelperRepository + "/releases/download"
@@ -176,7 +176,7 @@ func downloadSyncHelper(ctx context.Context, helperName, syncBinaryFolder, versi
176176
}
177177

178178
// download sha256 html
179-
url := fmt.Sprintf("https://github.com/loft-sh/devspace/releases/download/%s/%s.sha256", version, helperName)
179+
url := fmt.Sprintf("https://github.com/devspace-sh/devspace/releases/download/%s/%s.sha256", version, helperName)
180180
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
181181
if err != nil {
182182
return nil

0 commit comments

Comments
 (0)