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

Broker client dao #795

Merged
merged 9 commits into from
Mar 1, 2018
Merged

Conversation

shawn-hurley
Copy link
Contributor

@shawn-hurley shawn-hurley commented Feb 26, 2018

Describe what this PR does and why we need it:
Implements Broker client dao.
Changes proposed in this pull request

  • Adds a config value for CRD dao
  • Adds implementation for conversion and dao from CRD to apb package structures

Does this PR depend on another PR (Use this to track when PRs should be merged)
depends-on
#775
#794

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 26, 2018
@shawn-hurley shawn-hurley added the 3.10 | release-1.2 Kubernetes 1.10 | Openshift 3.10 | Broker release-1.2 label Feb 26, 2018
@shawn-hurley shawn-hurley force-pushed the broker-client-dao branch 2 times, most recently from 989c992 to 7193d52 Compare February 28, 2018 14:35
@shawn-hurley shawn-hurley changed the title [WIP] - Broker client dao Broker client dao Feb 28, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 28, 2018
@eriknelson
Copy link
Contributor

@shawn-hurley merged both blocker PRs, so this should be good for a rebase.

Copy link
Contributor

@jmrodri jmrodri left a 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) {
Copy link
Contributor

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
}
Copy link
Contributor

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" {
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

OMG

- apiGroups: ["automationbroker.io"]
attributeRestrictions: null
resources: ["bundles", "jobstates", "servicebindings", "serviceinstances"]
verbs: ["*"]
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG

Copy link
Contributor

@eriknelson eriknelson left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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"
Copy link
Contributor

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.

log.Errorf("unable to get bundle from k8s api - %v", err)
return nil, err
}
return bundleToSpec(s.Spec, s.GetName()), nil
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateing -> updating

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))
Copy link
Contributor

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 {
Copy link
Contributor

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.

@shawn-hurley
Copy link
Contributor Author

@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.

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{}
Copy link
Contributor

@maleck13 maleck13 Feb 27, 2018

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)
Copy link
Contributor

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

Spec: spec,
}
_, err := d.client.ServiceInstances(d.namespace).Create(&s)
if err != nil {
Copy link
Contributor

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.

Copy link
Contributor

@eriknelson eriknelson left a 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.

@eriknelson
Copy link
Contributor

eriknelson commented Mar 1, 2018

I've been banging on this for the last hour, make ci is good, I ran through a number of scenarios I know were potential trouble cases, it's handling them fine. I can also read the resources with oc get, which is actually making this much more friendly for broker developers debugging compared to raw etcd. Big +1, nice work @shawn-hurley.

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.

@jmrodri
Copy link
Contributor

jmrodri commented Mar 1, 2018

@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.

@eriknelson
Copy link
Contributor

eriknelson commented Mar 1, 2018 via email

Copy link
Contributor

@maleck13 maleck13 left a 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!

@shawn-hurley shawn-hurley merged commit 6b5cf4b into openshift:master Mar 1, 2018
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 | release-1.2 Kubernetes 1.10 | Openshift 3.10 | Broker release-1.2 needs-review size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants