Skip to content

Commit

Permalink
fix lifecycle change summarizer to show relocated image
Browse files Browse the repository at this point in the history
fixes #187
  • Loading branch information
tomkennedy513 committed Aug 18, 2021
1 parent 4183b49 commit 9dbc939
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/import/change_summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func SummarizeChange(
StackRefGetter: stackFactory,
}

err = writeLifecycleChange(ctx, desc.Lifecycle, iDiffer, cs, &summarizer)
err = writeLifecycleChange(ctx, kpConfig, desc.Lifecycle, iDiffer, cs, &summarizer)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/import/change_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ type changeWriter interface {
writeChange(header string)
}

func writeLifecycleChange(ctx context.Context, newLifecycle Lifecycle, differ *ImportDiffer, cs buildk8s.ClientSet, cw changeWriter) error {
func writeLifecycleChange(ctx context.Context, kpConfig config.KpConfig, newLifecycle Lifecycle, differ *ImportDiffer, cs buildk8s.ClientSet, cw changeWriter) error {
if newLifecycle.Image != "" {
oldImg, err := lifecycle.GetImage(ctx, cs.K8sClient)
if err != nil {
return err
}

diff, err := differ.DiffLifecycle(oldImg, newLifecycle.Image)
diff, err := differ.DiffLifecycle(kpConfig, oldImg, newLifecycle.Image)
if err != nil {
return err
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/import/import_differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package _import
import (
"context"
"fmt"
"path"
"strings"
"sync"

"github.com/google/go-containerregistry/pkg/authn"
Expand Down Expand Up @@ -33,8 +35,19 @@ type ImportDiffer struct {
StackRefGetter StackRefGetter
}

func (id *ImportDiffer) DiffLifecycle(oldImg string, newImg string) (string, error) {
return id.Differ.Diff(oldImg, newImg)
func (id *ImportDiffer) DiffLifecycle(kpConfig config.KpConfig, oldImg string, newImg string) (string, error) {
canonicalRepo, err := kpConfig.CanonicalRepository()
if err != nil {
return "", err
}

newLifecycleImg := path.Join(canonicalRepo, "lifecycle")
s := strings.Split(newImg, "@")
if len(s) == 2 {
newLifecycleImg = fmt.Sprintf("%s@%s", newLifecycleImg, s[1])
}

return id.Differ.Diff(oldImg, newLifecycleImg)
}

func (id *ImportDiffer) DiffClusterStore(keychain authn.Keychain, kpConfig config.KpConfig, oldCS *v1alpha1.ClusterStore, newCS ClusterStore) (string, error) {
Expand Down
25 changes: 25 additions & 0 deletions pkg/import/import_differ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,29 @@ func testImportDiffer(t *testing.T, when spec.G, it spec.S) {
require.Equal(t, nil, diffArg0)
})
})

when("DiffLifecycle", func() {
oldLifecycle := "my-cool-repo/lifecycle@some-digest"
it("diffs lifecycle with digest", func() {
newLifecycle := "someregistry/lifecycle@some-new-digest"
diff, err := importDiffer.DiffLifecycle(kpConfig, oldLifecycle, newLifecycle)
require.NoError(t, err)
require.Equal(t, "some-diff", diff)

diffArg0, diffArg1 := fakeDiffer.Args()
require.Equal(t, oldLifecycle, diffArg0)
require.Equal(t, "my-cool-repo/lifecycle@some-new-digest", diffArg1)
})

it("diffs lifecycle with no digest", func() {
newLifecycle := "someregistry/lifecycle"
diff, err := importDiffer.DiffLifecycle(kpConfig, oldLifecycle, newLifecycle)
require.NoError(t, err)
require.Equal(t, "some-diff", diff)

diffArg0, diffArg1 := fakeDiffer.Args()
require.Equal(t, oldLifecycle, diffArg0)
require.Equal(t, "my-cool-repo/lifecycle", diffArg1)
})
})
}

0 comments on commit 9dbc939

Please sign in to comment.