Skip to content

Commit

Permalink
init observe func
Browse files Browse the repository at this point in the history
Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>

fixes

Signed-off-by: Fahed DORGAA <fahed.dorgaa@gmail.com>
  • Loading branch information
fahedouch committed May 10, 2022
1 parent 471b45d commit 37c4af5
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 35 deletions.
4 changes: 3 additions & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ In this case, we define the desired state as source of truth for our OpenShift c

The annotation used to specify the policy information is not part of the desired state or source of truth. It is really just a small chunk of metadata that instructs the Ansible provider how to trigger the Ansible role.

When user creates the `AnsibleRun` resource, it means they claim to request the cluster. This will trigger the Ansible role in `Observe()`. When user deletes the `AnsibleRun` resource, it means they claim to drop the cluster. This will trigger the same Ansible role in `Delete()` to clean the cluster.
When user creates the `AnsibleRun` resource, it means they claim to request the cluster. This will trigger the Ansible role in `Observe()`.
When user edits the `AnsibleRun` resource, it means they claim to update the cluster. This will trigger the Ansible role in `Observe()`.
When user deletes the `AnsibleRun` resource, it means they claim to drop the cluster. This will trigger the same Ansible role in `Delete()` to clean the cluster.

In order to differentiate the presence or absence of `AnsibleRun`, a special variable will be sent to the Ansible role when it starts to run:

