Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support chart #196

Merged
merged 31 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e4e4d03
feat: add chart
siyul-park Oct 3, 2024
f5fa475
feat: add links and unlinks
siyul-park Oct 3, 2024
b64e9a0
feat: add link hook
siyul-park Oct 7, 2024
82fa520
feat: add scheme.Kinds
siyul-park Oct 7, 2024
7436d63
docs: add comment
siyul-park Oct 7, 2024
01b7aeb
feat: add store
siyul-park Oct 8, 2024
772ea13
feat: support loader
siyul-park Oct 8, 2024
d5143bf
feat: add linker
siyul-park Oct 8, 2024
4fac10c
feat: add cluster node
siyul-park Oct 8, 2024
4e8c890
refactor: divide build
siyul-park Oct 8, 2024
739ebfe
test: add test case
siyul-park Oct 8, 2024
517b6a9
feat: link runtime
siyul-park Oct 8, 2024
78f6616
feat: support driver
siyul-park Oct 8, 2024
060a60b
feat: link start, apply cmd
siyul-park Oct 8, 2024
f192e7f
feat: link delete and get
siyul-park Oct 8, 2024
af2af58
feat: link get
siyul-park Oct 8, 2024
dde76b3
docs: add document
siyul-park Oct 8, 2024
87b76c9
docs: more readable
siyul-park Oct 8, 2024
7ab3731
fix: support memongo
siyul-park Oct 8, 2024
2d36910
style: make lint
siyul-park Oct 8, 2024
f5e3672
fix: remain native codec
siyul-park Oct 9, 2024
8c1ced2
refactor: more readable
siyul-park Oct 9, 2024
e66b1e5
fix: reuse port in cluster
siyul-park Oct 9, 2024
3eba618
test: add more test case
siyul-park Oct 9, 2024
1e0914e
fix: rollback loaded chart
siyul-park Oct 9, 2024
850802e
docs: add comment
siyul-park Oct 9, 2024
725d259
fix: race condition
siyul-park Oct 9, 2024
9ed9d05
refactor: remove unnessart
siyul-park Oct 9, 2024
5e32f89
refactor: change method name
siyul-park Oct 9, 2024
94de6aa
feat: support link unlink hook
siyul-park Oct 9, 2024
8306bd4
feat: support chart syscall
siyul-park Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Before running commands, configure your system using environment variables. You
|-----------------------|----------------------------|----------------------------|
| `database.url` | `DATABASE.URL` | `mem://` or `mongodb://` |
| `database.name` | `DATABASE.NAME` | - |
| `collection.charts` | `COLLECTION.CHARTS` | `charts` |
| `collection.nodes` | `COLLECTION.NODES` | `nodes` |
| `collection.secrets` | `COLLECTION.SECRETS` | `secrets` |

