Skip to content

Commit 82793bc

Browse files
committed
resolve comments
1 parent 2ca5725 commit 82793bc

File tree

1 file changed

+65
-18
lines changed

1 file changed

+65
-18
lines changed

docs/design-docs/01-kpt-live-stdin.md

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,25 @@ to use ResourceGroup only.
2828

2929
### Read standard input resources
3030

31-
We will add a reserved keyword “-” as a special kpt directory. This "-" accepts resources
32-
from the standard input. For example, `kustomize build | kpt live apply -`
31+
We will change the existing `kpt live apply` from STDIN to not require the existence of Kptfile (
32+
to be more specific, the `inventory` file from Kptfile). As long as the STDIN contains
33+
one and only one valid ResourceGroup, `kpt live apply` should be able to create/match the
34+
ResourceGroup in cluster.
3335

3436
### Initialize a `ResourceGroup` object
3537

36-
`kpt live init` will create a ResourceGroup CR in resourcegroup.yaml. Only three fields
37-
should be given to the CR.
38+
`kpt live init` will create a ResourceGroup CR in resourcegroup.yaml.
39+
40+
By default, the ResoureGroup will have name and namespace assigned as below. And users can
41+
override via existing flags "--name" and "--namespace".
3842

3943
- metadata.name: A client-provided valid RFC 1123 DNS subdomain name. Default value has prefix “inventory-” with
40-
8 digit numbers. E.g. “inventory-02014045”
41-
- metadata.namespace: a valid namespace. default to value “default”
42-
- metadata.labels.cli-utils.sigs.k8s.io/inventory-id: A client-provided valid label.
43-
Default value is a UUID e.g. 7c5af957-a3e2-4d68-8c0f-6c1864a66050
44+
8 digit numbers. E.g. "inventory-02014045"
45+
- metadata.namespace: a valid namespace. default to value "default"
46+
47+
If users want to reuse an existing inventory (from Kptfile) or ResourceGroup (which has been deployed to the cluster),
48+
they shall provide the value of the inventory's inventory-id or the ResourceGroup's "metadata.labels[0].cli-utils.sigs.k8s.io/inventory-id"
49+
via "--inventory-id" flag.
4450

4551
### Convert Inventory to ResourceGroup
4652

