Skip to content

Commit

Permalink
Bugfix for operator-framework#4530: not able to test ansible operator…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
rashmigottipati authored May 26, 2021
1 parent f855bd6 commit 45b6a52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

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

## Documentation

Expand Down
17 changes: 14 additions & 3 deletions internal/ansible/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
// to the ansible-runner command. This will override the value for a particular CR.
// Example usage "ansible.sdk.operatorframework.io/verbosity: 5"
AnsibleVerbosityAnnotation = "ansible.sdk.operatorframework.io/verbosity"

ansibleRunnerBin = "ansible-runner"
)

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

func (r *runner) Run(ident string, u *unstructured.Unstructured, kubeconfig string) (RunResult, error) {
if _, err := exec.LookPath(ansibleRunnerBin); err != nil {
return nil, err
}

timer := metrics.ReconcileTimer(r.GVK.String())
defer timer.ObserveDuration()

Expand Down Expand Up @@ -277,11 +283,16 @@ func (r *runner) Run(ident string, u *unstructured.Unstructured, kubeconfig stri
// link the current run to the `latest` directory under artifacts
currentRun := filepath.Join(inputDir.Path, "artifacts", ident)
latestArtifacts := filepath.Join(inputDir.Path, "artifacts", "latest")
if _, err = os.Lstat(latestArtifacts); err == nil {
if err = os.Remove(latestArtifacts); err != nil {
logger.Error(err, "Error removing the latest artifacts symlink")
if _, err = os.Lstat(latestArtifacts); err != nil {
if !errors.Is(err, os.ErrNotExist) {
logger.Error(err, "Latest artifacts dir has error")
return
}
} else if err = os.Remove(latestArtifacts); err != nil {
logger.Error(err, "Error removing the latest artifacts symlink")
return
}

if err = os.Symlink(currentRun, latestArtifacts); err != nil {
logger.Error(err, "Error symlinking latest artifacts")
}
Expand Down

0 comments on commit 45b6a52

Please sign in to comment.