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

feature: dynamic inventory of resources created by a CR of an ansible operator #22

Open
jobcespedes opened this issue May 6, 2021 · 4 comments
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@jobcespedes
Copy link

jobcespedes commented May 6, 2021

Feature Request

Dynamic inventory of resources created by a CR of an ansible operator

Describe the problem you need a feature to resolve.

Operating or running ansible tasks over pods generated by a CR of an ansible operator is kind of cumbersome. One could use kubectl connection plugin and add them dynamically during each reconciliation loop using variables. The existing dynamic k8s inventory plugin could be a better fit. However, adding it to an ansible operator requires some steps. In addition, when done, it shows all the pods and services the operator has access and groups them in a way, in my opinion, not intuitive for the operator scope. They could not be filter, for instance.

Describe the solution you'd like.

The operator sdk to already include a dynamic inventory plugin that groups and adds only the pods, and optionally other kind of resources, of the CR the reconciliation loop is running. I would like to run some complementary ansible tasks over some of those pods. How it groups them should be intuitive in order to reference hosts, or groups more probably, in playbooks inside the operator. For instance: the name of a default group of all pods of a CR could be used as: hosts: {{ ansible_operator_meta.namespace }}__{{ ansible_operator_meta.namespace }}__pods. In addition, it would be helpful to define custom group formats using labels and add extra ansible variables using annotations. The following example shows: a posible pod definition for it to be considered as part of a CR inventory, to define a custom group membership and extra ansible variables:

apiVersion: v1
kind: Pod
metadata:
  annotations:
    # Define a variable for this pod only
    ansible.sdk.operatorframework.io/inventory_variable: '{"ansible_python_interpreter": "/usr/libexec/platform-python"}'
  labels:
    # Define a label to be included in an specific inventory.  
    ansible.sdk.operatorframework.io/inventory: "mynamespace/mysample"  
    # A default group for all pods could be <mynamespace>__<mysample>__pods
    # Define a custom group membership to <mynamespace>__<mysample>__<mygroup>__pods could be defined with:
    ansible.sdk.operatorframework.io/inventory_group: "mygroup"

The custom CR could be:

apiVersion: sample.example.com/v1alpha1
kind: Sample
metadata:
  name: mysample
  namespace: mynamespace
  annotations:
    # Define which label selector identify resources of this specific inventory for this CR.  
    ansible.sdk.operatorframework.io/inventory: "mynamespace/mysample"  
    # Define a variable for each pod
    ansible.sdk.operatorframework.io/inventory_variable: '{"ansible_remote_tmp": "/var/tmp/.ansible"}'

Using ansible to manage pods could be considered an anti-patter for k8s.

However, it could complement k8s where some functionality is lacking or to add some logic to an operator.

/language ansible

krestomatio-cibot referenced this issue in krestomatio/moodle-operator May 9, 2021
- filter pods using label selector infered from cwd
- only create groups for pods
- create subgroups for app.kubernetes.io labels
- add hostvars from annotation
- sanitize group names

https://github.com/operator-framework/operator-sdk/issues/4887
@estroz estroz added the kind/feature Categorizes issue or PR as related to a new feature. label May 10, 2021
@openshift-bot
Copy link

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci openshift-ci bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 8, 2021
@openshift-bot
Copy link

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci openshift-ci bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 8, 2021
@fabianvf
Copy link
Member

fabianvf commented Sep 8, 2021

/lifecycle frozen

@openshift-ci openshift-ci bot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Sep 8, 2021
@everettraven everettraven transferred this issue from operator-framework/operator-sdk Oct 5, 2023
@openshift-ci
Copy link

openshift-ci bot commented Oct 5, 2023

@jobcespedes: The label(s) language/ansible cannot be applied, because the repository doesn't have them.

In response to this:

Feature Request

Dynamic inventory of resources created by a CR of an ansible operator

Describe the problem you need a feature to resolve.

Operating or running ansible tasks over pods generated by a CR of an ansible operator is kind of cumbersome. One could use kubectl connection plugin and add them dynamically during each reconciliation loop using variables. The existing dynamic k8s inventory plugin could be a better fit. However, adding it to an ansible operator requires some steps. In addition, when done, it shows all the pods and services the operator has access and groups them in a way, in my opinion, not intuitive for the operator scope. They could not be filter, for instance.

Describe the solution you'd like.

The operator sdk to already include a dynamic inventory plugin that groups and adds only the pods, and optionally other kind of resources, of the CR the reconciliation loop is running. I would like to run some complementary ansible tasks over some of those pods. How it groups them should be intuitive in order to reference hosts, or groups more probably, in playbooks inside the operator. For instance: the name of a default group of all pods of a CR could be used as: hosts: {{ ansible_operator_meta.namespace }}__{{ ansible_operator_meta.namespace }}__pods. In addition, it would be helpful to define custom group formats using labels and add extra ansible variables using annotations. The following example shows: a posible pod definition for it to be considered as part of a CR inventory, to define a custom group membership and extra ansible variables:

apiVersion: v1
kind: Pod
metadata:
 annotations:
   # Define a variable for this pod only
   ansible.sdk.operatorframework.io/inventory_variable: '{"ansible_python_interpreter": "/usr/libexec/platform-python"}'
 labels:
   # Define a label to be included in an specific inventory.  
   ansible.sdk.operatorframework.io/inventory: "mynamespace/mysample"  
   # A default group for all pods could be <mynamespace>__<mysample>__pods
   # Define a custom group membership to <mynamespace>__<mysample>__<mygroup>__pods could be defined with:
   ansible.sdk.operatorframework.io/inventory_group: "mygroup"

The custom CR could be:

apiVersion: sample.example.com/v1alpha1
kind: Sample
metadata:
 name: mysample
 namespace: mynamespace
 annotations:
   # Define which label selector identify resources of this specific inventory for this CR.  
   ansible.sdk.operatorframework.io/inventory: "mynamespace/mysample"  
   # Define a variable for each pod
   ansible.sdk.operatorframework.io/inventory_variable: '{"ansible_remote_tmp": "/var/tmp/.ansible"}'

Using ansible to manage pods could be considered an anti-patter for k8s.

However, it could complement k8s where some functionality is lacking or to add some logic to an operator.

/language ansible

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

No branches or pull requests

4 participants