File: create-setter.md

package info (click to toggle)
golang-k8s-sigs-kustomize-cmd-config 0.20.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 996 kB
  • sloc: makefile: 198; sh: 50
file content (93 lines) | stat: -rw-r--r-- 2,499 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
## create-setter

[Alpha] Create a custom setter for a Resource field

### Synopsis

Create a custom setter for a Resource field by inlining OpenAPI as comments.

  DIR

    A directory containing Resource configuration.

  NAME

    The name of the setter to create.

  VALUE

    The current value of the field, or a substring within the field.

### Creating a Custom Setter

**Given the YAML:**

    # resource.yaml
    apiVersion: v1
    kind: Service
    metadata:
      ...
    spec:
      ...
      ports:
        ...
      - name: http
        port: 8080
        ...

**Create a new setter:**

    # create a setter for ports
    $ kustomize cfg set create DIR/ http-port 8080 --type "integer" --field "port"

  Resources fields with a field name matching `--field` and field value matching `VALUE` will
  have a line comment added marking this field as settable.

**Newly modified YAML:**

    # resource.yaml
    apiVersion: v1
    kind: Service
    metadata:
      ...
    spec:
      ...
      ports:
        ...
      - name: http
        port: 8080  # {"type":"integer","x-kustomize":{"partialFieldSetters":[{"name":"http-port","value":"8080"}]}}
        ...

  Setters may also be defined directly by editing the yaml and adding the comment.

Users may not set the field value using the `set` command:

    # change the http-port value to 8081
    $ kustomize cfg set DIR/ http-port 8081

### Using default values

The default values for a setter may be:

- valid field values (e.g. `8080` or `008080` for a port)
- invalid values that adhere to the schema (e.g. `0000` for a port)
- values that do not adhere to the schema (e.g. `[PORT]` for port)

A setter may be for a substring of a full field:

    $ kustomize cfg set create DIR/ image-tag v1.0.01 --type "string" --field "image"

    image: gcr.io/example/app:v1.0.1 # # {"type":"string","x-kustomize":{"partialFieldSetters":[{"name":"image-tag","value":"v1.0.1"}]}}

A single field value may have multiple setters applied to it for different parts of the field.

### Examples

    # create a setter for port fields matching "8080"
    kustomize cfg create-setter DIR/ port 8080 --type "integer" --field port \
         --description "default port used by the app"

    # create a setter for a substring of a field rather than the full field -- e.g. only the
    # image tag, not the full image
    kustomize cfg create-setter DIR/ image-tag v1.0.1 --type "string" \
        --field image --description "current stable release"