Skip to content
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

ansible operator reapeating tasks twice? #6424

Closed
ricosega opened this issue May 9, 2023 · 6 comments
Closed

ansible operator reapeating tasks twice? #6424

ricosega opened this issue May 9, 2023 · 6 comments
Assignees
Labels
triage/support Indicates an issue that is a support question.
Milestone

Comments

@ricosega
Copy link

ricosega commented May 9, 2023

Question

Why the operator is repeating the task twice?

What did you do?

Created a new crd and in the tasks doing some steps:

  • create namespace if does not exist
  • create a kubernetes object (external secret) this causes repetition

What did you expect to see?

I want the task to be done once.

What did you see instead? Under which circumstances?

The task repeated.
First time it creates the namespace and creates the object externalSecret.
But it runs again from the beginning.

Environment

Operator type:

Kubernetes cluster type:
EKS 1.25

$ operator-sdk version
operator-sdk version: "v1.27.0", commit: "5cbdad9209332043b7c730856b6302edc8996faf", kubernetes version: "1.25.0", go version: "go1.19.5", GOOS: "linux", GOARCH: "amd64"

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", GitCommit:"434bfd82814af038ad94d62ebe59b133fcb50506", GitTreeState:"clean", BuildDate:"2022-10-12T10:57:26Z", GoVersion:"go1.19.2", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"25+", GitVersion:"v1.25.6-eks-48e63af", GitCommit:"9f22d4ae876173884749c0701f01340879ab3f95", GitTreeState:"clean", BuildDate:"2023-01-24T19:19:02Z", GoVersion:"go1.19.5", Compiler:"gc", Platform:"linux/amd64"}

Additional context

Is not the only case when adding this part of code "create externalSecrets" that causes the task to be repeated twice. But tried removing all the tasks and leaving the minimum when it starts to do this behavior.
Below you can see it:
https://gist.github.com/ricosega/ba9d35904af8e9329de16c7853543be2

@varshaprasad96 varshaprasad96 added the triage/support Indicates an issue that is a support question. label May 15, 2023
@varshaprasad96 varshaprasad96 added this to the Backlog milestone May 15, 2023
@everettraven
Copy link
Contributor

@ricosega Would you be able to share your watches.yaml file? My suspicion is that you are somehow watching secrets so when your playbook runs and creates a Secret it triggers the reconciliation again.

@ricosega
Copy link
Author

ricosega commented May 16, 2023

hi @everettraven,

here is my watches.yaml

---
# Use the 'create api' subcommand to add watches to this file.
- version: v1alpha1
  group: deploy.lab
  kind: Laboratory
  playbook: playbooks/laboratory.yml
  manageStatus: False
  watchAnnotationsChanges: False
  finalizer:
    name: deploy.lab/finalizer
    playbook: roles/laboratory/tasks/delete/laboratory.yaml  
#+kubebuilder:scaffold:watch

Just to give you more overview, the operator manages creating labs, so it creates needed kubernetes objects and also some infrastructure.

@everettraven
Copy link
Contributor

@ricosega Thanks for sharing your watches.yaml! I think the problem may be that by default the ansible operator injects owner-references on resources created during reconciliation and will automatically establish watches for them. This can be configured by using the watchDependentResources field for a watches.yaml entry. For more information on this, see the documentation here: https://sdk.operatorframework.io/docs/building-operators/ansible/reference/dependent-watches/

I suspect that if you disable the dependent resource watches that you will no longer see the reconciliation triggered a second time

@ricosega
Copy link
Author

@everettraven that was the cause!
would it be possible to remove this owner reference for specific object without losing the watchDependentResources feature for the whole CR?
I can't see how to do it.
https://sdk.operatorframework.io/docs/building-operators/ansible/reference/retroactively-owned-resources/

@everettraven
Copy link
Contributor

@ricosega Apologies for my severly late reply. I don't think it is possible to only remove the injected owner reference for a specific object, but I do think you could configure a watch on individual resources you want watched to trigger the same playbook.

@ricosega
Copy link
Author

well the "watchDependentResources" solved our problem, thank you @everettraven for your responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

3 participants