Skip to content

Commit

Permalink
Merge pull request #2512 from lizardruss/pull-secrets-upgrade
Browse files Browse the repository at this point in the history
fix: add pull secret config for images during v5->v6 schema upgrade
  • Loading branch information
lizardruss authored Jan 27, 2023
2 parents 94cde72 + 25edaa3 commit f26b041
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
27 changes: 27 additions & 0 deletions e2e/tests/pullsecret/pullsecrets.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package pullsecret

import (
"bytes"
"context"
"encoding/base64"
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
"github.com/onsi/ginkgo/v2"
"gopkg.in/yaml.v3"
"os"
"sort"

Expand Down Expand Up @@ -96,4 +99,28 @@ var _ = DevSpaceDescribe("pullsecret", func() {
framework.ExpectEqual(serviceAccount.ImagePullSecrets[1].Name, "merged-secret")
framework.ExpectEqual(serviceAccount.ImagePullSecrets[2].Name, "test-secret")
})

ginkgo.It("should create pullsecrets for v1beta11 images", func() {
tempDir, err := framework.CopyToTempDir("tests/pullsecret/testdata/v1-upgrade")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

// create a new print command
configBuffer := &bytes.Buffer{}
printCmd := &cmd.PrintCmd{
GlobalFlags: &flags.GlobalFlags{},
Out: configBuffer,
SkipInfo: true,
}

err = printCmd.Run(f)
framework.ExpectNoError(err)

latestConfig := &latest.Config{}
err = yaml.Unmarshal(configBuffer.Bytes(), latestConfig)
framework.ExpectNoError(err)
framework.ExpectEqual(len(latestConfig.PullSecrets), 2)
framework.ExpectEqual(latestConfig.PullSecrets["app"].Registry, "registry1.example.com")
framework.ExpectEqual(latestConfig.PullSecrets["skip"].Registry, "registry2.example.com")
})
})
9 changes: 9 additions & 0 deletions e2e/tests/pullsecret/testdata/v1-upgrade/devspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v1beta11
name: pullsecrets-upgrade
images:
app:
image: registry1.example.com/username/image1
skip:
image: registry2.example.com/username/image2
build:
disabled: true
42 changes: 41 additions & 1 deletion pkg/devspace/config/versions/v1beta11/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path"
"strings"

"github.com/loft-sh/devspace/pkg/devspace/pullsecrets"

"github.com/loft-sh/devspace/pkg/util/ptr"

"github.com/loft-sh/devspace/pkg/devspace/config/versions/config"
Expand Down Expand Up @@ -177,9 +179,10 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
// pull secrets
pullSecrets := []string{}
nextConfig.PullSecrets = map[string]*next.PullSecretConfig{}
pullSecretsByRegistry := map[string]*next.PullSecretConfig{}
for idx, pullSecret := range c.PullSecrets {
pullSecretName := fmt.Sprintf("pull-secret-%d", idx)
nextConfig.PullSecrets[pullSecretName] = &next.PullSecretConfig{
pullSecretConfig := &next.PullSecretConfig{
Name: pullSecretName,
Registry: pullSecret.Registry,
Username: pullSecret.Username,
Expand All @@ -188,13 +191,50 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
Secret: pullSecret.Secret,
ServiceAccounts: pullSecret.ServiceAccounts,
}
nextConfig.PullSecrets[pullSecretName] = pullSecretConfig
pullSecretsByRegistry[pullSecret.Registry] = pullSecretConfig

if pullSecret.Disabled {
continue
}

pullSecrets = append(pullSecrets, pullSecretName)
}

// Add pull secrets for images for backwards compatibility
for k, image := range c.Images {
registryURL, err := pullsecrets.GetRegistryFromImageName(image.Image)
if err != nil {
return nil, err
}

if registryURL == "" {
// Skip
continue
}

if image.CreatePullSecret != nil && !*image.CreatePullSecret {
// Disabled
continue
}

if pullSecretsByRegistry[registryURL] != nil {
// Already configured
continue
}

// Create a default pull secret config for images without pull secrets.
pullSecretName := encoding.Convert(k)
pullSecretConfig := &next.PullSecretConfig{
Name: pullSecretName,
Registry: registryURL,
}
nextConfig.PullSecrets[pullSecretName] = pullSecretConfig
pullSecretsByRegistry[registryURL] = pullSecretConfig

pullSecrets = append(pullSecrets, pullSecretName)
}

// use a pretty simple pipeline which was used by DevSpace before
if len(pullSecrets) > 0 {
deployPipeline += fmt.Sprintf("ensure_pull_secrets %s\n", strings.Join(pullSecrets, " "))
Expand Down
4 changes: 2 additions & 2 deletions pkg/devspace/dependency/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

func TestSwitchURLType(t *testing.T) {
httpURL := "https://github.com/loft-sh/devspace.git"
sshURL := "[email protected]:loft-sh/devspace.git"
httpURL := "https://github.com/devspace-sh/devspace.git"
sshURL := "[email protected]:devspace-sh/devspace.git"

assert.Equal(t, sshURL, switchURLType(httpURL))
assert.Equal(t, httpURL, switchURLType(sshURL))
Expand Down
2 changes: 1 addition & 1 deletion pkg/devspace/server/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

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

// UIDownloadBaseURL is the base url where to look for the ui
const UIDownloadBaseURL = UIRepository + "/releases/download"
Expand Down
4 changes: 2 additions & 2 deletions pkg/devspace/services/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

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

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

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

0 comments on commit f26b041

Please sign in to comment.