If using [MongoDB](https://www.mongodb.com/), ensure that [Change Streams](https://www.mongodb.com/docs/manual/changeStreams/) are enabled so that the engine can track changes to node specifications. To utilize Change Streams, set up a [Replica Set](https://www.mongodb.com/docs/manual/replication/#std-label-replication).
If using [MongoDB](https://www.mongodb.com/), ensure that [Change Streams](https://www.mongodb.com/docs/manual/changeStreams/) are enabled so that the engine can track changes to resources. To utilize Change Streams, set up a [Replica Set](https://www.mongodb.com/docs/manual/replication/#std-label-replication).
3 changes: 2 additions & 1 deletion cmd/README_kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
|----------------------|--------------------------|----------------------------|
| `database.url` | `DATABASE.URL` | `mem://` 또는 `mongodb://` |
| `database.name` | `DATABASE.NAME` | - |
| `collection.charts` | `COLLECTION.CHARTS` | `charts` |
| `collection.nodes` | `COLLECTION.NODES` | `nodes` |
| `collection.secrets` | `COLLECTION.SECRETS` | `secrets` |

[MongoDB](https://www.mongodb.com/)를 사용할 경우, 엔진이 노드 명세의 변경을 추적할 수 있도록 [변경 스트림](https://www.mongodb.com/docs/manual/changeStreams/)을 활성화해야 합니다. 변경 스트림을 이용하려면 [복제본 세트](https://www.mongodb.com/ko-kr/docs/manual/replication/#std-label-replication)를 설정하세요.
[MongoDB](https://www.mongodb.com/)를 사용할 경우, 엔진이 리소스의 변경을 추적할 수 있도록 [변경 스트림](https://www.mongodb.com/docs/manual/changeStreams/)을 활성화해야 합니다. 변경 스트림을 이용하려면 [복제본 세트](https://www.mongodb.com/ko-kr/docs/manual/replication/#std-label-replication)를 설정하세요.
57 changes: 47 additions & 10 deletions cmd/pkg/cli/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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/secret"
"github.com/siyul-park/uniflow/pkg/spec"
Expand All @@ -11,6 +12,7 @@

// ApplyConfig represents the configuration for the apply command.
type ApplyConfig struct {
ChartStore chart.Store
SpecStore spec.Store
SecretStore secret.Store
FS afero.Fs
Expand All @@ -22,7 +24,7 @@
Use: "apply",
Short: "Apply resources to the specified namespace",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
ValidArgs: []string{argNodes, argSecrets},
ValidArgs: []string{argCharts, argNodes, argSecrets},
RunE: runApplyCommand(config),
}

Expand Down Expand Up @@ -55,6 +57,42 @@
writer := resource.NewWriter(cmd.OutOrStdout())

switch args[0] {
case argCharts:
var charts []*chart.Chart
if err := reader.Read(&charts); err != nil {
return err

Check warning on line 63 in cmd/pkg/cli/apply.go

View check run for this annotation

Codecov / codecov/patch

cmd/pkg/cli/apply.go#L63

Added line #L63 was not covered by tests
}

for _, scrt := range charts {
if scrt.GetNamespace() == "" {
scrt.SetNamespace(namespace)
}
}

ok, err := config.ChartStore.Load(ctx, charts...)
if err != nil {
return err

Check warning on line 74 in cmd/pkg/cli/apply.go

View check run for this annotation

Codecov / codecov/patch

cmd/pkg/cli/apply.go#L74

Added line #L74 was not covered by tests
}

var inserts []*chart.Chart
var updates []*chart.Chart
for _, chrt := range charts {
if match := resourcebase.Match(chrt, ok...); len(match) > 0 {
chrt.SetID(match[0].GetID())
updates = append(updates, chrt)
} else {
inserts = append(inserts, chrt)
}
}

if _, err := config.ChartStore.Store(ctx, inserts...); err != nil {
return err

Check warning on line 89 in cmd/pkg/cli/apply.go

View check run for this annotation

Codecov / codecov/patch

cmd/pkg/cli/apply.go#L89

Added line #L89 was not covered by tests
}
if _, err := config.ChartStore.Swap(ctx, updates...); err != nil {
return err

Check warning on line 92 in cmd/pkg/cli/apply.go

View check run for this annotation

Codecov / codecov/patch

cmd/pkg/cli/apply.go#L92

Added line #L92 was not covered by tests
}

return writer.Write(charts)
case argNodes:
var specs []spec.Spec
if err := reader.Read(&specs); err != nil {
Expand Down Expand Up @@ -97,9 +135,9 @@
return err
}

for _, sec := range secrets {
if sec.GetNamespace() == "" {
sec.SetNamespace(namespace)
for _, scrt := range secrets {
if scrt.GetNamespace() == "" {
scrt.SetNamespace(namespace)
}
}

Expand All @@ -110,12 +148,12 @@

var inserts []*secret.Secret
var updates []*secret.Secret
for _, sec := range secrets {
if match := resourcebase.Match(sec, ok...); len(match) > 0 {
sec.SetID(match[0].GetID())
updates = append(updates, sec)
for _, scrt := range secrets {
if match := resourcebase.Match(scrt, ok...); len(match) > 0 {
scrt.SetID(match[0].GetID())
updates = append(updates, scrt)
} else {
inserts = append(inserts, sec)
inserts = append(inserts, scrt)
}
}

Expand All @@ -128,7 +166,6 @@

return writer.Write(secrets)
}

return nil
}
}
Loading
Loading