Skip to content

Commit

Permalink
feat: remove chart be simple runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Jan 4, 2025
1 parent 88a5c02 commit 4c3e965
Show file tree
Hide file tree
Showing 46 changed files with 52 additions and 3,135 deletions.
25 changes: 0 additions & 25 deletions cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Settings can be modified using the `.uniflow.toml` file or system environment va
|---------------------|--------------------------|--------------------------|
| `database.url` | `DATABASE_URL` | `mem://` or `mongodb://` |
| `database.name` | `DATABASE_NAME` | - |
| `collection.charts` | `COLLECTION_CHARTS` | `charts` |
| `collection.specs` | `COLLECTION_SPECS` | `specs` |
| `collection.values` | `COLLECTION_VALUES` | `values` |

Expand Down Expand Up @@ -40,12 +39,6 @@ You can specify an initial values file with the `--from-values` flag:
./dist/uniflow start --namespace default --from-values examples/values.yaml
```

Charts can be initialized using the `--from-charts` flag:

```sh
./dist/uniflow start --namespace default --from-charts examples/charts.yaml
```

## Using Uniflowctl

`uniflowctl` is a command used to manage resources within a namespace.
Expand All @@ -64,12 +57,6 @@ To apply values:
./dist/uniflowctl apply values --namespace default --filename examples/values.yaml
```

To apply charts:

```sh
./dist/uniflowctl apply charts --namespace default --filename examples/charts.yaml
```

### Delete Command

The `delete` command removes all resources defined in the specified file. If no namespace is specified, the `default` namespace is used.
Expand All @@ -84,12 +71,6 @@ To delete values:
./dist/uniflowctl delete values --namespace default --filename examples/values.yaml
```

To delete charts:

```sh
./dist/uniflowctl delete charts --namespace default --filename examples/charts.yaml
```

### Get Command

The `get` command retrieves all resources in the specified namespace. If no namespace is specified, the `default` namespace is used.
Expand All @@ -103,9 +84,3 @@ To retrieve values:
```sh
./dist/uniflowctl get values --namespace default
```

To retrieve charts:

```sh
./dist/uniflowctl get charts --namespace default
```
25 changes: 0 additions & 25 deletions cmd/README_kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
|---------------------|---------------------|--------------------------|
| `database.url` | `DATABASE_URL` | `mem://` 또는 `mongodb://` |
| `database.name` | `DATABASE_NAME` | - |
| `collection.charts` | `COLLECTION_CHARTS` | `charts` |
| `collection.specs` | `COLLECTION_SPECS` | `specs` |
| `collection.values` | `COLLECTION_VALUES` | `values` |

Expand Down Expand Up @@ -39,12 +38,6 @@
./dist/uniflow start --namespace default --from-values examples/values.yaml
```

초기 차트 파일은 `--from-charts` 플래그로 제공할 수 있습니다:

```sh
./dist/uniflow start --namespace default --from-charts examples/charts.yaml
```

## Uniflowctl 사용하기

`uniflowctl`는 네임스페이스 내에서 리소스를 관리하는 명령어입니다.
Expand All @@ -63,12 +56,6 @@
./dist/uniflowctl apply values --namespace default --filename examples/values.yaml
```

차트를 적용하려면:

```sh
./dist/uniflowctl apply charts --namespace default --filename examples/charts.yaml
```

### Delete 명령어

