From 44cb2c720996f6184d8b4429f46206ad8fd06a88 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 17 Mar 2022 11:16:52 +0100 Subject: [PATCH] feat: Allow to enable barriers on deployment item level --- docs/annotations.md | 23 ++++++++++++++++++++++- pkg/deployment/deployment_item.go | 5 +++++ pkg/deployment/utils/apply_utils.go | 2 +- pkg/utils/utils.go | 12 ++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/annotations.md b/docs/annotations.md index 147003eed..ef6d17361 100644 --- a/docs/annotations.md +++ b/docs/annotations.md @@ -1,4 +1,4 @@ -# Annotations +# Annotations on object level kluctl supports multiple annotations that influence individual commands. These are: @@ -124,3 +124,24 @@ are added to the validation result, which is then returned by the validate comma The annotation key is dynamic, meaning that all annotations that begin with `validate-result.kluctl.io/` are taken into account. +# Annotations on kustomize deployment level + +In addition to kluctl.io annotations which can be set on object/resource level, you can also set a few annotations +inside the kustomization.yml itself. + +Example: +```yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +metadata: + annotations: + kluctl.io/barrier: "true" + +resources: + - deployment.yml +``` + +### kluctl.io/barrier +If set to `true`, kluctl will wait for all previous objects to be applied (but not necessarily ready). This has the +same effect as [barrier](./deployments.md#barriers) from deployment projects. diff --git a/pkg/deployment/deployment_item.go b/pkg/deployment/deployment_item.go index 3069960f4..1402faf9d 100644 --- a/pkg/deployment/deployment_item.go +++ b/pkg/deployment/deployment_item.go @@ -28,6 +28,9 @@ type DeploymentItem struct { dir *string index int + // These values come from the metadata of the kustomization.yml + Barrier bool + Objects []*uo.UnstructuredObject relProjectDir string @@ -295,6 +298,8 @@ func (di *DeploymentItem) prepareKustomizationYaml() error { } } + di.Barrier = utils.ParseBoolOrFalse(ky.GetK8sAnnotation("kluctl.io/barrier")) + // Save modified kustomize.yml err = yaml.WriteYamlFile(kustomizeYamlPath, ky) if err != nil { diff --git a/pkg/deployment/utils/apply_utils.go b/pkg/deployment/utils/apply_utils.go index 4228d939f..5ad9441d9 100644 --- a/pkg/deployment/utils/apply_utils.go +++ b/pkg/deployment/utils/apply_utils.go @@ -432,7 +432,7 @@ func (a *ApplyUtil) ApplyDeployments() { a.applyDeploymentItem(d) }() - barrier := d.Config.Barrier != nil && *d.Config.Barrier + barrier := (d.Config.Barrier != nil && *d.Config.Barrier) || d.Barrier if barrier { log.Infof("Waiting on barrier...") wg.Wait() diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 5f303199b..9a6a0ecf0 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -7,6 +7,7 @@ import ( "log" "os" "path/filepath" + "strconv" "sync" ) @@ -42,3 +43,14 @@ func FindStrInSlice(a []string, s string) int { } return -1 } + +func ParseBoolOrFalse(s *string) bool { + if s == nil { + return false + } + b, err := strconv.ParseBool(*s) + if err != nil { + return false + } + return b +}