Skip to content

Commit

Permalink
♻️ Make local-config annotation specific
Browse files Browse the repository at this point in the history
kpt only does a function at once, and honors the removal
of the `config.kuberntes.io/local-config` marked resources.

In consequence, we cannot use `config.kuberntes.io/local-config`
anymore to inject resources. We replace it with
 `config.kaweezle.com/local-config`.

`prune-local` is not a workaround anymore  but becomes
a feature. The README needs to be adapted in consequence.
  • Loading branch information
antoinemartin committed Jan 26, 2023
1 parent 0c02181 commit 9beefad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 0 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/fn/framework/command"
"sigs.k8s.io/kustomize/kyaml/kio/filters"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
Expand Down Expand Up @@ -85,11 +84,6 @@ func main() {
if err != nil {
return errors.WrapPrefixf(err, "Removing local from keep-local resources")
}
filter := &filters.IsLocalConfig{IncludeLocalConfig: false, ExcludeNonLocalConfig: false}
err = rl.Filter(filter)
if err != nil {
return errors.WrapPrefixf(err, "filtering local configs")
}
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
FunctionAnnotationFunction = ConfigurationAnnotationDomain + "/function"

// true when the resource is part of the local configuration
FunctionAnnotationLocalConfig = ConfigurationAnnotationDomain + "/local-config"
FunctionAnnotationLocalConfig = LocalConfigurationAnnotationDomain + "/local-config"

// Setting to true means we want this function configuration to be injected as a
// local configuration resource (local-config)
Expand Down
11 changes: 8 additions & 3 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/kio/filters"
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
Expand Down Expand Up @@ -40,7 +39,7 @@ func RemoveBuildAnnotations(r *resource.Resource) {
func MakeResourceLocal(r *yaml.RNode) error {
annotations := r.GetAnnotations()

annotations[filters.LocalConfigAnnotation] = "true"
annotations[FunctionAnnotationLocalConfig] = "true"
if _, ok := annotations[kioutil.PathAnnotation]; !ok {
annotations[kioutil.PathAnnotation] = ".generated.yaml"
}
Expand All @@ -54,6 +53,7 @@ func MakeResourceLocal(r *yaml.RNode) error {
}

func unLocal(list []*yaml.RNode) ([]*yaml.RNode, error) {
output := []*yaml.RNode{}
for _, r := range list {
annotations := r.GetAnnotations()
if _, ok := annotations[FunctionAnnotationKeepLocal]; ok {
Expand All @@ -70,9 +70,14 @@ func unLocal(list []*yaml.RNode) ([]*yaml.RNode, error) {
delete(annotations, FunctionAnnotationIndex)
}
r.SetAnnotations(annotations)
output = append(output, r)
} else {
if _, ok := annotations[FunctionAnnotationLocalConfig]; !ok {
output = append(output, r)
}
}
}
return list, nil
return output, nil
}

var UnLocal kio.FilterFunc = unLocal

0 comments on commit 9beefad

Please sign in to comment.