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

Support various target and resource with go-getter #2278

Merged
merged 2 commits into from
Mar 24, 2020

Conversation

yujunz
Copy link
Member

@yujunz yujunz commented Mar 15, 2020

  • getter is inserted before git cloner
  • local file is NOT handled by getter
  • tested against existing examples

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 15, 2020
@yujunz
Copy link
Member Author

yujunz commented Mar 15, 2020

Backward compatible with existing examples

hack/testExamplesAgainstKustomize.sh HEAD
Example tests passed against HEAD.

@yujunz
Copy link
Member Author

yujunz commented Mar 15, 2020

/test kustomize-presubmit-master

@yujunz
Copy link
Member Author

yujunz commented Mar 15, 2020

Unable to understand the lint error:

level=error msg="Running error: SA2003: failed prerequisites: [[email protected]/kustomize/api/resmap_test [sigs.k8s.io/kustomize/api/resmap.test]: analysis skipped: errors in package: [/home/prow/go/src/sigs.k8s.io/kustomize/api/resmap/resmap_test.go:730:40: cannot use rf (variable of type *resource.Factory) as *resource.Factory value in argument to resmaptest_test.NewRmBuilder

Is it a flake? I didn't even change the file.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 16, 2020
@yujunz yujunz force-pushed the getter branch 2 times, most recently from 8c2554e to ea5d780 Compare March 16, 2020 08:59
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 18, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 19, 2020
@yujunz
Copy link
Member Author

yujunz commented Mar 19, 2020

Ready for review @Liujingfang1 @pwittrock

@Liujingfang1
Copy link
Contributor

@yujunz Where did you see the lint error? Is it resolved?

}

// newLoaderAtConfirmedDir returns a new fileLoader with given root.
func newLoaderAtConfirmedDir(
lr LoadRestrictorFunc,
root filesys.ConfirmedDir, fSys filesys.FileSystem,
referrer *fileLoader, cloner git.Cloner) *fileLoader {
referrer *fileLoader, cloner git.Cloner, getter resourceGetter) *fileLoader {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looks like getter and cover the functionality of cloner. Can you see if we can use getter only rather than both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an intersection between getter and cloner. Some special URLs can only be handled by cloner at the moment.

One thing we can do is refactoring cloner to Detect and Get in getter and register them in getter. Then we shall have the unified interface while keeping backward compatibility.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the special URLs that can't be handled by cloner? If they are not supported by getter, keeping the cloner for them should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example,

if isAzureHost(x.Host) || isAWSHost(x.Host) {

I don't see detectors in go-getter to handle them. It supports only plain git, GitHub and bitbucket url.

@yujunz
Copy link
Member Author

yujunz commented Mar 20, 2020

Where did you see the lint error? Is it resolved?

Yes, it has been resolved by #2280

// Getter is a function that can gets resource
type resourceGetter func(rs *resourceSpec) error

func newResourceGetter(raw string, fSys filesys.FileSystem, referrer *fileLoader, cloner git.Cloner, getter resourceGetter) (ifc.Loader, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the function name of newResourceGetter. Maybe newLoaderAtGetter to be consistent with other function names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


`github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6`
- a subdirectory in a repo on branch repoUrl2
# a repo with a root level kustomization.yaml on branch test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already covered by L91

# a subdirectory in a repo on branch repoUrl2
- github.com/Liujingfang1/kustomize/examples/helloWorld?ref=repoUrl2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already covered in L91 that followed. kustomize repository is too huge for testing. It takes a long time to clone when network is not so good.

return nil, err
}

// TODO(yujunz): check file or directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by this todo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A resource can either be a plain yaml or an archive. The former should be loaded as it is and the latter needs to be extracted to directory. It turns out this is already handled in

// try loading resource as file then as base (directory or git repository)

Removed the TODO item

// TODO(yujunz): check file or directory

return &fileLoader{
loadRestrictor: RestrictionRootOnly,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loadRestrictor should be inherited from the parent overlay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the top level similar tonewLoaderAtGiClone

// Clones never allowed to escape root.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're correct. For the remote target, we should restrict the load restrictor to be within that remote target.

}

// Getter is a function that can gets resource
type resourceGetter func(rs *resourceSpec) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to change resourceGetter to remoteTargetGetter since resource has a specific meaning in kustomize, which is different from the usage here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"sigs.k8s.io/kustomize/api/internal/git"
)

type resourceSpec struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resourceSpec -> remoteTargetSpec

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member Author

@yujunz yujunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments inline

@Liujingfang1
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Liujingfang1, yujunz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 24, 2020
@k8s-ci-robot k8s-ci-robot merged commit cd6614a into kubernetes-sigs:master Mar 24, 2020
@yujunz yujunz deleted the getter branch March 25, 2020 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants