From 0401bd644cd079d8a08c574ccc39c30eb80aaad9 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Thu, 18 Nov 2021 20:34:18 +0000 Subject: [PATCH] Allow to customize inventory policy for applier Change-Id: I6943cddee52bcb605ce63adc21ce56f6afaadc5b Signed-off-by: Ruslan Aliev --- krm-functions/applier/image/main.go | 7 +++++++ krm-functions/applier/image/types/types.go | 15 ++++++++------- .../airshipit.org_kubernetesapplies.yaml | 6 ++++++ pkg/api/v1alpha1/kubernetes_apply_types.go | 5 +++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/krm-functions/applier/image/main.go b/krm-functions/applier/image/main.go index 0368fc872..e887f6f82 100644 --- a/krm-functions/applier/image/main.go +++ b/krm-functions/applier/image/main.go @@ -27,6 +27,7 @@ import ( v1 "k8s.io/client-go/applyconfigurations/core/v1" "k8s.io/klog/v2" 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/pkg/apply" "sigs.k8s.io/cli-utils/pkg/common" @@ -136,12 +137,18 @@ func (c *Config) toCliOptions() apply.Options { 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{ DryRunStrategy: dryRunStrategy, NoPrune: !c.PruneOptions.Prune, EmitStatusEvents: emitStatusEvents, ReconcileTimeout: timeout, PollInterval: pollInterval, + InventoryPolicy: inventoryPolicy, } } diff --git a/krm-functions/applier/image/types/types.go b/krm-functions/applier/image/types/types.go index e1e68f10e..5aa3e3f96 100755 --- a/krm-functions/applier/image/types/types.go +++ b/krm-functions/applier/image/types/types.go @@ -20,13 +20,14 @@ import ( // ApplyConfig provides instructions on how to apply resources to kubernetes cluster type ApplyConfig struct { - WaitOptions ApplyWaitOptions `json:"waitOptions,omitempty"` - PruneOptions ApplyPruneOptions `json:"pruneOptions,omitempty"` - Kubeconfig string `json:"kubeconfig,omitempty"` - Context string `json:"context,omitempty"` - DryRun bool `json:"druRun,omitempty"` - Debug bool `json:"debug,omitempty"` - PhaseName string `json:"phaseName,omitempty"` + WaitOptions ApplyWaitOptions `json:"waitOptions,omitempty"` + PruneOptions ApplyPruneOptions `json:"pruneOptions,omitempty"` + Kubeconfig string `json:"kubeconfig,omitempty"` + Context string `json:"context,omitempty"` + DryRun bool `json:"druRun,omitempty"` + Debug bool `json:"debug,omitempty"` + PhaseName string `json:"phaseName,omitempty"` + InventoryPolicy string `json:"inventoryPolicy,omitempty"` } // ApplyWaitOptions provides instructions how to wait for kubernetes resources diff --git a/manifests/function/airshipctl-schemas/airshipit.org_kubernetesapplies.yaml b/manifests/function/airshipctl-schemas/airshipit.org_kubernetesapplies.yaml index 1655679c6..f6ace77c6 100644 --- a/manifests/function/airshipctl-schemas/airshipit.org_kubernetesapplies.yaml +++ b/manifests/function/airshipctl-schemas/airshipit.org_kubernetesapplies.yaml @@ -37,6 +37,12 @@ spec: type: boolean druRun: 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: type: string phaseName: diff --git a/pkg/api/v1alpha1/kubernetes_apply_types.go b/pkg/api/v1alpha1/kubernetes_apply_types.go index f54e1533e..c5a7dfd09 100644 --- a/pkg/api/v1alpha1/kubernetes_apply_types.go +++ b/pkg/api/v1alpha1/kubernetes_apply_types.go @@ -37,6 +37,11 @@ type ApplyConfig struct { DryRun bool `json:"druRun,omitempty"` Debug bool `json:"debug,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