@@ -50,12 +56,12 @@ the ResourceGroup is unique. This requires Kptfile to exist to use `kpt live app
5056

5157
To split the Inventory from Kptfile to resourcegroup.yaml and convert the Inventory to
5258
ResourceGroup, `kpt live migrate` should be extended to map the inventory.name,
53-
inventory.namespace, inventory.inventoryID to ResourceGroup CR metadata.name,
59+
inventory.namespace, inventory.inventoryID to ResourceGroup CR metadata.name,
5460
metadata.namespace, metadata.labels.cli-utils.sigs.k8s.io/inventory-id correspondingly.
5561

5662
Inventory in Kptfile
5763
```yaml
58-
apiVersion: kpt.dev/v1betaX
64+
apiVersion: kpt.dev/v1
5965
kind: Kptfile
6066
inventory:
6167
name: <INVENTORY_NAME>
@@ -73,33 +79,74 @@ metadata
7379
cli-utils.sigs.k8s.io/inventory-id: <INVENTORY_ID>
7480
```
7581
82+
### Simplify the Inventory
83+
84+
Current inventory contains inventory-id which is required to match the label `cli-utils.sigs.k8s.io/inventory-id`.
85+
86+
For new users, they should no longer need to be exposed to the inventory-id, but kpt will
87+
build one composed by `name-namespace` on the fly.
88+
89+
For existing users, the inventory-id is still
90+
required in the standalone ResourceGroup file to guarantee the adoption matches, unless they use "--inventory-policy=adopt"
91+
to override the label. This flag is only required as a one-off via `kpt live apply -` to override the label to `name-namespace`.
92+
7693
### ResourceGroup as a singleton object
7794

78-
`kpt live apply [--resourcegroup-path] -` from STDIN accepts and only accepts a single
95+
`kpt live apply [--resourcegroup-file] -` from STDIN accepts and only accepts a single
7996
ResourceGroup, including the ResourceGroup provided by the flag. It detects
8097
1. If more than one ResourceGroup is found, raise errors and display all the ResourceGroup objects.
8198
2. If no ResourceGroup is found in STDIN and and Kptfile inventory does not exists, raise errors and suggest users to
8299
run kpt live init
83100
3. If no ResourceGroup is found in STDIN and Kptfile inventory exists, raise errors and
84101
suggest users to run kpt live migrate
85102

103+
### New flags
104+
105+
#### `--resourcegroup-file`
106+
107+
- description: The file path to the ResourceGroup CR, default to `resourcegroup.yaml`
108+
- short form `--rg`
109+
- This flag will be added to `kpt live init`, `kpt live migrate` and `kpt live apply`
110+
111+
#### `--name` for invectory
112+
113+
- description: The name for the ResourceGroup
114+
- This flag will continue to be used by `kpt live init`. Rather than overriding the
115+
inventory.name in Kptfile, it will override the default metadata.name in the standalone ResourceGroup file.
116+
117+
#### `--namespace` for invectory
118+
119+
- description: The namespace for the ResourceGroup
120+
- This flag will continue to be used by `kpt live init`, Rather than overriding the
121+
inventory.namespace in Kptfile, it will override the default metadata.namespace in the standalone ResourceGroup file.
122+
123+
#### `--inventory-id` for invectory
124+
125+
- description: Inventory identifier. This is used to detect overlap between
126+
two sets of ResourceGroup managed resources that might use the same name and namespace.
127+
- This flag will continue to be accepted by `kpt live init` for backward compatibility reasons.
128+
If given, ResourceGroup will store the inventory-id value in "metadata.labels[0].cli-utils.sigs.k8s.io/inventory-id"
129+
of the ResourceGroup.
130+
If not given, the ResourceGroup labels will be empty and the value of "<name>-<namespace>" will be
131+
used as the "cli-utils.sigs.k8s.io/inventory-id" label in `kpt live apply` from STD.
132+
86133
## User Guide
87134

88135
### To hydrate via kustomize and deploy via kpt
89136

90137
#### Day 1
91138

92-
<b>For new users to start from scratch (no Kptfile)</b>
139+
##### For new users to start from scratch (no Kptfile)
93140
User can run `kpt live init [--resourcegroup-file=CUSTOM_RG.yaml]` to create a
94141
ResourceGroup object and store it in a resourcegroup.yaml file.
95142
Users can customize the file path with the flag “--resourcegroup-file”.
96143

97-
<b>For existing kpt users to migrate from Kptfile</b>
144+
##### For existing kpt users to migrate from Kptfile
98145
Users run `kpt live migrate [--resourcegroup-file=CUSTOM_RG.yaml]` to convert the
99146
Inventory object from Kptfile to a standalone resourcegroup.yaml file.
100147
Users can customize the file path with the flag “--resourcegroup-file”.
101148

102-
<b>[optional]: Add shareable ResourceGroup to kustomize resources</b>
149+
##### [optional]: Add shareable ResourceGroup to kustomize resources
103150
If the ResourceGroup is expected to be shared in the Gitops workflow, users can add
104151
the resourcegroup.yaml file path to the .resources field in kustomization.yaml.
105152
This simplifies the Day N deployment by omitting the “–resourcegroup-file“ flag.
@@ -116,11 +163,11 @@ This simplifies the Day N deployment by omitting the “–resourcegroup-file“
116163

117164
#### Day 1
118165

119-
<b>For new users to start from scratch (no Kptfile)</b>
166+
##### For new users to start from scratch (no Kptfile)
120167
User can run `kpt live init --resourcegroup-file=<DIR>/resourcegroup.yaml` to create
121168
a ResourceGroup object and store it in the helm template <DIR>.
122169

123-
<b>For existing kpt users to migrate from Kptfile</b>
170+
##### For existing kpt users to migrate from Kptfile
124171
Users run `kpt live migrate --resourcegroup-file=<DIR>/resourcegroup.yaml` to convert
125172
the Inventory object from Kptfile to a standalone resourcegroup.yaml file.
126173

@@ -180,7 +227,7 @@ the ResourceGroup unintentionally (e.g. via kubectl apply).
180227

181228
inventory.yaml
182229
```yaml
183-
apiVersion: kpt.dev/v1betaX
230+
apiVersion: kpt.dev/v1
184231
kind: Inventory
185232
metadata:
186233
name: <INVENTORY_NAME>
@@ -205,7 +252,7 @@ inventoryID: <INVENTORY_ID>
205252

206253
inventory.yaml
207254
```yaml
208-
apiVersion: kpt.dev/v1betaX
255+
apiVersion: kpt.dev/v1
209256
kind: Inventory
210257
spec:
211258
resourceGroup:

0 commit comments

Comments
 (0)