From e306d63dd1cef70fc66b2501c3b5596cbe567909 Mon Sep 17 00:00:00 2001 From: Ahmed AbouZaid <6760103+aabouzaid@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:06:09 +0200 Subject: [PATCH] docs: add examples for config embedded and external files (#1432) --- docs/usage/configfile.md | 13 ++++++ pkg/config/config_test.go | 13 +++--- .../test_assets/config_test_simple.yaml | 44 +++++++++---------- .../test_assets/{baz-ns.yaml => ns-baz.yaml} | 0 4 files changed, 42 insertions(+), 28 deletions(-) rename pkg/config/test_assets/{baz-ns.yaml => ns-baz.yaml} (100%) diff --git a/docs/usage/configfile.md b/docs/usage/configfile.md index 1c689305..1fa450d7 100644 --- a/docs/usage/configfile.md +++ b/docs/usage/configfile.md @@ -77,6 +77,19 @@ env: - envVar: bar=baz # same as `--env 'bar=baz@server:0'` nodeFilters: - server:0 +files: + - description: 'Source: Embedded, Destination: Magic shortcut path' + source: | + apiVersion: v1 + kind: Namespace + metadata: + name: foo + destination: k3s-manifests-custom/foo.yaml # Resolved to /var/lib/rancher/k3s/server/manifests/custom/foo.yaml + - description: 'Source: Relative, Destination: Absolute path, Node: Servers only' + source: ns-baz.yaml + destination: /var/lib/rancher/k3s/server/manifests/baz.yaml + nodeFilters: + - "server:*" registries: # define how registries should be created or used create: # creates a default registry to be used with the cluster; same as `--registry-create registry.localhost` name: registry.localhost diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 9f2687b3..3f387fcf 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -73,6 +73,7 @@ func TestReadSimpleConfig(t *testing.T) { }, Files: []conf.FileWithNodeFilters{ { + Description: "Source: Embedded, Destination: Absolute path", Source: "apiVersion: v1\n" + "kind: Namespace\n" + "metadata:\n" + @@ -80,23 +81,23 @@ func TestReadSimpleConfig(t *testing.T) { Destination: "/var/lib/rancher/k3s/server/manifests/foo.yaml", }, { + Description: "Source: Embedded, Destination: Magic shortcut path", Source: "apiVersion: v1\n" + "kind: Namespace\n" + "metadata:\n" + " name: bar\n", Destination: "k3s-manifests/bar.yaml", - Description: "Source: Embedded content in k3d config file, Destination: Magic shortcut path, Description: Defined", }, { - Source: "baz-ns.yaml", + Description: "Source: Relative, Destination: Magic shortcut path", + Source: "ns-baz.yaml", Destination: "k3s-manifests-custom/baz.yaml", - Description: "Source: Relative path to k3d config file, Destination: Magic shortcut path, Description: Defined", }, { - Source: "baz-ns.yaml", - Destination: "k3s-manifests-custom/baz-server.yaml", + Description: "Source: Relative, Destination: Magic shortcut path, Node: Servers only", + Source: "ns-baz.yaml", + Destination: "k3s-manifests/baz.yaml", NodeFilters: []string{"server:*"}, - Description: "Source: Relative path to k3d config file, Destination: Magic shortcut path, Node: Defined, Description: Defined", }, }, Options: conf.SimpleConfigOptions{ diff --git a/pkg/config/test_assets/config_test_simple.yaml b/pkg/config/test_assets/config_test_simple.yaml index 3dd1cb88..53139b49 100644 --- a/pkg/config/test_assets/config_test_simple.yaml +++ b/pkg/config/test_assets/config_test_simple.yaml @@ -24,28 +24,28 @@ env: nodeFilters: - all files: - - source: | - apiVersion: v1 - kind: Namespace - metadata: - name: foo - destination: /var/lib/rancher/k3s/server/manifests/foo.yaml - # destination: "Source: Embedded content in k3d config file, Destination: Absolute path, Description: Not defined" - - source: | - apiVersion: v1 - kind: Namespace - metadata: - name: bar - destination: k3s-manifests/bar.yaml # Resolved to /var/lib/rancher/k3s/server/manifests/bar.yaml - description: 'Source: Embedded content in k3d config file, Destination: Magic shortcut path, Description: Defined' - - source: baz-ns.yaml - destination: k3s-manifests-custom/baz.yaml # Resolved to /var/lib/rancher/k3s/server/manifests/custom/bar.yaml - description: 'Source: Relative path to k3d config file, Destination: Magic shortcut path, Description: Defined' - - source: baz-ns.yaml - destination: k3s-manifests-custom/baz-server.yaml # Resolved to /var/lib/rancher/k3s/server/manifests/custom/bar-server.yaml - nodeFilters: - - "server:*" - description: 'Source: Relative path to k3d config file, Destination: Magic shortcut path, Node: Defined, Description: Defined' + - description: 'Source: Embedded, Destination: Absolute path' + source: | + apiVersion: v1 + kind: Namespace + metadata: + name: foo + destination: /var/lib/rancher/k3s/server/manifests/foo.yaml + - description: 'Source: Embedded, Destination: Magic shortcut path' + source: | + apiVersion: v1 + kind: Namespace + metadata: + name: bar + destination: k3s-manifests/bar.yaml # Resolved to /var/lib/rancher/k3s/server/manifests/bar.yaml + - description: 'Source: Relative, Destination: Magic shortcut path' + source: ns-baz.yaml + destination: k3s-manifests-custom/baz.yaml # Resolved to /var/lib/rancher/k3s/server/manifests/custom/baz.yaml + - description: 'Source: Relative, Destination: Magic shortcut path, Node: Servers only' + source: ns-baz.yaml + destination: k3s-manifests/baz.yaml # Resolved to /var/lib/rancher/k3s/server/manifests/baz.yaml + nodeFilters: + - "server:*" options: k3d: diff --git a/pkg/config/test_assets/baz-ns.yaml b/pkg/config/test_assets/ns-baz.yaml similarity index 100% rename from pkg/config/test_assets/baz-ns.yaml rename to pkg/config/test_assets/ns-baz.yaml