`delete` 명령어는 지정된 파일에 정의된 모든 리소스를 삭제합니다. 네임스페이스를 지정하지 않으면 기본적으로 `default` 네임스페이스가 사용됩니다.
Expand All @@ -83,12 +70,6 @@
./dist/uniflowctl delete values --namespace default --filename examples/values.yaml
```

차트를 삭제하려면:

```sh
./dist/uniflowctl delete charts --namespace default --filename examples/charts.yaml
```

### Get 명령어

`get` 명령어는 지정된 네임스페이스 내 모든 리소스를 조회합니다. 네임스페이스가 지정되지 않으면 기본적으로 `default` 네임스페이스가 사용됩니다.
Expand All @@ -102,9 +83,3 @@
```sh
./dist/uniflowctl get values --namespace default
```

차트를 조회하려면:

```sh
./dist/uniflowctl get charts --namespace default
```
5 changes: 1 addition & 4 deletions cmd/pkg/cli/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"github.com/siyul-park/uniflow/cmd/pkg/resource"
"github.com/siyul-park/uniflow/pkg/chart"
resourcebase "github.com/siyul-park/uniflow/pkg/resource"
"github.com/siyul-park/uniflow/pkg/spec"
"github.com/siyul-park/uniflow/pkg/value"
Expand All @@ -14,7 +13,6 @@ import (
type ApplyConfig struct {
SpecStore spec.Store
ValueStore value.Store
ChartStore chart.Store
FS afero.Fs
}

Expand All @@ -24,11 +22,10 @@ func NewApplyCommand(config ApplyConfig) *cobra.Command {
Use: "apply",
Short: "Apply resources to the specified namespace",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
ValidArgs: []string{specs, values, charts},
ValidArgs: []string{specs, values},
RunE: runs(map[string]func(cmd *cobra.Command) error{
specs: runApplyCommand(config.SpecStore, config.FS),
values: runApplyCommand(config.ValueStore, config.FS),
charts: runApplyCommand(config.ChartStore, config.FS),
}),
}

Expand Down
94 changes: 0 additions & 94 deletions cmd/pkg/cli/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"testing"

"github.com/go-faker/faker/v4"
"github.com/gofrs/uuid"
"github.com/siyul-park/uniflow/pkg/chart"
"github.com/siyul-park/uniflow/pkg/spec"
"github.com/siyul-park/uniflow/pkg/value"
"github.com/spf13/afero"
Expand All @@ -19,7 +17,6 @@ import (
func TestApplyCommand_Execute(t *testing.T) {
specStore := spec.NewStore()
valueStore := value.NewStore()
chartStore := chart.NewStore()

fs := afero.NewMemMapFs()

Expand Down Expand Up @@ -51,7 +48,6 @@ func TestApplyCommand_Execute(t *testing.T) {
cmd := NewApplyCommand(ApplyConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})
cmd.SetOut(output)
Expand Down Expand Up @@ -98,7 +94,6 @@ func TestApplyCommand_Execute(t *testing.T) {
cmd := NewApplyCommand(ApplyConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})
cmd.SetOut(output)
Expand Down Expand Up @@ -140,7 +135,6 @@ func TestApplyCommand_Execute(t *testing.T) {
cmd := NewApplyCommand(ApplyConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})
cmd.SetOut(output)
Expand Down Expand Up @@ -185,7 +179,6 @@ func TestApplyCommand_Execute(t *testing.T) {
cmd := NewApplyCommand(ApplyConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})
cmd.SetOut(output)
Expand All @@ -200,91 +193,4 @@ func TestApplyCommand_Execute(t *testing.T) {
assert.Len(t, results, 1)
assert.Contains(t, output.String(), scrt.Name)
})

t.Run("InsertChart", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

filename := "charts.json"

chrt := &chart.Chart{
ID: uuid.Must(uuid.NewV7()),
Name: faker.UUIDHyphenated(),
}

data, err := json.Marshal(chrt)
assert.NoError(t, err)

file, err := fs.Create(filename)
assert.NoError(t, err)
defer file.Close()

_, err = file.Write(data)
assert.NoError(t, err)

output := new(bytes.Buffer)

cmd := NewApplyCommand(ApplyConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})
cmd.SetOut(output)
cmd.SetErr(output)
cmd.SetArgs([]string{charts, fmt.Sprintf("--%s", flagFilename), filename})

err = cmd.Execute()
assert.NoError(t, err)

results, err := chartStore.Load(ctx, chrt)
assert.NoError(t, err)
assert.Len(t, results, 1)
assert.Contains(t, output.String(), chrt.Name)
})

t.Run("UpdateChart", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

filename := "charts.json"

chrt := &chart.Chart{
ID: uuid.Must(uuid.NewV7()),
Name: faker.UUIDHyphenated(),
}

_, err := chartStore.Store(ctx, chrt)
assert.NoError(t, err)

data, err := json.Marshal(chrt)
assert.NoError(t, err)

file, err := fs.Create(filename)
assert.NoError(t, err)
defer file.Close()

_, err = file.Write(data)
assert.NoError(t, err)

output := new(bytes.Buffer)

cmd := NewApplyCommand(ApplyConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})
cmd.SetOut(output)
cmd.SetErr(output)
cmd.SetArgs([]string{charts, fmt.Sprintf("--%s", flagFilename), filename})

err = cmd.Execute()
assert.NoError(t, err)

results, err := chartStore.Load(ctx, chrt)
assert.NoError(t, err)
assert.Len(t, results, 1)
assert.Contains(t, output.String(), chrt.Name)
})
}
1 change: 0 additions & 1 deletion cmd/pkg/cli/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
const (
specs = "specs"
values = "values"
charts = "charts"
)

func runs(runs map[string]func(cmd *cobra.Command) error) func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 1 addition & 4 deletions cmd/pkg/cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"github.com/siyul-park/uniflow/cmd/pkg/resource"
"github.com/siyul-park/uniflow/pkg/chart"
resourcebase "github.com/siyul-park/uniflow/pkg/resource"
"github.com/siyul-park/uniflow/pkg/spec"
"github.com/siyul-park/uniflow/pkg/value"
Expand All @@ -14,7 +13,6 @@ import (
type DeleteConfig struct {
SpecStore spec.Store
ValueStore value.Store
ChartStore chart.Store
FS afero.Fs
}

Expand All @@ -24,11 +22,10 @@ func NewDeleteCommand(config DeleteConfig) *cobra.Command {
Use: "delete",
Short: "Delete resources from the specified namespace",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
ValidArgs: []string{specs, values, charts},
ValidArgs: []string{specs, values},
RunE: runs(map[string]func(cmd *cobra.Command) error{
specs: runDeleteCommand(config.SpecStore, config.FS, spec.New),
values: runDeleteCommand(config.ValueStore, config.FS, value.New),
charts: runDeleteCommand(config.ChartStore, config.FS, chart.New),
}),
}

Expand Down
46 changes: 0 additions & 46 deletions cmd/pkg/cli/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"testing"

"github.com/go-faker/faker/v4"
"github.com/gofrs/uuid"
"github.com/siyul-park/uniflow/pkg/chart"
"github.com/siyul-park/uniflow/pkg/spec"
"github.com/siyul-park/uniflow/pkg/value"
"github.com/spf13/afero"
Expand All @@ -18,7 +16,6 @@ import (
func TestDeleteCommand_Execute(t *testing.T) {
specStore := spec.NewStore()
valueStore := value.NewStore()
chartStore := chart.NewStore()

fs := afero.NewMemMapFs()

Expand Down Expand Up @@ -51,7 +48,6 @@ func TestDeleteCommand_Execute(t *testing.T) {
cmd := NewDeleteCommand(DeleteConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})

Expand Down Expand Up @@ -92,7 +88,6 @@ func TestDeleteCommand_Execute(t *testing.T) {
cmd := NewDeleteCommand(DeleteConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})

Expand All @@ -105,45 +100,4 @@ func TestDeleteCommand_Execute(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, rValue, 0)
})

t.Run("DeleteChart", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

filename := "charts.json"

chrt := &chart.Chart{
ID: uuid.Must(uuid.NewV7()),
Name: faker.UUIDHyphenated(),
}

data, err := json.Marshal(chrt)
assert.NoError(t, err)

file, err := fs.Create(filename)
assert.NoError(t, err)
defer file.Close()

_, err = file.Write(data)
assert.NoError(t, err)

_, err = chartStore.Store(ctx, chrt)
assert.NoError(t, err)

cmd := NewDeleteCommand(DeleteConfig{
SpecStore: specStore,
ValueStore: valueStore,
ChartStore: chartStore,
FS: fs,
})

cmd.SetArgs([]string{charts, fmt.Sprintf("--%s", flagFilename), filename})

err = cmd.Execute()
assert.NoError(t, err)

r, err := chartStore.Load(ctx, chrt)
assert.NoError(t, err)
assert.Len(t, r, 0)
})
}
Loading

0 comments on commit 4c3e965

Please sign in to comment.