-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat: add support for relative paths (ansible) #2273
Conversation
cmd/operator-sdk/up/local.go
Outdated
// 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) | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
All done @joelanford 👍 |
pkg/ansible/watches/watches_test.go
Outdated
func Test_getFullRolePathWithEnvVarSet(t *testing.T) { | ||
// Mock customized Path | ||
customPath := "customized/myroles" | ||
os.Setenv("ANSIBLE_ROLES_PATH", customPath) |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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.
pkg/ansible/watches/watches.go
Outdated
envVar, ok := os.LookupEnv("ANSIBLE_ROLES_PATH") | ||
if ok && len(envVar) > 0 { | ||
return filepath.Join(envVar, path) | ||
} |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
I might be unavailable to review again next time around :)
/hold Pending support for colon-separate path handling and tests around that. |
pkg/ansible/watches/watches.go
Outdated
// 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 | ||
} |
There was a problem hiding this comment.
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>
)?
There was a problem hiding this comment.
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)
pkg/ansible/watches/watches.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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
?
/lgtm when CI passes |
/hold cancel |
New changes are detected. LGTM label has been removed. |
Description
operator-SDK up local
with the roles and playbooks using relative pathsPS.: Now, when roles/playbooks are configured with a relative path then, the operator will looking for them in the current directory.