Skip to content

Commit b63424e

Browse files
authored
Fix force-delete-replace and add filter to not copy YTT code (#302)
1 parent df5d78a commit b63424e

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

internal/kpt/util/update/fastforward_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestUpdate_FastForward(t *testing.T) {
130130
WithResource(pkgbuilder.DeploymentResource),
131131
),
132132
},
133-
"doesn't update the Kptfile": {
133+
"Updates the Kptfile": {
134134
origin: pkgbuilder.NewRootPkg().
135135
WithKptfile(
136136
pkgbuilder.NewKptfile().
@@ -155,7 +155,7 @@ func TestUpdate_FastForward(t *testing.T) {
155155
expected: pkgbuilder.NewRootPkg().
156156
WithKptfile(
157157
pkgbuilder.NewKptfile().
158-
WithUpstream(kptRepo, "/", "master", "fast-forward").
158+
WithUpstream(kptRepo, "/", "v1.0", "fast-forward").
159159
WithUpstreamLock(kptRepo, "/", "master", "abc123"),
160160
).
161161
WithResource(pkgbuilder.ConfigMapResource),

internal/kpt/util/update/replace.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/nephio-project/porch/internal/kpt/pkg"
2323
"github.com/nephio-project/porch/internal/kpt/types"
2424
"github.com/nephio-project/porch/internal/kpt/util/pkgutil"
25+
"github.com/nephio-project/porch/pkg/kpt/kptfileutil"
2526
)
2627

2728
// Updater updates a package to a new upstream version.
@@ -32,11 +33,16 @@ type ReplaceUpdater struct{}
3233

3334
func (u ReplaceUpdater) Update(options Options) error {
3435
const op errors.Op = "update.Update"
36+
37+
// Update Kptfile for root package
38+
if err := kptfileutil.UpdateKptfile(options.LocalPath, options.UpdatedPath, options.OriginPath, true); err != nil {
39+
return errors.E(op, types.UniquePath(options.LocalPath), err)
40+
}
41+
3542
paths, err := pkgutil.FindSubpackagesForPaths(pkg.Local, true, options.LocalPath, options.UpdatedPath)
3643
if err != nil {
3744
return errors.E(op, types.UniquePath(options.LocalPath), err)
3845
}
39-
4046
for _, p := range append([]string{"."}, paths...) {
4147
isRootPkg := false
4248
if p == "." && options.IsRoot {

internal/kpt/util/update/replace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestUpdate_Replace(t *testing.T) {
130130
WithResource(pkgbuilder.DeploymentResource),
131131
),
132132
},
133-
"doesn't update the Kptfile": {
133+
"Updates the Kptfile": {
134134
origin: pkgbuilder.NewRootPkg().
135135
WithKptfile(
136136
pkgbuilder.NewKptfile().
@@ -155,7 +155,7 @@ func TestUpdate_Replace(t *testing.T) {
155155
expected: pkgbuilder.NewRootPkg().
156156
WithKptfile(
157157
pkgbuilder.NewKptfile().
158-
WithUpstream(kptRepo, "/", "master", "force-delete-replace").
158+
WithUpstream(kptRepo, "/", "v1.0", "force-delete-replace").
159159
WithUpstreamLock(kptRepo, "/", "master", "abc123"),
160160
).
161161
WithResource(pkgbuilder.ConfigMapResource),

pkg/task/generictaskhandler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package task
1717
import (
1818
"context"
1919
"fmt"
20+
"strings"
2021

2122
api "github.com/nephio-project/porch/api/porch/v1alpha1"
2223
configapi "github.com/nephio-project/porch/api/porchconfig/v1alpha1"
@@ -358,7 +359,11 @@ func healConfig(old, new map[string]string) (map[string]string, error) {
358359
if n.GetNamespace() == original.GetNamespace() &&
359360
n.GetName() == original.GetName() &&
360361
n.GetApiVersion() == original.GetApiVersion() &&
361-
n.GetKind() == original.GetKind() {
362+
n.GetKind() == original.GetKind() &&
363+
// Support ytt templates with #@ and #! comments
364+
!strings.Contains(n.MustString(), "#@") && !strings.Contains(original.MustString(), "#@") &&
365+
!strings.Contains(n.MustString(), "#!") && !strings.Contains(original.MustString(), "#!") {
366+
362367
err = comments.CopyComments(original, n)
363368
if err != nil {
364369
return nil, fmt.Errorf("failed to copy comments: %w", err)

0 commit comments

Comments
 (0)