|
| 1 | +// Module included in the following assembly: |
| 2 | +// |
| 3 | +// * scalability_and_performance/cluster-compare/creating-a-reference-configuration.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | + |
| 7 | +[id="cluster-compare-exclude-metadata_{context}"] |
| 8 | += Configuring the metadata.yaml file to exclude template fields |
| 9 | + |
| 10 | +You can configure the `metadata.yaml` file to exclude fields from a comparison. Exclude fields that are irrelevant to a comparison, for example annotations or labels that are inconsequential to a cluster configuration. |
| 11 | + |
| 12 | +You can configure exclusions in the `metadata.yaml` file in the following ways: |
| 13 | + |
| 14 | +* Exclude all fields in a custom resource not specified in a template. |
| 15 | + |
| 16 | +* Exclude specific fields that you define using the `pathToKey` field. |
| 17 | ++ |
| 18 | +[NOTE] |
| 19 | +==== |
| 20 | +`pathToKey` is a dot separated path. Use quotes to escape key values featuring a period. |
| 21 | +==== |
| 22 | + |
| 23 | +[id="cluster-compare-ignore-all-fields_{context}"] |
| 24 | +== Excluding all fields not specified in a template |
| 25 | + |
| 26 | +During the comparison process, the `cluster-compare` plugin renders a template by merging fields from the corresponding custom resource (CR). If you configure the `ignore-unspecified-fields` to `true`, all fields that are present in the CR, but not in the template, are excluded from the merge. Use this approach when you want to focus the comparison on the fields specified in the template only. |
| 27 | + |
| 28 | +.Procedure |
| 29 | + |
| 30 | +* Create a `metadata.yaml` file to match your use case. Use the following structure as an example: |
| 31 | ++ |
| 32 | +[source,yaml] |
| 33 | +---- |
| 34 | +apiVersion: v2 |
| 35 | +parts: |
| 36 | + - name: Part1 |
| 37 | + components: |
| 38 | + - name: Namespace |
| 39 | + allOf: |
| 40 | + - path: namespace.yaml |
| 41 | + config: |
| 42 | + ignore-unspecified-fields: true <1> |
| 43 | +#... |
| 44 | +---- |
| 45 | +<1> Specify `true` to exclude from the comparison all fields in a CR that are not explicitly configured in the corresponding `namespace.yaml` template. |
| 46 | + |
| 47 | +[id="cluster-compare-ignore-default-fields_{context}"] |
| 48 | +== Excluding specific fields by setting default exclusion fields |
| 49 | + |
| 50 | +You can exclude fields by defining a default value for `fieldsToOmitRefs` in the `defaultOmitRef` field. This default exclusion applies to all templates, unless overridden by the `config.fieldsToOmitRefs` field for a specific template. |
| 51 | + |
| 52 | +.Procedure |
| 53 | + |
| 54 | +* Create a `metadata.yaml` file to match your use case. Use the following structure as an example: |
| 55 | ++ |
| 56 | +.Example metadata.yaml file |
| 57 | +[source,yaml] |
| 58 | +---- |
| 59 | +apiVersion: v2 |
| 60 | +parts: |
| 61 | +
|
| 62 | +#... |
| 63 | +
|
| 64 | +fieldsToOmit: |
| 65 | + defaultOmitRef: default <1> |
| 66 | + items: |
| 67 | + default: |
| 68 | + - pathToKey: a.custom.default."k8s.io" <2> |
| 69 | +---- |
| 70 | +<1> Sets the default exclusion for all templates, unless overridden by the `config.fieldsToOmitRefs` field for a specific template. |
| 71 | +<2> The value is excluded for all templates. |
| 72 | + |
| 73 | +[id="cluster-compare-ignore-specified-fields_{context}"] |
| 74 | +== Excluding specific fields |
| 75 | + |
| 76 | +You can specify fields to exclude by defining the path to the field, and then referencing the definition in the `config` section for a template. |
| 77 | + |
| 78 | +.Procedure |
| 79 | + |
| 80 | +* Create a `metadata.yaml` file to match your use case. Use the following structure as an example: |
| 81 | ++ |
| 82 | +.Example metadata.yaml file |
| 83 | +[source,yaml] |
| 84 | +---- |
| 85 | +apiVersion: v2 |
| 86 | +parts: |
| 87 | + - name: Part1 |
| 88 | + components: |
| 89 | + - name: Component1 |
| 90 | + - path: deployment.yaml |
| 91 | + config: |
| 92 | + fieldsToOmitRefs: |
| 93 | + - deployments <1> |
| 94 | +
|
| 95 | +#... |
| 96 | +
|
| 97 | +fieldsToOmit: |
| 98 | + items: |
| 99 | + deployments: |
| 100 | + - pathToKey: spec.selector.matchLabels.k8s-app <2> |
| 101 | +---- |
| 102 | +<1> References the `fieldsToOmit.items.deployments` item for the `deployment.yaml` template. |
| 103 | +<2> Excludes the `spec.selector.matchLabels.k8s-app` field from the comparison. |
| 104 | ++ |
| 105 | +[NOTE] |
| 106 | +==== |
| 107 | +Setting `fieldsToOmitRefs` replaces the default value. |
| 108 | +==== |
| 109 | + |
| 110 | +[id="cluster-compare-ignore-default-groups_{context}"] |
| 111 | +== Excluding specific fields by setting default exclusion groups |
| 112 | + |
| 113 | +You can create default groups of fields to exclude. A group of exclusions can reference another group to avoid duplication when defining exclusions. |
| 114 | + |
| 115 | +.Procedure |
| 116 | + |
| 117 | +* Create a `metadata.yaml` file to match your use case. Use the following structure as an example: |
| 118 | ++ |
| 119 | +.Example metadata.yaml file |
| 120 | +[source,yaml] |
| 121 | +---- |
| 122 | +apiVersion: v2 |
| 123 | +parts: |
| 124 | +
|
| 125 | +#... |
| 126 | +
|
| 127 | +fieldsToOmit: |
| 128 | + defaultOmitRef: default |
| 129 | + items: |
| 130 | + common: |
| 131 | + - pathToKey: metadata.annotations."kubernetes.io/metadata.name" |
| 132 | + - pathToKey: metadata.annotations."kubernetes.io/metadata.name" |
| 133 | + - pathToKey: metadata.annotations."kubectl.kubernetes.io/last-applied-configuration" |
| 134 | + - pathToKey: metadata.creationTimestamp |
| 135 | + - pathToKey: metadata.generation |
| 136 | + - pathToKey: spec.ownerReferences |
| 137 | + - pathToKey: metadata.ownerReferences |
| 138 | + default: |
| 139 | + - include: common <1> |
| 140 | + - pathToKey: status |
| 141 | +---- |
| 142 | +<1> The `common` group is included in the default group. |
0 commit comments