Debian Codegraph @

kyaml/kio/filters/local.go

raw symbols SCIP
1 // Copyright 2019 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 package filters
5
6 import (
7 "sigs.k8s.io/kustomize/kyaml/yaml"
8 )
9
10 const LocalConfigAnnotation = "config.kubernetes.io/local-config"
11
12 // IsLocalConfig filters Resources using the config.kubernetes.io/local-config annotation
13 type IsLocalConfig struct {
14 // IncludeLocalConfig will include local-config if set to true
15 IncludeLocalConfig bool `yaml:"includeLocalConfig,omitempty"`
16
17 // ExcludeNonLocalConfig will exclude non local-config if set to true
18 ExcludeNonLocalConfig bool `yaml:"excludeNonLocalConfig,omitempty"`
19 }
20
21 // Filter implements kio.Filter
22 func (c *IsLocalConfig) Filter(inputs []*yaml.RNode) ([]*yaml.RNode, error) {
23 var out []*yaml.RNode
24 for i := range inputs {
25 meta, err := inputs[i].GetMeta()
26 if err != nil {
27 return nil, err
28 }
29 _, local := meta.Annotations[LocalConfigAnnotation]
30
31 if local && c.IncludeLocalConfig {
32 out = append(out, inputs[i])
33 } else if !local && !c.ExcludeNonLocalConfig {
34 out = append(out, inputs[i])
35 }
36 }
37 return out, nil
38 }