Skip to content

Commit 45b6a52

Browse files
Bugfix for operator-framework#4530: not able to test ansible operator locally or on k8s cluster (operator-framework#4944)
* Bugfix for operator-framework#4530: unable to test ansible operator locally or on k8s cluster Signed-off-by: rashmigottipati <[email protected]>
1 parent f855bd6 commit 45b6a52

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
[![Build Status](https://github.com/operator-framework/operator-sdk/workflows/deploy/badge.svg)](https://github.com/operator-framework/operator-sdk/actions)
55
[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
6-
[![Go Report Card](https://goreportcard.com/badge/github.com/operator-framework/operator-sdk)](https://goreportcard.com/report/github.com/operator-framework/operator-sdk)
76

87
## Documentation
98

internal/ansible/runner/runner.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const (
4848
// to the ansible-runner command. This will override the value for a particular CR.
4949
// Example usage "ansible.sdk.operatorframework.io/verbosity: 5"
5050
AnsibleVerbosityAnnotation = "ansible.sdk.operatorframework.io/verbosity"
51+
52+
ansibleRunnerBin = "ansible-runner"
5153
)
5254

5355
// Runner - a runnable that should take the parameters and name and namespace
@@ -180,6 +182,10 @@ type runner struct {
180182
}
181183

182184
func (r *runner) Run(ident string, u *unstructured.Unstructured, kubeconfig string) (RunResult, error) {
185+
if _, err := exec.LookPath(ansibleRunnerBin); err != nil {
186+
return nil, err
187+
}
188+
183189
timer := metrics.ReconcileTimer(r.GVK.String())
184190
defer timer.ObserveDuration()
185191

@@ -277,11 +283,16 @@ func (r *runner) Run(ident string, u *unstructured.Unstructured, kubeconfig stri
277283
// link the current run to the `latest` directory under artifacts
278284
currentRun := filepath.Join(inputDir.Path, "artifacts", ident)
279285
latestArtifacts := filepath.Join(inputDir.Path, "artifacts", "latest")
280-
if _, err = os.Lstat(latestArtifacts); err == nil {
281-
if err = os.Remove(latestArtifacts); err != nil {
282-
logger.Error(err, "Error removing the latest artifacts symlink")
286+
if _, err = os.Lstat(latestArtifacts); err != nil {
287+
if !errors.Is(err, os.ErrNotExist) {
288+
logger.Error(err, "Latest artifacts dir has error")
289+
return
283290
}
291+
} else if err = os.Remove(latestArtifacts); err != nil {
292+
logger.Error(err, "Error removing the latest artifacts symlink")
293+
return
284294
}
295+
285296
if err = os.Symlink(currentRun, latestArtifacts); err != nil {
286297
logger.Error(err, "Error symlinking latest artifacts")
287298
}

0 commit comments

Comments
 (0)