Skip to content

Commit 7077b97

Browse files
authored
Remove addition of "package-context.yaml" to sub-packages in a PackageRevision (#364)
* Remove mutation on clne that adds package-context.yaml Signed-off-by: liamfallon <liam.fallon@est.tech> * Changed implementation to just add to root of package Signed-off-by: liamfallon <liam.fallon@est.tech> * Updated to address review comments Signed-off-by: liamfallon <liam.fallon@est.tech> --------- Signed-off-by: liamfallon <liam.fallon@est.tech>
1 parent 642fe5e commit 7077b97

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

internal/kpt/builtins/pkg_context.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (pc *PackageContextGenerator) Process(resourceList *framework.ResourceList)
7575

7676
// This loop does the following:
7777
// - Filters out package context resources from the input resources
78-
// - Generates a package context resource for each kpt package (i.e Kptfile)
78+
// - Generates a package context resource for the root kpt package (i.e Kptfile)
7979
for _, resource := range resourceList.Items {
8080
gvk := resid.GvkFromNode(resource)
8181
if gvk.Equals(configMapGVK) && resource.GetName() == PkgContextName {
@@ -95,7 +95,11 @@ func (pc *PackageContextGenerator) Process(resourceList *framework.ResourceList)
9595
}
9696
return resourceList.Results
9797
}
98-
contextResources = append(contextResources, pkgContext)
98+
99+
// Only add package context to the root kpt package
100+
if pkgContext != nil {
101+
contextResources = append(contextResources, pkgContext)
102+
}
99103
}
100104
}
101105

@@ -121,6 +125,12 @@ func pkgContextResource(kptfile *yaml.RNode, packageConfig *PackageConfig) (*yam
121125
if err != nil {
122126
return nil, err
123127
}
128+
129+
// We only want one "package-context.yaml" in each kpt package
130+
if kptfilePath != kptfilev1.KptFileGVK().Kind {
131+
return nil, nil
132+
}
133+
124134
annotations := map[string]string{
125135
kioutil.PathAnnotation: path.Join(path.Dir(kptfilePath), PkgContextFile),
126136
}

internal/kpt/builtins/testdata/pkg-with-nesting/out.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,8 @@ items:
4242
internal.config.kubernetes.io/path: 'package-context.yaml'
4343
data:
4444
name: order-service
45-
- apiVersion: v1
46-
kind: ConfigMap
47-
metadata:
48-
name: kptfile.kpt.dev
49-
annotations:
50-
config.kubernetes.io/local-config: "true"
51-
internal.config.kubernetes.io/path: 'subpkg/package-context.yaml'
52-
data:
53-
name: subpkg
5445
results:
5546
- message: generated package context
5647
severity: info
5748
file:
5849
path: package-context.yaml
59-
- message: generated package context
60-
severity: info
61-
file:
62-
path: subpkg/package-context.yaml

0 commit comments

Comments
 (0)