Skip to content

Commit

Permalink
feat: Allow to enable barriers on deployment item level
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Mar 17, 2022
1 parent 881ae9b commit 44cb2c7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
23 changes: 22 additions & 1 deletion docs/annotations.md
@@ -1,4 +1,4 @@
# Annotations
# Annotations on object level

kluctl supports multiple annotations that influence individual commands. These are:

Expand Down Expand Up @@ -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.
5 changes: 5 additions & 0 deletions pkg/deployment/deployment_item.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/utils/apply_utils.go
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions pkg/utils/utils.go
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"strconv"
"sync"
)

Expand Down Expand Up @@ -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
}

0 comments on commit 44cb2c7

Please sign in to comment.