Merge "Allow to customize inventory policy for applier"

This commit is contained in:
Zuul 2021-11-19 23:24:09 +00:00 committed by Gerrit Code Review
commit 0dc707359a
4 changed files with 26 additions and 7 deletions

View File

@ -27,6 +27,7 @@ import (
v1 "k8s.io/client-go/applyconfigurations/core/v1" v1 "k8s.io/client-go/applyconfigurations/core/v1"
"k8s.io/klog/v2" "k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/cmd/flagutils"
"sigs.k8s.io/cli-utils/cmd/printers" "sigs.k8s.io/cli-utils/cmd/printers"
"sigs.k8s.io/cli-utils/pkg/apply" "sigs.k8s.io/cli-utils/pkg/apply"
"sigs.k8s.io/cli-utils/pkg/common" "sigs.k8s.io/cli-utils/pkg/common"
@ -136,12 +137,18 @@ func (c *Config) toCliOptions() apply.Options {
emitStatusEvents = true emitStatusEvents = true
} }
inventoryPolicy, err := flagutils.ConvertInventoryPolicy(c.InventoryPolicy)
if err != nil {
klog.V(2).Infof("%s or force-adopt, using the default one (strict)", err.Error())
}
return apply.Options{ return apply.Options{
DryRunStrategy: dryRunStrategy, DryRunStrategy: dryRunStrategy,
NoPrune: !c.PruneOptions.Prune, NoPrune: !c.PruneOptions.Prune,
EmitStatusEvents: emitStatusEvents, EmitStatusEvents: emitStatusEvents,
ReconcileTimeout: timeout, ReconcileTimeout: timeout,
PollInterval: pollInterval, PollInterval: pollInterval,
InventoryPolicy: inventoryPolicy,
} }
} }

View File

@ -20,13 +20,14 @@ import (
// ApplyConfig provides instructions on how to apply resources to kubernetes cluster // ApplyConfig provides instructions on how to apply resources to kubernetes cluster
type ApplyConfig struct { type ApplyConfig struct {
WaitOptions ApplyWaitOptions `json:"waitOptions,omitempty"` WaitOptions ApplyWaitOptions `json:"waitOptions,omitempty"`
PruneOptions ApplyPruneOptions `json:"pruneOptions,omitempty"` PruneOptions ApplyPruneOptions `json:"pruneOptions,omitempty"`
Kubeconfig string `json:"kubeconfig,omitempty"` Kubeconfig string `json:"kubeconfig,omitempty"`
Context string `json:"context,omitempty"` Context string `json:"context,omitempty"`
DryRun bool `json:"druRun,omitempty"` DryRun bool `json:"druRun,omitempty"`
Debug bool `json:"debug,omitempty"` Debug bool `json:"debug,omitempty"`
PhaseName string `json:"phaseName,omitempty"` PhaseName string `json:"phaseName,omitempty"`
InventoryPolicy string `json:"inventoryPolicy,omitempty"`
} }
// ApplyWaitOptions provides instructions how to wait for kubernetes resources // ApplyWaitOptions provides instructions how to wait for kubernetes resources

View File

@ -37,6 +37,12 @@ spec:
type: boolean type: boolean
druRun: druRun:
type: boolean type: boolean
inventoryPolicy:
description: 'InventoryPolicy defines if an inventory object can take
over objects that belong to another inventory object or don''t belong
to any inventory object. Possible values are: "strict", "adopt"
or "force-adopt"'
type: string
kubeconfig: kubeconfig:
type: string type: string
phaseName: phaseName:

View File

@ -37,6 +37,11 @@ type ApplyConfig struct {
DryRun bool `json:"druRun,omitempty"` DryRun bool `json:"druRun,omitempty"`
Debug bool `json:"debug,omitempty"` Debug bool `json:"debug,omitempty"`
PhaseName string `json:"phaseName,omitempty"` PhaseName string `json:"phaseName,omitempty"`
// InventoryPolicy defines if an inventory object can take over objects that belong to another
// inventory object or don't belong to any inventory object. Possible values are:
// "strict", "adopt" or "force-adopt"
InventoryPolicy string `json:"inventoryPolicy,omitempty"`
} }
// ApplyWaitOptions provides instructions how to wait for kubernetes resources // ApplyWaitOptions provides instructions how to wait for kubernetes resources