Skip to content

Commit ecd89e8

Browse files
committed
Changed implementation to just add to root of package
Signed-off-by: liamfallon <liam.fallon@est.tech>
1 parent ebb869c commit ecd89e8

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

internal/kpt/builtins/pkg_context.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 of a 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

pkg/task/clone.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ func (m *clonePackageMutation) apply(ctx context.Context, resources repository.P
8080
}
8181
}
8282

83+
if m.isDeployment {
84+
// TODO(droot): executing this as mutation is not really needed, but can be
85+
// refactored once we finalize the task/mutation/commit model.
86+
genPkgContextMutation, err := newPackageContextGeneratorMutation(m.packageConfig)
87+
if err != nil {
88+
return repository.PackageResources{}, nil, err
89+
}
90+
cloned, _, err = genPkgContextMutation.apply(ctx, cloned)
91+
if err != nil {
92+
return repository.PackageResources{}, nil, pkgerrors.Wrap(err, "failed to generate deployment context")
93+
}
94+
}
95+
8396
// ensure merge-key comment is added to newly added resources.
8497
// this operation is done on best effort basis because if upstream contains
8598
// valid YAML but invalid KRM resources, merge-key operation will fail

0 commit comments

Comments
 (0)