Skip to content

Commit

Permalink
Fix that get of host config returned nil instead of error. (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
fasaxc committed Feb 7, 2017
1 parent 645bc68 commit 1cb7a03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/backend/k8s/k8s.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Tigera, Inc. All rights reserved.
// Copyright (c) 2016-2017 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -718,10 +718,7 @@ func (c *KubeClient) deleteGlobalConfig(k *model.KVPair) error {
}

func (c *KubeClient) getHostConfig(k model.HostConfigKey) (*model.KVPair, error) {
return &model.KVPair{
Key: k,
Value: nil,
}, nil
return nil, errors.ErrorResourceDoesNotExist{Identifier: k}
}

func (c *KubeClient) listHostConfig(l model.HostConfigListOptions) ([]*model.KVPair, error) {
Expand Down
21 changes: 21 additions & 0 deletions lib/backend/k8s/k8s_fv_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright (c) 2016-2017 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package k8s

import (
Expand All @@ -10,6 +24,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/projectcalico/libcalico-go/lib/backend/api"
"github.com/projectcalico/libcalico-go/lib/backend/model"
"github.com/projectcalico/libcalico-go/lib/errors"
cnet "github.com/projectcalico/libcalico-go/lib/net"
k8sapi "k8s.io/client-go/pkg/api/v1"
extensions "k8s.io/client-go/pkg/apis/extensions/v1beta1"
Expand Down Expand Up @@ -344,6 +359,12 @@ var _ = Describe("Test Syncer API for Kubernetes backend", func() {
Expect(len(objs)).To(Equal(0))
})

It("should report ErrorResourceDoesNotExist for HostConfig", func() {
kv, err := c.Get(model.HostConfigKey{Hostname: "host", Name: "foo"})
Expect(kv).To(BeNil())
Expect(err).To(BeAssignableToTypeOf(errors.ErrorResourceDoesNotExist{}))
})

It("should support setting and getting GlobalConfig", func() {
gc := &model.KVPair{
Key: model.GlobalConfigKey{
Expand Down

0 comments on commit 1cb7a03

Please sign in to comment.