Skip to content

Commit

Permalink
Dont allow CRUD on clusterinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ozdanborne committed Apr 10, 2018
1 parent 4e01112 commit 9d503d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions calicoctl/resourcemgr/resourcemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/projectcalico/calicoctl/calicoctl/commands/argutils"
yamlsep "github.com/projectcalico/calicoctl/calicoctl/util/yaml"
yaml "github.com/projectcalico/go-yaml-wrapper"
api "github.com/projectcalico/libcalico-go/lib/apis/v3"
client "github.com/projectcalico/libcalico-go/lib/clientv3"
cerrors "github.com/projectcalico/libcalico-go/lib/errors"
validator "github.com/projectcalico/libcalico-go/lib/validator/v3"
Expand Down Expand Up @@ -151,6 +152,15 @@ func (rh resourceHelper) GetObjectType() reflect.Type {
// Apply is an un-typed method to apply (create or update) a resource. This calls Create
// and if the resource already exists then we call the Update method.
func (rh resourceHelper) Apply(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
// Block operations on ClusterInfo as calico/node is responsible for managing it.
if _, ok := resource.(*api.ClusterInformation); ok {
return nil, cerrors.ErrorOperationNotSupported{
Operation: "apply",
Identifier: "ClusterInformation",
Reason: "resource is readonly",
}
}

// Store the original ResourceVersion for the Update operation later.
originalRV := resource.(ResourceObject).GetObjectMeta().GetResourceVersion()

Expand Down
2 changes: 1 addition & 1 deletion tests/st/calicoctl/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def test_clusterinfo(self):
# Apply an update to the cluster information and assert not found (we need the node to
# create it).
rc = calicoctl("apply", data=clusterinfo_name1_rev2)
rc.assert_error(NOT_FOUND)
rc.assert_error(NOT_SUPPORTED)

# Delete the resource by name (i.e. without using a resource version) - assert not
# supported.
Expand Down

0 comments on commit 9d503d0

Please sign in to comment.