mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 02:55:22 +00:00
* api: Add new types for customizeable resource ordering Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com> * plugins: Implement SortOrderTransformer plugin Implement the SortOrderTransformer plugin. This plugin allows the user to customize the order that kustomize will output resources in. The API for the plugin is the following: sortOptions: order: legacy | fifo legacySortOptions: orderFirst: - {GVK} orderLast: - {GVK} Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com> * plugins: Add boilerplate and generate code for new SortOrderTransformer Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com> * build: Add option to denote if the reorder flag was set by the user We want to take different actions if the reorder flag was set by the user or filled by the default value. Thus, we propagate this information from build to the krusty options. Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com> * api/krusty: Ensure sort ordering works with CLI flag and kustomization Sort order can be defined in two places: - (new) kustomization file - (old) CLI flag We want the kustomization file to take precedence over the CLI flag. Eventually, we may want to move away from having a CLI flag altogether: https://github.com/kubernetes-sigs/kustomize/issues/3947 Case 1: Sort order set in kustomization file AND in CLI flag. Print a warning and let the kustomization file take precedence. Case 2: Sort order set in CLI flag only or not at all. Follow the CLI flag (defaults to legacy) and reorder at the end. Case 3: Sort order set in kustomization file only. Simply build the kustomization. Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com> * krusty: Add e2e test for SortOrderTransformer Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com> * plugins: Purge LegacyOrderTransformer Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com> * Update go.work.sum Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com> * review: Make review changes Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com> Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com> Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
// Copyright 2019 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package krusty
|
|
|
|
import (
|
|
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
|
"sigs.k8s.io/kustomize/api/types"
|
|
)
|
|
|
|
type ReorderOption string
|
|
|
|
const (
|
|
ReorderOptionLegacy ReorderOption = "legacy"
|
|
ReorderOptionNone ReorderOption = "none"
|
|
ReorderOptionUnspecified ReorderOption = "unspecified"
|
|
)
|
|
|
|
// Options holds high-level kustomize configuration options,
|
|
// e.g. are plugins enabled, should the loader be restricted
|
|
// to the kustomization root, etc.
|
|
type Options struct {
|
|
// When true, sort the resources before emitting them,
|
|
// per a particular sort order. When false, don't do the
|
|
// sort, and instead respect the depth-first resource input
|
|
// order as specified by the kustomization file(s).
|
|
|
|
// Sort the resources before emitting them. Possible values:
|
|
// - "legacy": Use a fixed order that kustomize provides for backwards
|
|
// compatibility.
|
|
// - "none": Respect the depth-first resource input order as specified by the
|
|
// kustomization file.
|
|
// - "unspecified": The user didn't specify any preference. Kustomize will
|
|
// select the appropriate default.
|
|
Reorder ReorderOption
|
|
|
|
// When true, a label
|
|
// app.kubernetes.io/managed-by: kustomize-<version>
|
|
// is added to all the resources in the build out.
|
|
AddManagedbyLabel bool
|
|
|
|
// Restrictions on what can be loaded from the file system.
|
|
// See type definition.
|
|
LoadRestrictions types.LoadRestrictions
|
|
|
|
// Create an inventory object for pruning.
|
|
DoPrune bool
|
|
|
|
// Options related to kustomize plugins.
|
|
PluginConfig *types.PluginConfig
|
|
}
|
|
|
|
// MakeDefaultOptions returns a default instance of Options.
|
|
func MakeDefaultOptions() *Options {
|
|
return &Options{
|
|
Reorder: ReorderOptionNone,
|
|
AddManagedbyLabel: false,
|
|
LoadRestrictions: types.LoadRestrictionsRootOnly,
|
|
DoPrune: false,
|
|
PluginConfig: types.DisabledPluginConfig(),
|
|
}
|
|
}
|
|
|
|
// GetBuiltinPluginNames returns a list of builtin plugin names
|
|
func GetBuiltinPluginNames() []string {
|
|
var ret []string
|
|
for k := range builtinhelpers.GeneratorFactories {
|
|
ret = append(ret, k.String())
|
|
}
|
|
for k := range builtinhelpers.TransformerFactories {
|
|
ret = append(ret, k.String())
|
|
}
|
|
return ret
|
|
}
|