Skip to content

feat: add support for relative paths (ansible) #2273

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

Merged
merged 7 commits into from
Feb 5, 2020
Merged

feat: add support for relative paths (ansible) #2273

merged 7 commits into from
Feb 5, 2020

Conversation

camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Nov 26, 2019

Description

  • Allow users to inform relative paths and names for roles and playbook
  • Allow using the operator-SDK up local with the roles and playbooks using relative paths

PS.: Now, when roles/playbooks are configured with a relative path then, the operator will looking for them in the current directory.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 26, 2019
@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 26, 2019
@camilamacedo86 camilamacedo86 changed the title WIP - Roles and playbooks ansible Allow users to inform relative paths and names for roles and playbook Nov 28, 2019
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 28, 2019
@camilamacedo86 camilamacedo86 added language/ansible Issue is related to an Ansible operator project kind/feature Categorizes issue or PR as related to a new feature. labels Nov 29, 2019
@camilamacedo86 camilamacedo86 changed the title Allow users to inform relative paths and names for roles and playbook WIP : Allow users to inform relative paths and names for roles and playbook Nov 29, 2019
@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 29, 2019
@camilamacedo86 camilamacedo86 changed the title WIP : Allow users to inform relative paths and names for roles and playbook WIP : feat: add support for relative paths (ansible) Dec 6, 2019
@openshift-ci-robot openshift-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 6, 2019
@camilamacedo86 camilamacedo86 changed the title WIP : feat: add support for relative paths (ansible) feat: add support for relative paths (ansible) Dec 7, 2019
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 7, 2019
Comment on lines 170 to 174
// Set local env
if err := os.Setenv(k8sutil.ForceRunModeEnv, "local"); err != nil {
return fmt.Errorf("failed to set %s environment variable: (%v)", k8sutil.ForceRunModeEnv, err)
}

Copy link
Member

Choose a reason for hiding this comment

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

Is this change related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because the env var has not been set.
It also is required in the fix: #2190

@camilamacedo86
Copy link
Contributor Author

All done @joelanford 👍

@camilamacedo86 camilamacedo86 added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Feb 4, 2020
func Test_getFullRolePathWithEnvVarSet(t *testing.T) {
// Mock customized Path
customPath := "customized/myroles"
os.Setenv("ANSIBLE_ROLES_PATH", customPath)
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a couple of other tests with the following paths:

  • "nonexistent/roles"
  • "customized/myroles:nonexistent/roles"
  • "nonexistent/roles:customized/myroles"
  • "nonexistent1/roles:nonexistent2/roles"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests were improved.
We are testing the func getFullRolePath with and whiteout the envVar + we are checking the load well with the successful scenarios.

Comment on lines 173 to 176
envVar, ok := os.LookupEnv("ANSIBLE_ROLES_PATH")
if ok && len(envVar) > 0 {
return filepath.Join(envVar, path)
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't we still need to handle the case of a multiple paths in the ANSIBLE_ROLES_PATH value? (e.g. path1/roles:path2/roles:/absolute/path3/roles)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

@joelanford joelanford dismissed their stale review February 4, 2020 18:34

I might be unavailable to review again next time around :)

@joelanford
Copy link
Member

/hold

Pending support for colon-separate path handling and tests around that.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 4, 2020
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 4, 2020
Comment on lines 184 to 188
// Check if the role can be found in the envVar + roles + role role
infoPathWithRolesDir := filepath.Join(result[i], "roles", path)
if _, err := os.Stat(infoPathWithRolesDir); err == nil {
return infoPathWithRolesDir
}
Copy link
Member

@joelanford joelanford Feb 4, 2020

Choose a reason for hiding this comment

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

Does ANSIBLE_ROLES_PATH work this way (where it checks in <path>/<role> and <path>/roles/<role>)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Ansible documentation do not explain how it should work.
However, according to it maintainer

A role should be found in the defined "roles path" (via config) or in a roles/ directory adjacent to the play
From: ansible/ansible#16911 (comment)

@@ -290,7 +304,7 @@ func verifyAnsiblePath(playbook string, role string) error {
case role != "":
rolePath := getFullRolePath(role)
if _, err := os.Stat(rolePath); err != nil {
return fmt.Errorf("role path: %v was not found", role)
return fmt.Errorf("role role: %v was not found", role)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like there was a global search/replace of path to role?

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 4, 2020
@joelanford
Copy link
Member

/lgtm

when CI passes

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2020
@joelanford
Copy link
Member

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 4, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2020
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-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 Feb 4, 2020
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. kind/feature Categorizes issue or PR as related to a new feature. language/ansible Issue is related to an Ansible operator project size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants