|
1 | 1 | package pullsecret |
2 | 2 |
|
3 | | -import "github.com/onsi/ginkgo" |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/base64" |
| 6 | + "github.com/loft-sh/devspace/cmd" |
| 7 | + "github.com/loft-sh/devspace/cmd/flags" |
| 8 | + "github.com/loft-sh/devspace/e2e/framework" |
| 9 | + "github.com/loft-sh/devspace/e2e/kube" |
| 10 | + "github.com/loft-sh/devspace/pkg/util/factory" |
| 11 | + "github.com/onsi/ginkgo" |
| 12 | + k8sv1 "k8s.io/api/core/v1" |
| 13 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 14 | + "os" |
| 15 | + "sort" |
| 16 | +) |
4 | 17 |
|
5 | 18 | var _ = DevSpaceDescribe("pullsecret", func() { |
6 | | - ginkgo.It("should create pullsecret with user & password", func() { |
7 | | - // TODO |
8 | | - }) |
| 19 | + initialDir, err := os.Getwd() |
| 20 | + if err != nil { |
| 21 | + panic(err) |
| 22 | + } |
| 23 | + |
| 24 | + // create a new factory |
| 25 | + var ( |
| 26 | + f factory.Factory |
| 27 | + kubeClient *kube.KubeHelper |
| 28 | + ) |
9 | 29 |
|
10 | | - ginkgo.It("should add pull secret to service account", func() { |
11 | | - // TODO |
| 30 | + ginkgo.BeforeEach(func() { |
| 31 | + f = framework.NewDefaultFactory() |
| 32 | + |
| 33 | + kubeClient, err = kube.NewKubeHelper() |
| 34 | + framework.ExpectNoError(err) |
12 | 35 | }) |
13 | 36 |
|
14 | | - ginkgo.It("should create pullsecret from dockercache", func() { |
15 | | - // TODO |
| 37 | + ginkgo.It("should create pullsecret with user & password", func() { |
| 38 | + tempDir, err := framework.CopyToTempDir("tests/pullsecret/testdata/simple") |
| 39 | + framework.ExpectNoError(err) |
| 40 | + defer framework.CleanupTempDir(initialDir, tempDir) |
| 41 | + |
| 42 | + ns, err := kubeClient.CreateNamespace("pullsecret") |
| 43 | + framework.ExpectNoError(err) |
| 44 | + defer func() { |
| 45 | + err := kubeClient.DeleteNamespace(ns) |
| 46 | + framework.ExpectNoError(err) |
| 47 | + }() |
| 48 | + |
| 49 | + // create a new dev command |
| 50 | + deployCmd := &cmd.DeployCmd{ |
| 51 | + GlobalFlags: &flags.GlobalFlags{ |
| 52 | + NoWarn: true, |
| 53 | + Namespace: ns, |
| 54 | + }, |
| 55 | + } |
| 56 | + |
| 57 | + // run the command |
| 58 | + err = deployCmd.Run(f) |
| 59 | + framework.ExpectNoError(err) |
| 60 | + |
| 61 | + // check if secrets are created |
| 62 | + pullSecret, err := kubeClient.RawClient().CoreV1().Secrets(ns).Get(context.TODO(), "test-secret", metav1.GetOptions{}) |
| 63 | + framework.ExpectNoError(err) |
| 64 | + framework.ExpectEqual(len(pullSecret.Data), 1) |
| 65 | + registryAuthEncoded := base64.StdEncoding.EncodeToString([]byte("my-user:my-password")) |
| 66 | + pullSecretDataValue := []byte(`{ |
| 67 | + "auths": { |
| 68 | + "ghcr.io": { |
| 69 | + "auth": "` + registryAuthEncoded + `", |
| 70 | + "email": "noreply@devspace.sh" |
| 71 | + } |
| 72 | + } |
| 73 | + }`) |
| 74 | + framework.ExpectEqual(string(pullSecret.Data[k8sv1.DockerConfigJsonKey]), string(pullSecretDataValue)) |
| 75 | + |
| 76 | + pullSecret, err = kubeClient.RawClient().CoreV1().Secrets(ns).Get(context.TODO(), "devspace-auth-ghcr2-io", metav1.GetOptions{}) |
| 77 | + framework.ExpectNoError(err) |
| 78 | + framework.ExpectEqual(len(pullSecret.Data), 1) |
| 79 | + registryAuthEncoded = base64.StdEncoding.EncodeToString([]byte("my-user2:my-password2")) |
| 80 | + pullSecretDataValue = []byte(`{ |
| 81 | + "auths": { |
| 82 | + "ghcr2.io": { |
| 83 | + "auth": "` + registryAuthEncoded + `", |
| 84 | + "email": "noreply@devspace.sh" |
| 85 | + } |
| 86 | + } |
| 87 | + }`) |
| 88 | + framework.ExpectEqual(string(pullSecret.Data[k8sv1.DockerConfigJsonKey]), string(pullSecretDataValue)) |
| 89 | + |
| 90 | + serviceAccount, err := kubeClient.RawClient().CoreV1().ServiceAccounts(ns).Get(context.TODO(), "default", metav1.GetOptions{}) |
| 91 | + framework.ExpectNoError(err) |
| 92 | + framework.ExpectEqual(len(serviceAccount.ImagePullSecrets), 2) |
| 93 | + sort.Slice(serviceAccount.ImagePullSecrets, func(i, j int) bool { |
| 94 | + return serviceAccount.ImagePullSecrets[i].Name < serviceAccount.ImagePullSecrets[j].Name |
| 95 | + }) |
| 96 | + framework.ExpectEqual(serviceAccount.ImagePullSecrets[0].Name, "devspace-auth-ghcr2-io") |
| 97 | + framework.ExpectEqual(serviceAccount.ImagePullSecrets[1].Name, "test-secret") |
16 | 98 | }) |
17 | 99 | }) |
0 commit comments