-
Notifications
You must be signed in to change notification settings - Fork 84
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
Broker client dao #795
Broker client dao #795
Conversation
989c992
to
7193d52
Compare
@shawn-hurley merged both blocker PRs, so this should be good for a rebase. |
7193d52
to
c979e27
Compare
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.
ACK
@@ -152,7 +151,7 @@ func NewAnsibleBroker(dao dao.Dao, | |||
func (a AnsibleBroker) GetServiceInstance(instanceUUID uuid.UUID) (apb.ServiceInstance, error) { | |||
instance, err := a.dao.GetServiceInstance(instanceUUID.String()) | |||
if err != nil { | |||
if client.IsKeyNotFound(err) { | |||
if a.dao.IsNotFoundError(err) { |
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.
+1 makes sense.
etcdClient, err := clients.Etcd() | ||
if err != nil { | ||
return err | ||
} |
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.
👍 took a while to figure out what really changed here, but it was the if statement that caused the indentation of the block of code. looks good.
if err != nil { | ||
return err | ||
} | ||
if strings.ToLower(c.GetString("dao.type")) != "crd" { |
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.
What happens if it isn't crd? What is the other valid value?
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.
All other values will mean we use etcd
. This is so every old config should still work as expected with etcd
as it's DAO.
bindingIds: | ||
type: array | ||
items: | ||
type: string |
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.
- apiGroups: ["automationbroker.io"] | ||
attributeRestrictions: null | ||
resources: ["bundles", "jobstates", "servicebindings", "serviceinstances"] | ||
verbs: ["*"] |
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.
👍
@@ -402,6 +406,242 @@ objects: | |||
${{BROKER_AUTH}} | |||
caBundle: ${BROKER_CA_CERT} | |||
|
|||
# CRDs for the broker. | |||
- apiVersion: apiextensions.k8s.io/v1beta1 |
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.
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 spelling nit and a few questions. We also need to file an issue over the mix between automation broker and ansible service broker. I also think we should add to the developer documentation some of the basics about the different storage backends, the basics of how to tweak CRDS (like if I want to add or remove a field), and how to get the code generated and into the broker's client go.
Overall looks great though.
We're also going to need to update CI to turn on the CRD backend, but only for PRs coming into master, is that possible? I'm running through regression tests with this now.
name: bundles.automationbroker.io | ||
spec: | ||
group: automationbroker.io | ||
version: v1 |
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.
Is there any reason to consider these v1alpha or v1beta?
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.
it is not possible to have more than 1 version for an API in CRDs so it is not like we could bump up and start using v1 and still have v1beta1 around. I think because of that, just make it easy and call them v1.
etcd "github.com/openshift/ansible-service-broker/pkg/dao/etcd" | ||
logutil "github.com/openshift/ansible-service-broker/pkg/util/logging" | ||
) | ||
|
||
var log = logutil.NewLog() | ||
|
||
// NewDao - Create a new Dao object | ||
func NewDao() (Dao, error) { | ||
func NewDao(c *config.Config) (Dao, error) { |
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 is great. 👍
import ( | ||
"fmt" | ||
|
||
automationbrokerv1 "github.com/automationbroker/broker-client-go/client/clientset/versioned/typed/automationbroker.io/v1" |
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'm concerned that we're starting to mix automationbroker
and ansible-service-broker
language now in the codebase. automationbroker
is the correct choice IMO, but I think we need to get this issue captured and start to move forward with the rebrand.
pkg/dao/crd/dao.go
Outdated
log.Errorf("unable to get bundle from k8s api - %v", err) | ||
return nil, err | ||
} | ||
return bundleToSpec(s.Spec, s.GetName()), nil |
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 it's expected that the dao layer will need to transform between the ASB types and their CRD counterparts for most of these, so the rest of the codebase is getting objects they expect?
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, that is the plan and what I was hoping to do here.
pkg/dao/crd/dao.go
Outdated
log.Debugf("set service instance: %v", id) | ||
spec := convertServiceInstanceToCRD(serviceInstance) | ||
if si, err := d.client.ServiceInstances(d.namespace).Get(id, metav1.GetOptions{}); err == nil { | ||
log.Debugf("updateing service instance: %v", id) |
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.
updateing
-> updating
pkg/dao/crd/dao.go
Outdated
j := convertJobStateToCRD(&state) | ||
if js, err := d.client.JobStates(d.namespace).Get(state.Token, metav1.GetOptions{}); err == nil { | ||
js.Spec = j | ||
js.ObjectMeta.Labels[jobStateLabel] = fmt.Sprintf("%v", convertStateToCRD(state.State)) |
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.
Why are we setting the labels here? Selector filtering? That's actually pretty slick.
@@ -333,6 +333,11 @@ func (d *Dao) GetStateByKey(key string) (apb.JobState, error) { | |||
return state, nil | |||
} | |||
|
|||
// IsNotFoundError - Will determine if an error is a key is not found error. | |||
func (d *Dao) IsNotFoundError(err error) bool { |
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.
Nice this got pushed into the dao.
@eriknelson as far as testing against CRDs on master branch. I am slightly worried about switching over to CRDs right now. Mostly, this has worked in my testing of the actions but I am gun shy. If someone else's tests and thinks it is good to go, then I say we change the default template to use crds. |
pkg/dao/crd/conversion.go
Outdated
b, err := json.Marshal(spec.Metadata) | ||
if err != nil { | ||
log.Errorf("unable to marshal the metadata for spec to a json byte array - %v", err) | ||
return v1.BundleSpec{} |
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 makes me a bit nervous that instead of failing on an error you may save just an empty BundleSpec without realizing it?
// BatchDeleteSpecs - set specs based on SpecManifest in the kvp API. | ||
func (d *Dao) BatchDeleteSpecs(specs []*apb.Spec) error { | ||
for _, spec := range specs { | ||
err := d.DeleteSpec(spec.ID) |
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.
Should we perhaps push errors into an array here to allow for other specs to delete. Then check the len of the array and return a new error with any errors that occurred. Or perhaps consider using something like multi error https://github.com/hashicorp/go-multierror
pkg/dao/crd/dao.go
Outdated
Spec: spec, | ||
} | ||
_, err := d.client.ServiceInstances(d.namespace).Create(&s) | ||
if err != nil { |
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 is really just a nit or point of discussion but should we consider just returning the error here and allowing the caller decide what to do with it, rather than logging it here, as what can happen is it gets logged here, then the caller logs it, then the callers caller logs it etc causing very noisy logs.
Some places in this file we do this and others we log the error before returning.
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.
Sorry @shawn-hurley I ack'd a little early, I just want to test it as well. Working on that tonight.
I've been banging on this for the last hour, We should start to think about when we want this to graduate to the default storage layer, and make sure when that happens, we've updated our various supported deployment efforts. |
@shawn-hurley Tested with my crash simulation patch (i.e. random adapter failing). I see that the bundles all get deleted and slowly populate as they get parsed. The final state was right, not sure if this is just being picky or not. |
I have scenarios I run knowing they were existing bugs. We should get these
captured in make ci somehow so they're always checked.
…On Feb 28, 2018 9:18 PM, "Jesus Rodriguez" ***@***.***> wrote:
@shawn-hurley <https://github.com/shawn-hurley> Tested with my crash
simulation patch (i.e. random adapter failing). I see that the bundles all
get deleted and slowly populate as they get parsed. The final state was
right, not sure if this is just being picky or not.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#795 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAZFNfEsoclsal66S17kvx520jjKCgg-ks5tZ1qNgaJpZM4STdBj>
.
|
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.
These changes look great!
* initial commit * adding DAO implementation for CRDs * adding CRDs to deploy template * adding CRDs to k8s templates. * working CRD dao implementation. * Implement error checking for IsNotFound error int he dao impl * implement errors returns for conversion methods
Describe what this PR does and why we need it:
Implements Broker client dao.
Changes proposed in this pull request
Does this PR depend on another PR (Use this to track when PRs should be merged)
depends-on
#775#794