-
Notifications
You must be signed in to change notification settings - Fork 1.8k
doc/proposal: Ansible Operator proposal #430
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
doc/proposal: Ansible Operator proposal #430
Conversation
* Describes how the library packages of ansible operator will be layed out * New commands to manage ansible operators.
| | - cr.yaml | ||
``` | ||
|
||
`operator-sdk generate crd <api-version> <kind> ` This will be used to generate new CRDs based on ansible code. The command helps when a user wants to watch more than one CRD for their operator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to have this functionality for the go operator as well. I think once we switch to controller runtime, we can do that for the go operator. The question I am having now is that how do we generate additional CRDs for both go type and ansible type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is already an operator-sdk generate k8s
which will generate the code for custom resources. The ansible only needs the CRD. Therefore I suggest that operator-sdk generate k8s
both generates the go structures and a CRD, while this command only generates the CRD.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while this command (operator-sdk generate crd <api-version> <kind>) only generates the CRD.
as long as it can generate a CRD regardless whether the operator is a Go one or Ansible one. I think this command makes sense.
doc/proposals/ansible-operator.md
Outdated
Flags: | ||
Optional: --defaults-file - A path to the defaults file to use to generate a new CRD.yaml. If this is not defined, then an empty CRD is created. | ||
|
||
`operator-sdk up ansible` - This should use the known structure and the ansible operator code to run the operator from this location. The command works by running the operator-sdk binary, which includes the ansible operator code, as the operator process. This is slightly different than the current up local command. For debugging a user could then set a flag --verbose which tells ansible to be more verbose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a bit thought. Currently, we have operator-sdk up local
to run test for go operator. Maybe we can have operator-sdk up local --type=ansible
to run ansible operator locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should discuss the up
command. Currently, it only has a local
subcommand. We should determine if what other uses of Up
there are and determine if another subcommand would be easier to use or an option on local
.
I didn't see another subcommand for up
so I am having a hard time seeing why another subcommand would be a problem here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see another subcommand for up so I am having a hard time seeing why another subcommand would be a problem here
Initially, we were thinking about add another command calling up remote
such that it can build the operator image, push it to a repo, and then runs it to a remote cluster as discussed here #142 (comment). I am unsure if that's relevant or not anymore. If it is still relevant, then we should group all the commands that uses the usr's computer as a local pod within up local
command. For instance, operator-sdk up local --type=Ansible
runs the ansible operator locally and operator-sdk up remote --type=Ansible
builds the ansible operator and deploys to a remote cluster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I have two thoughts
-
I don't want ansible operator developers to feel like a second-class citizen from the commands. The constant need to add type arguments worries me in this sense because we are not giving them a "default" way of running their code.
-
The idea of a "remote" command seems like a good idea. Your right that we would want the ansible operator to be used for that command as well.
I wonder if we could do something like:
operator-sdk up {local,remore}
- where the presence of a cmd
directory with a .go
file somewhere inside means we go run
, while the absence means we use ansible.
The only issue I worry about with this is a possible poor user experience if their project is in a very odd state. It might be hard for us to determine errors where if they are explicit we can do more error checking.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic detection can cause all sorts of problems. Also, assuming one when its not the other also doesn't scale when a 3rd option comes around. I'm for a little more typing that is always consistent. don't make go lang a special thing and just add a required, type flag = [go, ansible]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fanminshi Are you ok with this? I think I agree with @kfox1111
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shawn-hurley @kfox1111 I think we default the --type
flag to go
for backward compatibility. However, if user can use --type go
if they want to. In essence, we should have a --type
for all supported types but with the default to go
. That's my opinion on this. If we want to make the flag required, that can cause backward compatibility issue which is also something we can discuss about. I am not for breaking backward compatibility in general. Since the project is still in early stage, I am fine with it if everyone thinks it is a good idea.
doc/proposals/ansible-operator.md
Outdated
|
||
`operator-sdk build --type=ansible <image-name>` - This builds the operator image. The command calls ansible-galaxy install for the role dependencies and creates the image from the Dockerfile. | ||
|
||
`operator-sdk new --type ansible --hybrid` - This converts an ansible operator to a new hybrid operator. Hybrid operators allow the developer the ability to create a golang operator while still using the ansible operator code they have already written. This is intended for advanced users to allow developers full customization of their operator. The generated operator should now function the same as standard operator-sdk operators. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest changing this option from --hybrid
to --source
. The --source
option tells the command to include the source code for the ansible operator.
doc/proposals/ansible-operator.md
Outdated
|
||
`operator-sdk build --type=ansible <image-name>` - This builds the operator image. The command calls ansible-galaxy install for the role dependencies and creates the image from the Dockerfile. | ||
|
||
`operator-sdk new --type ansible --source` - This converts an ansible operator to a ansible operator. A user can now change the base ansible operator. This will also allow users to continue using their ansible code while also using the operator-sdk. This is intended for advanced users to allow developers full customization of their operator. The generated operator should now function the same as standard operator-sdk operators. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This converts an ansible operator to a ansible operator
Can we reword and clarify this statement a bit?
Does this mean we run operator-sdk new --type ansible --source
inside the pure ansible type project previously generated by operator-sdk new --type ansible --kind=<kind> --apiversion<group/version>
to convert it to a hybrid type.
Adds clarification about the `--source` command.
lgtm |
Packages will be added to the operator-sdk. These packages are designed to be usable by the end user if they choose to and should have a well documented public API. The proposed packages are: | ||
* /operator-sdk/pkg/ansible/controller | ||
* Will contain the ansible operator controller. | ||
* Will contain a exposed reconciler. But the default `Add` method will use this reconciler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the default
Add
method will use this reconciler
@shawn-hurley Just so I understand this correctly, this controller is expected to be added to the manager in the hybrid case right?
likely in cmd/manager/main.go:
import ac "github.com/operator-framework/operator-sdk/pkg/ansible/controller"
...
// Add the manage
ac.Add(mgr, ac.Options{...})
So users can either call Add()
to add the default ansible controller to their manager.
Or create their own controller and use the default reconciler (AnsibleOperatorReconciler
from #461 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*an exposed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad I just realized this controller pkg is being used by up local
's manager to run the ansible-operator locally.
Although this can still be used in the hybrid case as well I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hasbro17 that is what we are thinking as well +1
doc/proposals/ansible-operator.md
Outdated
### Commands | ||
We are adding and updating existing commands to accommodate the ansible operator. Changes to the `cmd` package as well as changes to the generator are needed. | ||
|
||
`operator-sdk new --type ansible --kind <kind> --api-version <group/version>` This will be a new generation command under the hood. We will: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit but this would be:
operator-sdk new <project-name> --type ansible --kind <kind> --api-version <group/version>
if we keep the same behavior of operator-sdk new
creating a new project directory.
Optional: --defaults-file - A path to the defaults file to use to generate a new CRD.yaml. If this is not defined, then an empty CRD is created. | ||
|
||
`operator-sdk up local` - This should use the known structure and the ansible operator code to run the operator from this location. This will need to be changed to determine if it is an ansible operator or a golang operator. The command works by running the operator-sdk binary, which includes the ansible operator code, as the operator process. This is slightly different than the current up local command. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
running the operator-sdk binary, which includes the ansible operator code
Sorry if I'm rehashing this again but how exactly does the operator-sdk run the user's local ansible code?
In a Golang project it would just run the main entry point from the local project exec.Command("go run cmd/manager/main.go")
.
And for a pure ansible project up local
is just going to run the main function inside its own process right? i.e start a new manager, read the local watches.yaml and create a controller for each gvk.
Basically up local
would run this internally.
https://github.com/water-hole/ansible-operator/blob/master/cmd/ansible-operator/main.go#L29-L78
Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a pure ansible operator, up local
would run the code you linked to, which would be already compiled into the operator-sdk
binary.
In a "hybrid" operator, up local
would just treat it like any other golang operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct!
LGTM |
\ | - <kind> | ||
| \ | - generated ansible role | ||
| | ||
| - watchers.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shawn-hurley shouldn't this be watches.yaml
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, oops 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool.. thought it was me :)
will be layed out