Skip to content

Commit

Permalink
add to BuildAnnotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed Nov 19, 2021
1 parent dfc6270 commit bd7bad1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions api/resource/resource.go
Expand Up @@ -42,9 +42,12 @@ var BuildAnnotations = []string{
kioutil.PathAnnotation,
kioutil.IndexAnnotation,
kioutil.SeqIndentAnnotation,
kioutil.IdAnnotation,
kioutil.InternalAnnotationsMigrationResourceIDAnnotation,

kioutil.LegacyPathAnnotation,
kioutil.LegacyIndexAnnotation,
kioutil.LegacyIdAnnotation,
}

func (r *Resource) ResetRNode(incoming *Resource) {
Expand Down
10 changes: 3 additions & 7 deletions kyaml/kio/kio.go
Expand Up @@ -14,10 +14,6 @@ import (
"sigs.k8s.io/kustomize/kyaml/yaml"
)

// resourceIDAnnotation is used to uniquely identify the resource during round trip
// to and from a function execution.
const resourceIDAnnotation = "internal.config.k8s.io/annotations-migration-resource-id"

// Reader reads ResourceNodes. Analogous to io.Reader.
type Reader interface {
Read() ([]*yaml.RNode, error)
Expand Down Expand Up @@ -178,7 +174,7 @@ func PreprocessResourcesForInternalAnnotationMigration(result []*yaml.RNode) (ma
idToAnnosMap := make(map[string]map[string]string)
for i := range result {
idStr := strconv.Itoa(i)
err := result[i].PipeE(yaml.SetAnnotation(resourceIDAnnotation, idStr))
err := result[i].PipeE(yaml.SetAnnotation(kioutil.InternalAnnotationsMigrationResourceIDAnnotation, idStr))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -259,7 +255,7 @@ func ReconcileInternalAnnotations(result []*yaml.RNode, nodeAnnosMap map[string]
return err
}

if _, err = result[i].Pipe(yaml.ClearAnnotation(resourceIDAnnotation)); err != nil {
if _, err = result[i].Pipe(yaml.ClearAnnotation(kioutil.InternalAnnotationsMigrationResourceIDAnnotation)); err != nil {
return err
}
}
Expand Down Expand Up @@ -369,7 +365,7 @@ func checkAnnotationsAltered(rn *yaml.RNode, nodeAnnosMap map[string]map[string]
id: annotations[kioutil.LegacyIdAnnotation],
}

rid := annotations[resourceIDAnnotation]
rid := annotations[kioutil.InternalAnnotationsMigrationResourceIDAnnotation]
originalAnnotations, found := nodeAnnosMap[rid]
if !found {
return nil
Expand Down
5 changes: 5 additions & 0 deletions kyaml/kio/kioutil/kioutil.go
Expand Up @@ -41,6 +41,11 @@ const (

// Deprecated: use IdAnnotation instead.
LegacyIdAnnotation = "config.k8s.io/id"

// InternalAnnotationsMigrationResourceIDAnnotation is used to uniquely identify
// resources during round trip to and from a function execution. We will use it
// to track the internal annotations and reconcile them if needed.
InternalAnnotationsMigrationResourceIDAnnotation = "internal.config.k8s.io/annotations-migration-resource-id"
)

func GetFileAnnotations(rn *yaml.RNode) (string, string, error) {
Expand Down

0 comments on commit bd7bad1

Please sign in to comment.