From 6ef1b36d9233f4d00f0fc025c05bed6a0f84f901 Mon Sep 17 00:00:00 2001 From: Gabriele Santomaggio Date: Mon, 2 Nov 2020 13:54:42 +0100 Subject: [PATCH] Add inline plugins for the groups (#52) * Add inline plugin So we can mix existing groups with inline definition * Rebased --- cmd/tools/cli/apply.go | 8 ++++++++ cmd/tools/cli/delete.go | 7 +++++++ cmd/tools/cli/integration_test.go | 4 ++-- internal/plugins/groups.go | 7 ++++--- internal/plugins/groups_test.go | 2 +- internal/plugins/remote_contents_test.go | 2 +- local_repo/core/groups/argo-workflow/group.yaml | 11 +++++++++++ local_repo/core/groups/argo/group.yaml | 5 ----- 8 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 local_repo/core/groups/argo-workflow/group.yaml delete mode 100644 local_repo/core/groups/argo/group.yaml diff --git a/cmd/tools/cli/apply.go b/cmd/tools/cli/apply.go index fe5105e..b693556 100644 --- a/cmd/tools/cli/apply.go +++ b/cmd/tools/cli/apply.go @@ -42,6 +42,14 @@ func applyGroup(config kctl.Config, groupName string) error { } } } + + for _, inlinePlugin := range group.InlinePlugins { + err = kctl.Apply(config, inlinePlugin, nil) + if err != nil { + return err + } + } + } return nil diff --git a/cmd/tools/cli/delete.go b/cmd/tools/cli/delete.go index 059ed06..1accb02 100644 --- a/cmd/tools/cli/delete.go +++ b/cmd/tools/cli/delete.go @@ -43,6 +43,13 @@ func deleteGroup(config kctl.Config, groupName string) error { } } } + + for _, inlinePlugin := range group.InlinePlugins { + err = kctl.Delete(config, inlinePlugin) + if err != nil { + return err + } + } } return nil } diff --git a/cmd/tools/cli/integration_test.go b/cmd/tools/cli/integration_test.go index c9bf82c..1ab1d4a 100644 --- a/cmd/tools/cli/integration_test.go +++ b/cmd/tools/cli/integration_test.go @@ -67,7 +67,7 @@ func TestLocalDelete(t *testing.T) { func TestLocalGroupApply(t *testing.T) { cmd, out := setUp() - cmd.SetArgs([]string{"apply", "-g", "argo", "--kubectl", "--group-repo", joinWithRootData("groups")}) + cmd.SetArgs([]string{"apply", "-g", "argo-workflow", "--kubectl", "--group-repo", joinWithRootData("groups")}) if err := cmd.Execute(); err != nil { t.Fatalf("unexpected error %v", err) } @@ -76,7 +76,7 @@ func TestLocalGroupApply(t *testing.T) { func TestLocalGroupDelete(t *testing.T) { cmd, out := setUp() - cmd.SetArgs([]string{"delete", "-g", "argo", "--kubectl", "--group-repo", joinWithRootData("groups")}) + cmd.SetArgs([]string{"delete", "-g", "argo-workflow", "--kubectl", "--group-repo", joinWithRootData("groups")}) if err := cmd.Execute(); err != nil { t.Fatalf("unexpected error %v", err) } diff --git a/internal/plugins/groups.go b/internal/plugins/groups.go index 0800b3e..4e07bd3 100644 --- a/internal/plugins/groups.go +++ b/internal/plugins/groups.go @@ -14,9 +14,10 @@ type PluginGroup struct { //Group is the specification of each k3ai plugins group type Group struct { - PluginType string `yaml:"plugin-type"` - GroupName string `yaml:"group-name"` - Plugins []PluginGroup `yaml:"plugins,flow"` + PluginType string `yaml:"plugin-type"` + GroupName string `yaml:"group-name"` + Plugins []PluginGroup `yaml:"plugins,flow"` + InlinePlugins []Plugin `yaml:"inline-plugins,flow"` } //Groups is the specification of each k3ai plugins group diff --git a/internal/plugins/groups_test.go b/internal/plugins/groups_test.go index 2e8e94e..d2e61a9 100644 --- a/internal/plugins/groups_test.go +++ b/internal/plugins/groups_test.go @@ -7,7 +7,7 @@ import ( func TestValidatePluginsGroupSpec(t *testing.T) { var group Group - testPluginsGroupsSpec, err := group.Encode(joinWithRootData("groups/argo/group.yaml")) + testPluginsGroupsSpec, err := group.Encode(joinWithRootData("groups/argo-workflow/group.yaml")) if err != nil { t.Fatalf("failed to unmarshal test file: %s", err) diff --git a/internal/plugins/remote_contents_test.go b/internal/plugins/remote_contents_test.go index 83310ea..15c573b 100644 --- a/internal/plugins/remote_contents_test.go +++ b/internal/plugins/remote_contents_test.go @@ -55,7 +55,7 @@ func TestPluginYamls(t *testing.T) { } func TestGroupsYamls(t *testing.T) { - var server = mockPluginsServer(t, joinWithRootData("groups/argo/group.yaml"), GroupType) + var server = mockPluginsServer(t, joinWithRootData("groups/argo-workflow/group.yaml"), GroupType) defer server.Close() var groups Groups r, err := groups.Encode(server.URL, "/test") diff --git a/local_repo/core/groups/argo-workflow/group.yaml b/local_repo/core/groups/argo-workflow/group.yaml new file mode 100644 index 0000000..f74feb8 --- /dev/null +++ b/local_repo/core/groups/argo-workflow/group.yaml @@ -0,0 +1,11 @@ +plugin-type: group +group-name: argo-workflow +plugins: + - name: test + enabled: false + - name: argo-workflow + enabled: true +inline-plugins: + - plugin-name: Argo-bind-traefik + yaml: + - url: "https://raw.githubusercontent.com/kf5i/k3ai-plugins/main/common/traefik/argo-bind.yaml" \ No newline at end of file diff --git a/local_repo/core/groups/argo/group.yaml b/local_repo/core/groups/argo/group.yaml deleted file mode 100644 index ba9d0fd..0000000 --- a/local_repo/core/groups/argo/group.yaml +++ /dev/null @@ -1,5 +0,0 @@ -plugin-type: group -group-name: only-argo -plugins: - - name: argo - enabled: true