Skip to content

Commit

Permalink
Merge pull request #398 from robbrockbank/fix-kdd-get-node
Browse files Browse the repository at this point in the history
Don't use compat module for KDD datastore
  • Loading branch information
fasaxc authored Apr 20, 2017
2 parents 0a0ff81 + eb081bb commit 341b130
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 41 deletions.
17 changes: 10 additions & 7 deletions lib/backend/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ func NewClient(config api.CalicoAPIConfig) (c bapi.Client, err error) {
switch config.Spec.DatastoreType {
case api.EtcdV2:
c, err = etcd.NewEtcdClient(&config.Spec.EtcdConfig)
if c != nil {
// Wrap the backend, which deals only in raw KV pairs with an
// adaptor that handles aggregate datatypes. This allows for
// reading and writing Profile and Node objects, which for etcdv2
// are composed of multiple backend keys.
//
// This is only required for etcdv2 backend as Kuberenetes driver
// uses the composite Profile and Node KV types.
c = compat.NewAdaptor(c)
}
case api.Kubernetes:
c, err = k8s.NewKubeClient(&config.Spec.KubeConfig)
default:
err = errors.New(fmt.Sprintf("Unknown datastore type: %v",
config.Spec.DatastoreType))
}
if c != nil {
// Wrap the backend, which deals only in raw KV pairs with an
// adaptor that handles aggregate datatypes. This allows for
// reading and writing Profile objects, which are composed
// of multiple backend keys.
c = compat.NewAdaptor(c)
}
return
}
27 changes: 0 additions & 27 deletions lib/backend/compat/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ func (c *ModelAdaptor) Update(d *model.KVPair) (*model.KVPair, error) {
return d, nil
}
case model.NodeKey:
// Quick fix for k8s Node call. The k8s Node.Update call requires a complete model.Node object,
// therefore we do not need to break down the node object.
node, err := c.client.Update(d); if err == nil {
return node, nil
}

p, o := toNodeComponents(d)
if p, err = c.client.Update(p); err != nil {
return nil, err
Expand Down Expand Up @@ -150,12 +144,6 @@ func (c *ModelAdaptor) Apply(d *model.KVPair) (*model.KVPair, error) {
return d, nil
}
case model.NodeKey:
// Quick fix for k8s Node call. The k8s Node.Apply call requires a complete model.Node object,
// therefore we do not need to break down the node object. The etcd API will raise an error
// if we try to hand it the composite object, hence we then try to apply the separate components.
node, err := c.client.Apply(d); if err == nil {
return node, nil
}
p, o := toNodeComponents(d)
if p, err = c.client.Apply(p); err != nil {
return nil, err
Expand Down Expand Up @@ -278,12 +266,6 @@ func (c *ModelAdaptor) getBlock(k model.Key) (*model.KVPair, error) {
func (c *ModelAdaptor) getNode(nk model.NodeKey) (*model.KVPair, error) {
var err error

// Quick fix for k8s Node call. The k8s Node.Get call returns a complete model.Node object, therefore we do
// not need to find each piece individually.
node, err := c.client.Get(nk); if err == nil {
return node, nil
}

// Fill in the Metadata specific part of the node configuration. At the
// moment, there is nothing to fill in.
if _, err = c.client.Get(model.HostMetadataKey{nk.Hostname}); err != nil {
Expand Down Expand Up @@ -314,15 +296,6 @@ func validateBlockValue(kvp *model.KVPair) error {
// because of the way we do our list queries - we'll enumerate all endpoints on
// host as well!
func (c *ModelAdaptor) listNodes(l model.NodeListOptions) ([]*model.KVPair, error) {
// The k8s List returns the complete list and values we're interested in, so we make a
// call and check if the list has anything in it, returning if it does.
nodes, err := c.client.List(l)
if err != nil {
return nil, err
} else if len(nodes) > 0 {
return nodes, nil
}

hml := model.HostMetadataListOptions{Hostname: l.Hostname}
hmr, err := c.client.List(hml)
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions lib/backend/model/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@ type ProfileRules struct {
OutboundRules []Rule `json:"outbound_rules,omitempty" validate:"omitempty,dive"`
}

type client interface {
Create(object *KVPair) (*KVPair, error)
Update(object *KVPair) (*KVPair, error)
Apply(object *KVPair) (*KVPair, error)
Get(key Key) (*KVPair, error)
}

func (_ *ProfileListOptions) ListConvert(ds []*KVPair) []*KVPair {

profiles := make(map[string]*KVPair)
Expand Down

0 comments on commit 341b130

Please sign in to comment.