Expand Down
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gotest.tools/v3 v3.2.0
k8s.io/api v0.24.0
k8s.io/apimachinery v0.24.0
k8s.io/client-go v0.24.0
sigs.k8s.io/controller-runtime v0.11.2
Expand Down Expand Up @@ -50,7 +51,7 @@ require (
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.1.0 // indirect
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
Expand All @@ -75,7 +76,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
Expand All @@ -92,12 +93,11 @@ require (
google.golang.org/api v0.44.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.24.0 // indirect
k8s.io/apiextensions-apiserver v0.23.5 // indirect
k8s.io/component-base v0.23.5 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
Expand All @@ -107,3 +107,6 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

// Temporary fork crossplane-runtime to support PolicyRun meta
replace github.com/crossplane/crossplane-runtime => github.com/fahedouch/crossplane-runtime v0.15.2-0.20220510100729-93336f6af258
15 changes: 10 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
Expand All @@ -146,8 +147,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crossplane/crossplane-runtime v0.15.1 h1:4l3iTMyrQRkt9U0P1oJ6M71JMFGcIq95agFu7OPrwRE=
github.com/crossplane/crossplane-runtime v0.15.1/go.mod h1:XvktCTRFTkdP2jR2PecrvhsxzSO8XT3jHxTOk/k+NL8=
github.com/crossplane/crossplane-tools v0.0.0-20210320162312-1baca298c527 h1:9M6hMLKqjxtL9d9nwfcaAt59Ey0CPfSXQ3iIdYRUNaE=
github.com/crossplane/crossplane-tools v0.0.0-20210320162312-1baca298c527/go.mod h1:C735A9X0x0lR8iGVOOxb49Mt70Ua4EM2b7PGaRPBLd4=
github.com/dave/jennifer v1.3.0 h1:p3tl41zjjCZTNBytMwrUuiAnherNUZktlhPTKoF/sEk=
Expand Down Expand Up @@ -176,13 +175,16 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fahedouch/crossplane-runtime v0.15.2-0.20220510100729-93336f6af258 h1:D/C5QxU1k2b8tTAZX/XFq5VeP3YIuU0X/N8giaI+mOc=
github.com/fahedouch/crossplane-runtime v0.15.2-0.20220510100729-93336f6af258/go.mod h1:XvktCTRFTkdP2jR2PecrvhsxzSO8XT3jHxTOk/k+NL8=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
Expand Down Expand Up @@ -401,8 +403,9 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down Expand Up @@ -692,8 +695,9 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe
go.uber.org/atomic v0.0.0-20181018215023-8dc6146f7569/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
Expand Down Expand Up @@ -1132,8 +1136,9 @@ google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG
google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.41.0 h1:f+PlOh7QV4iIJkPrx5NQ7qaNGFQ3OTse67yaDHfju4E=
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
78 changes: 64 additions & 14 deletions internal/ansible/ansible.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"path/filepath"
"strings"

"github.com/crossplane/crossplane-runtime/pkg/meta"

"github.com/crossplane/provider-ansible/apis/v1alpha1"
"github.com/crossplane/provider-ansible/pkg/galaxyutil"
"github.com/crossplane/provider-ansible/pkg/runnerutil"
Expand All @@ -42,12 +44,37 @@ type Parameters struct {
GalaxyBinary string
// ansible-runner binary path.
RunnerBinary string
// Dir in which to execute the ansible-runner binary.
WorkingDir string
// WorkingDirPath in which to execute the ansible-runner binary.
WorkingDirPath string
CollectionsPath string
RolesPath string
}

// RunPolicy represents the run policies of Ansible.
type RunPolicy struct {
Name string
}

// newRunPolicy creates a run Policy with the specified Name.
// supports the following run policies:
// - ObserveAndDelete
// - CheckWhenObserve
// For more details about RunPolicy : https://github.com/multicloudlab/crossplane-provider-ansible/blob/main/docs/design.md#ansible-run-policy
func newRunPolicy(rPolicy string) (*RunPolicy, error) {
switch rPolicy {
case "", "ObserveAndDelete":
if rPolicy == "" {
rPolicy = "ObserveAndDelete"
}
case "CheckWhenObserve":
default:
return nil, fmt.Errorf("run policy %q not supported", rPolicy)
}
return &RunPolicy{
Name: rPolicy,
}, nil
}

// A runnerOption configures a Runner.
type runnerOption func(*Runner)

Expand All @@ -65,27 +92,34 @@ func withCmdFunc(cmdFunc cmdFuncType) runnerOption {
}
}

// withAnsibleVerbosity set the ansible-runner verbosity.
// withAnsibleVerbosity set the runner verbosity.
func withAnsibleVerbosity(verbosity int) runnerOption {
return func(r *Runner) {
r.ansibleVerbosity = verbosity
}
}

// withAnsibleGathering set the ansible-runner default policy of fact gathering.
// withAnsibleGathering set the runner default policy of fact gathering.
func withAnsibleGathering(gathering string) runnerOption {
return func(r *Runner) {
r.ansibleGathering = gathering
}
}

// withAnsibleHosts set the ansible-runner hosts to execute against.
// withAnsibleHosts set the runner hosts to execute against.
func withAnsibleHosts(hosts string) runnerOption {
return func(r *Runner) {
r.ansibleHosts = hosts
}
}

// withAnsibleRunPolicy set the runner Policy to execute against.
func withAnsibleRunPolicy(p *RunPolicy) runnerOption {
return func(r *Runner) {
r.AnsibleRunPolicy = p
}
}

type cmdFuncType func(gathering string, hosts string, verbosity int) *exec.Cmd

// playbookCmdFunc mimics https://github.com/operator-framework/operator-sdk/blob/707240f006ecfc0bc86e5c21f6874d302992d598/internal/ansible/runner/runner.go#L75-L90
Expand Down Expand Up @@ -149,7 +183,7 @@ func (p Parameters) roleCmdFunc(path string) (cmdFuncType, error) {

// GalaxyInstall Install non-exists collections with ansible-galaxy cli
func (p Parameters) GalaxyInstall() error {
requirementsFilePath := runnerutil.GetFullPath(p.WorkingDir, galaxyutil.RequirementsFile)
requirementsFilePath := runnerutil.GetFullPath(p.WorkingDirPath, galaxyutil.RequirementsFile)

cmdArgs := []string{"collection", "install"}
cmdOptions := []string{
Expand Down Expand Up @@ -203,24 +237,30 @@ func (p Parameters) Init(ctx context.Context, cr *v1alpha1.AnsibleRun, pc *v1alp
}
}

rPolicy, err := newRunPolicy(meta.GetPolicyRun(cr))
if err != nil {
return nil, err
}
return new(withPath(path),
withCmdFunc(cmdFunc),
// TODO add verbosity filed to the API, now it is ignored by (0) value
withAnsibleVerbosity(0),
withAnsibleGathering(behaviorVars["ANSIBLE_GATHERING"]),
// TODO hosts should be handled via configuration vars e.g: vars["hosts"]
withAnsibleHosts(""),
withAnsibleRunPolicy(rPolicy),
), nil
}

// Runner struct
type Runner struct {
Path string // path on disk to a playbook or role depending on what cmdFunc expects
Path string // absolute path on disk to a playbook or role depending on what cmdFunc expects
Vars map[string]interface{}
cmdFunc cmdFuncType // returns a Cmd that runs ansible-runner
ansibleVerbosity int
ansibleGathering string
ansibleHosts string
AnsibleRunPolicy *RunPolicy
}

// new returns a runner that will be used as ansible-runner client
Expand All @@ -236,10 +276,10 @@ func new(o ...runnerOption) *Runner {
}

// addRolePlaybookPaths will add the full path based on absolute path of cloning dir
// Func from operator SDK
// addRolePlaybookPaths mimics https://github.com/operator-framework/operator-sdk/blob/master/internal/ansible/watches/watches.go#L179-L206
func addRolePlaybookPaths(p Parameters, behaviorVars map[string]string, cr *v1alpha1.AnsibleRun) {
if len(cr.Spec.ForProvider.Playbook) > 0 {
cr.Spec.ForProvider.Playbook = runnerutil.GetFullPath(p.WorkingDir, cr.Spec.ForProvider.Playbook)
cr.Spec.ForProvider.Playbook = runnerutil.GetFullPath(p.WorkingDirPath, cr.Spec.ForProvider.Playbook)
}

if len(cr.Spec.ForProvider.Role) > 0 {
Expand All @@ -252,7 +292,7 @@ func addRolePlaybookPaths(p Parameters, behaviorVars map[string]string, cr *v1al
collectionsPath = behaviorVars[AnsibleCollectionsPath]
}

possibleRolePaths := getPossibleRolePaths(p.WorkingDir, cr.Spec.ForProvider.Role, collectionsPath, rolesPath)
possibleRolePaths := getPossibleRolePaths(p.WorkingDirPath, cr.Spec.ForProvider.Role, collectionsPath, rolesPath)
for _, possiblePath := range possibleRolePaths {
if _, err := os.Stat(possiblePath); err == nil {
cr.Spec.ForProvider.Role = possiblePath
Expand All @@ -263,7 +303,7 @@ func addRolePlaybookPaths(p Parameters, behaviorVars map[string]string, cr *v1al
}

// getPossibleRolePaths returns list of possible absolute paths derived from a user provided value.
func getPossibleRolePaths(workingDir, path, ansibleRolesPath, ansibleCollectionsPath string) []string {
func getPossibleRolePaths(workingDirPath, path, ansibleRolesPath, ansibleCollectionsPath string) []string {
possibleRolePaths := []string{}
if filepath.IsAbs(path) || len(path) == 0 {
return append(possibleRolePaths, path)
Expand Down Expand Up @@ -293,7 +333,16 @@ func getPossibleRolePaths(workingDir, path, ansibleRolesPath, ansibleCollections
}
}
// Roles can also live in the working directory.
return append(possibleRolePaths, runnerutil.GetFullPath(workingDir, filepath.Join("roles", path)))
return append(possibleRolePaths, runnerutil.GetFullPath(workingDirPath, filepath.Join("roles", path)))
}

// AddFile from https://github.com/operator-framework/operator-sdk/blob/master/internal/ansible/runner/internal/inputdir/inputdir.go#L55-L63
func (p Parameters) AddFile(path string, content []byte) error {
fullPath := filepath.Join(p.WorkingDirPath, path)
if err := os.WriteFile(fullPath, content, 0644); err != nil {
return err
}
return nil
}

// Changes parse 'ansible-playbook --check' results to determine whether there is a diff between
Expand Down Expand Up @@ -328,8 +377,9 @@ func getPossibleRolePaths(workingDir, path, ansibleRolesPath, ansibleCollections
return resourcesExists
}*/

// ParseResults play `ansible-playbook` then parse JSON stream results with check mode
/*func (pbCmd *PbCmd) ParseResults(ctx context.Context, mg resource.Managed) (bool, bool, error) {
// runWithCheckMode plays `ansible-runner` with check mode
// then parse JSON stream results
/*func (r *Runner) runWithCheckMode(ctx context.Context, mg resource.Managed) (bool, bool, error) {
// Enable the check flag
// Check don't make any changes; instead, try to predict some of the changes that may occur
pbCmd.Playbook.Options.Check = true
Expand Down
2 changes: 1 addition & 1 deletion internal/ansible/ansible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestInit(t *testing.T) {
firstCr.Spec.ForProvider.Role = filepath.Join(filepath.Join(ansibleCtx, "roles"), tc.role)

ps := Parameters{
WorkingDir: ansibleCtx,
WorkingDirPath: ansibleCtx,
}

secondCr := v1alpha1.AnsibleRun{ObjectMeta: objectMeta}
Expand Down
Loading

0 comments on commit 37c4af5

Please sign in to comment.