Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 678f7c9

Browse files
committed
Add distributed claim store through Kubernetes' secrets
Signed-off-by: Ulysses Souza <[email protected]>
1 parent 6d698be commit 678f7c9

File tree

10 files changed

+276
-43
lines changed

10 files changed

+276
-43
lines changed

internal/commands/inspect.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import (
88

99
"github.com/deislabs/cnab-go/action"
1010
"github.com/deislabs/cnab-go/bundle"
11+
"github.com/docker/cli/cli"
12+
"github.com/docker/cli/cli/command"
13+
"github.com/spf13/cobra"
14+
1115
"github.com/docker/app/internal"
1216
"github.com/docker/app/internal/cliopts"
1317
"github.com/docker/app/internal/cnab"
1418
"github.com/docker/app/internal/inspect"
1519
"github.com/docker/app/internal/packager"
16-
"github.com/docker/cli/cli"
17-
"github.com/docker/cli/cli/command"
18-
"github.com/spf13/cobra"
20+
"github.com/docker/app/internal/store"
1921
)
2022

2123
const inspectExample = `- $ docker app inspect my-running-app
@@ -43,7 +45,11 @@ func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContex
4345
}
4446

4547
func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
46-
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
48+
orchestrator, err := store.GetOrchestrator(dockerCli)
49+
if err != nil {
50+
return err
51+
}
52+
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
4753
if err != nil {
4854
return err
4955
}

internal/commands/list.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/deislabs/cnab-go/action"
13-
"github.com/docker/app/internal"
14-
"github.com/docker/app/internal/cliopts"
15-
"github.com/docker/app/internal/cnab"
16-
"github.com/docker/app/internal/store"
1713
"github.com/docker/cli/cli"
1814
"github.com/docker/cli/cli/command"
1915
"github.com/docker/cli/cli/config"
@@ -22,6 +18,11 @@ import (
2218
"github.com/docker/go/canonical/json"
2319
"github.com/pkg/errors"
2420
"github.com/spf13/cobra"
21+
22+
"github.com/docker/app/internal"
23+
"github.com/docker/app/internal/cliopts"
24+
"github.com/docker/app/internal/cnab"
25+
"github.com/docker/app/internal/store"
2526
)
2627

2728
var (
@@ -71,8 +72,12 @@ func runList(dockerCli command.Cli, opts listOptions, installerContext *cliopts.
7172
if err != nil {
7273
return err
7374
}
75+
orchestrator, err := store.GetOrchestrator(dockerCli)
76+
if err != nil {
77+
return err
78+
}
7479
targetContext := dockerCli.CurrentContext()
75-
installationStore, err := appstore.InstallationStore(targetContext)
80+
installationStore, err := appstore.InstallationStore(targetContext, orchestrator)
7681
if err != nil {
7782
return err
7883
}

internal/commands/remove.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ func removeCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
3434
Example: `$ docker app rm myrunningapp`,
3535
Args: cli.RequiresMinArgs(1),
3636
RunE: func(cmd *cobra.Command, args []string) error {
37-
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
37+
orchestrator, err := store.GetOrchestrator(dockerCli)
38+
if err != nil {
39+
return err
40+
}
41+
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
3842
if err != nil {
3943
return err
4044
}

internal/commands/root.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import (
66
"os"
77

88
"github.com/deislabs/cnab-go/claim"
9+
"github.com/docker/cli/cli/command"
10+
"github.com/docker/cli/cli/config"
11+
"github.com/spf13/cobra"
12+
"github.com/spf13/pflag"
13+
914
"github.com/docker/app/internal"
1015
"github.com/docker/app/internal/cliopts"
1116
"github.com/docker/app/internal/commands/build"
1217
"github.com/docker/app/internal/commands/image"
1318
"github.com/docker/app/internal/store"
1419
appstore "github.com/docker/app/internal/store"
15-
"github.com/docker/cli/cli/command"
16-
"github.com/docker/cli/cli/config"
17-
"github.com/spf13/cobra"
18-
"github.com/spf13/pflag"
1920
)
2021

2122
type mainOptions struct {
@@ -105,12 +106,12 @@ func muteDockerCli(dockerCli command.Cli) func() {
105106
}
106107
}
107108

108-
func prepareStores(targetContext string) (store.ImageStore, store.InstallationStore, store.CredentialStore, error) {
109+
func prepareStores(targetContext string, orchestrator command.Orchestrator) (store.ImageStore, store.InstallationStore, store.CredentialStore, error) {
109110
appstore, err := store.NewApplicationStore(config.Dir())
110111
if err != nil {
111112
return nil, nil, nil, err
112113
}
113-
installationStore, err := appstore.InstallationStore(targetContext)
114+
installationStore, err := appstore.InstallationStore(targetContext, orchestrator)
114115
if err != nil {
115116
return nil, nil, nil, err
116117
}

internal/commands/run.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/docker/app/internal/packager"
8-
9-
"github.com/docker/app/internal/image"
10-
11-
"github.com/deislabs/cnab-go/driver"
12-
"github.com/docker/app/internal/cliopts"
13-
147
"github.com/deislabs/cnab-go/action"
158
"github.com/deislabs/cnab-go/credentials"
16-
bdl "github.com/docker/app/internal/bundle"
17-
"github.com/docker/app/internal/cnab"
18-
"github.com/docker/app/internal/store"
9+
"github.com/deislabs/cnab-go/driver"
1910
"github.com/docker/cli/cli"
2011
"github.com/docker/cli/cli/command"
2112
"github.com/docker/docker/pkg/namesgenerator"
2213
"github.com/pkg/errors"
2314
"github.com/sirupsen/logrus"
2415
"github.com/spf13/cobra"
16+
17+
bdl "github.com/docker/app/internal/bundle"
18+
"github.com/docker/app/internal/cliopts"
19+
"github.com/docker/app/internal/cnab"
20+
"github.com/docker/app/internal/image"
21+
"github.com/docker/app/internal/packager"
22+
"github.com/docker/app/internal/store"
2523
)
2624

2725
type runOptions struct {
@@ -103,7 +101,11 @@ func runBundle(dockerCli command.Cli, bndl *image.AppImage, opts runOptions, ins
103101
if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil {
104102
return err
105103
}
106-
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
104+
orchestrator, err := store.GetOrchestrator(dockerCli)
105+
if err != nil {
106+
return err
107+
}
108+
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
107109
if err != nil {
108110
return err
109111
}

internal/commands/update.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/deislabs/cnab-go/driver"
8-
97
"github.com/deislabs/cnab-go/action"
108
"github.com/deislabs/cnab-go/credentials"
9+
"github.com/deislabs/cnab-go/driver"
10+
"github.com/docker/cli/cli/command"
11+
"github.com/spf13/cobra"
12+
1113
"github.com/docker/app/internal/bundle"
1214
"github.com/docker/app/internal/cliopts"
1315
"github.com/docker/app/internal/cnab"
1416
"github.com/docker/app/internal/packager"
15-
"github.com/docker/cli/cli/command"
16-
"github.com/spf13/cobra"
17+
"github.com/docker/app/internal/store"
1718
)
1819

1920
type updateOptions struct {
@@ -41,7 +42,11 @@ func updateCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4142
}
4243

4344
func runUpdate(dockerCli command.Cli, installationName string, opts updateOptions, installerContext *cliopts.InstallerContextOptions) error {
44-
imageStore, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
45+
orchestrator, err := store.GetOrchestrator(dockerCli)
46+
if err != nil {
47+
return err
48+
}
49+
imageStore, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext(), orchestrator)
4550
if err != nil {
4651
return err
4752
}

internal/store/app.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import (
55
"os"
66
"path/filepath"
77

8-
"github.com/deislabs/cnab-go/utils/crud"
8+
cnabCrud "github.com/deislabs/cnab-go/utils/crud"
9+
"github.com/docker/cli/cli/command"
910
digest "github.com/opencontainers/go-digest"
1011
"github.com/pkg/errors"
12+
13+
appCrud "github.com/docker/app/internal/store/crud"
1114
)
1215

1316
const (
@@ -51,12 +54,28 @@ func NewApplicationStore(configDir string) (*ApplicationStore, error) {
5154
}
5255

5356
// InstallationStore initializes and returns a context based installation store
54-
func (a ApplicationStore) InstallationStore(context string) (InstallationStore, error) {
55-
path := filepath.Join(a.path, InstallationStoreDirectory, makeDigestedDirectory(context))
56-
if err := os.MkdirAll(path, 0755); err != nil {
57-
return nil, errors.Wrapf(err, "failed to create installation store directory for context %q", context)
57+
func (a ApplicationStore) InstallationStore(context string, orchestrator command.Orchestrator) (InstallationStore, error) {
58+
switch {
59+
// FIXME What if orchestrator.HasKubernetes() and still want to use local store?
60+
case orchestrator.HasKubernetes():
61+
// FIXME Get this namespace, labelKey and labelValue dynamically through cli opts
62+
k8sStore, err := appCrud.NewKubernetesSecretsStore(
63+
appCrud.DefaultKubernetesNamespace,
64+
appCrud.LabelKV{
65+
appCrud.DefaultSecretLabelKey,
66+
appCrud.DefaultSecretLabelValue,
67+
})
68+
if err != nil {
69+
return nil, err
70+
}
71+
return &installationStore{store: k8sStore}, nil
72+
default:
73+
path := filepath.Join(a.path, InstallationStoreDirectory, makeDigestedDirectory(context))
74+
if err := os.MkdirAll(path, 0755); err != nil {
75+
return nil, errors.Wrapf(err, "failed to create installation store directory for context %q", context)
76+
}
77+
return &installationStore{store: cnabCrud.NewFileSystemStore(path, "json")}, nil
5878
}
59-
return &installationStore{store: crud.NewFileSystemStore(path, "json")}, nil
6079
}
6180

6281
// CredentialStore initializes and returns a context based credential store

0 commit comments

Comments
 (0)