format

command module
v0.0.0-...-3df40d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

format

Overview

? This function works well with 1.0.0-beta.1 or lower versions of kpt. Starting from 1.0.0-beta.2, the order of the fields is preserved by kpt CLI.

Format resources by sorting fields, fixing indentation and quoting ambiguous string values.

This function sorts the resource fields. Field ordering follows the ordering defined in the OpenAPI document for Kubernetes resources, falling back on lexicographical sorting for unrecognized fields. This function also performs other changes like fixing indentation and adding quotes to ambiguous string values.

Examples
Format a package

Let's start with the input resource in a package.

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    bar: 100
  name: nginx-deployment
spec:
  template:
    spec:
      containers:
        - name: nginx
          image: nginx:1.0.0
          ports:
            - containerPort: 80
              name: http

Invoke the format function on the package, formatted resource looks like the following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    bar: "100"
spec:
  template:
    spec:
      containers:
        - name: nginx
          image: nginx:1.0.0
          ports:
            - name: http
              containerPort: 80

The fields are ordered as per the OpenAPI schema definition of Deployment resource. For e.g. metadata.name field is moved up. Since the type of annotation value is string, quotes are added to value 100 as it will be interpreted as int by yaml in its current form.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Code generated by "mdtogo"; DO NOT EDIT.
Code generated by "mdtogo"; DO NOT EDIT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL