Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clone directory rewriting #2749

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions porch/engine/pkg/engine/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"

v1 "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
api "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1"
configapi "github.com/GoogleContainerTools/kpt/porch/controllers/pkg/apis/porch/v1alpha1"
"github.com/GoogleContainerTools/kpt/porch/engine/pkg/kpt"
Expand Down Expand Up @@ -98,19 +97,10 @@ func (m *clonePackageMutation) cloneFromGit(ctx context.Context, gitPackage *api
return repository.PackageResources{}, fmt.Errorf("cannot read package resources: %w", err)
}

// Rewrite paths
results := map[string]string{}
prefix := gitPackage.Directory + "/"
for k, v := range resources.Spec.Resources {
if !strings.HasPrefix(k, prefix) {
return repository.PackageResources{}, fmt.Errorf("invalid file path within a package: %q", k)
}
results[path.Join(m.name, k[len(prefix):])] = v
}
contents := resources.Spec.Resources

// Update Kptfile
kptfilePath := path.Join(m.name, "Kptfile")
kptfile, found := results[kptfilePath]
kptfile, found := contents[v1.KptFileName]
if !found {
return repository.PackageResources{}, fmt.Errorf("package %s@%s is not valid; missing Kptfile", gitPackage.Directory, gitPackage.Ref)
}
Expand All @@ -120,10 +110,10 @@ func (m *clonePackageMutation) cloneFromGit(ctx context.Context, gitPackage *api
return repository.PackageResources{}, err
}

results[kptfilePath] = kptfile
contents[v1.KptFileName] = kptfile

return repository.PackageResources{
Contents: results,
Contents: contents,
}, nil
}

Expand Down