From 1339e4cffcd343fde2458c4e1b81e364d0060bbb Mon Sep 17 00:00:00 2001 From: Henrik Schmidt Date: Mon, 25 Sep 2017 14:28:49 +0200 Subject: [PATCH] Use custom error for "unimplemented" --- pkg/cloudprovider/cloud.go | 1 + pkg/cloudprovider/providers/aws/aws.go | 4 ++-- pkg/cloudprovider/providers/azure/azure_instances.go | 3 +-- pkg/cloudprovider/providers/fake/fake.go | 3 +-- pkg/cloudprovider/providers/gce/gce_instances.go | 3 +-- .../providers/openstack/openstack_instances.go | 5 ++--- pkg/cloudprovider/providers/ovirt/ovirt.go | 9 ++++----- pkg/cloudprovider/providers/photon/photon.go | 8 ++++---- pkg/cloudprovider/providers/vsphere/vsphere.go | 4 ++-- 9 files changed, 18 insertions(+), 22 deletions(-) diff --git a/pkg/cloudprovider/cloud.go b/pkg/cloudprovider/cloud.go index 9a60e5490e6..00479e9c5a0 100644 --- a/pkg/cloudprovider/cloud.go +++ b/pkg/cloudprovider/cloud.go @@ -176,6 +176,7 @@ type Routes interface { var ( InstanceNotFound = errors.New("instance not found") DiskNotFound = errors.New("disk is not found") + NotImplemented = errors.New("unimplemented") ) // Zone represents the location of a particular machine. diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 6a8df0e3ea5..65c360f7e09 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -618,7 +618,7 @@ func newEc2Filter(name string, values ...string) *ec2.Filter { // AddSSHKeyToAllInstances is currently not implemented. func (c *Cloud) AddSSHKeyToAllInstances(user string, keyData []byte) error { - return errors.New("unimplemented") + return cloudprovider.NotImplemented } // CurrentNodeName returns the name of the current node @@ -1152,7 +1152,7 @@ func (c *Cloud) ExternalID(nodeName types.NodeName) (string, error) { // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. func (c *Cloud) InstanceExistsByProviderID(providerID string) (bool, error) { - return false, errors.New("unimplemented") + return false, cloudprovider.NotImplemented } // InstanceID returns the cloud provider ID of the node with the specified nodeName. diff --git a/pkg/cloudprovider/providers/azure/azure_instances.go b/pkg/cloudprovider/providers/azure/azure_instances.go index 3d9d6447550..ea85388ca4a 100644 --- a/pkg/cloudprovider/providers/azure/azure_instances.go +++ b/pkg/cloudprovider/providers/azure/azure_instances.go @@ -17,7 +17,6 @@ limitations under the License. package azure import ( - "errors" "fmt" "k8s.io/api/core/v1" @@ -90,7 +89,7 @@ func (az *Cloud) ExternalID(name types.NodeName) (string, error) { // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. func (az *Cloud) InstanceExistsByProviderID(providerID string) (bool, error) { - return false, errors.New("unimplemented") + return false, cloudprovider.NotImplemented } func (az *Cloud) isCurrentInstance(name types.NodeName) (bool, error) { diff --git a/pkg/cloudprovider/providers/fake/fake.go b/pkg/cloudprovider/providers/fake/fake.go index f35f244ddba..5efc09a11bf 100644 --- a/pkg/cloudprovider/providers/fake/fake.go +++ b/pkg/cloudprovider/providers/fake/fake.go @@ -17,7 +17,6 @@ limitations under the License. package fake import ( - "errors" "fmt" "net" "regexp" @@ -191,7 +190,7 @@ func (f *FakeCloud) EnsureLoadBalancerDeleted(clusterName string, service *v1.Se } func (f *FakeCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error { - return errors.New("unimplemented") + return cloudprovider.NotImplemented } // Implementation of Instances.CurrentNodeName diff --git a/pkg/cloudprovider/providers/gce/gce_instances.go b/pkg/cloudprovider/providers/gce/gce_instances.go index 0d551a29dd0..f55b06d6c40 100644 --- a/pkg/cloudprovider/providers/gce/gce_instances.go +++ b/pkg/cloudprovider/providers/gce/gce_instances.go @@ -17,7 +17,6 @@ limitations under the License. package gce import ( - "errors" "fmt" "net" "net/http" @@ -157,7 +156,7 @@ func (gce *GCECloud) ExternalID(nodeName types.NodeName) (string, error) { // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. func (gce *GCECloud) InstanceExistsByProviderID(providerID string) (bool, error) { - return false, errors.New("unimplemented") + return false, cloudprovider.NotImplemented } // InstanceID returns the cloud provider ID of the node with the specified NodeName. diff --git a/pkg/cloudprovider/providers/openstack/openstack_instances.go b/pkg/cloudprovider/providers/openstack/openstack_instances.go index a9037117b25..fdfc3e7c214 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_instances.go +++ b/pkg/cloudprovider/providers/openstack/openstack_instances.go @@ -17,7 +17,6 @@ limitations under the License. package openstack import ( - "errors" "fmt" "regexp" @@ -59,7 +58,7 @@ func (i *Instances) CurrentNodeName(hostname string) (types.NodeName, error) { } func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error { - return errors.New("unimplemented") + return cloudprovider.NotImplemented } func (i *Instances) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) { @@ -113,7 +112,7 @@ func (i *Instances) ExternalID(name types.NodeName) (string, error) { // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. func (i *Instances) InstanceExistsByProviderID(providerID string) (bool, error) { - return false, errors.New("unimplemented") + return false, cloudprovider.NotImplemented } // InstanceID returns the kubelet's cloud provider ID. diff --git a/pkg/cloudprovider/providers/ovirt/ovirt.go b/pkg/cloudprovider/providers/ovirt/ovirt.go index d2559794126..e688257ad87 100644 --- a/pkg/cloudprovider/providers/ovirt/ovirt.go +++ b/pkg/cloudprovider/providers/ovirt/ovirt.go @@ -18,7 +18,6 @@ package ovirt import ( "encoding/xml" - "errors" "fmt" "io" "io/ioutil" @@ -192,7 +191,7 @@ func (v *OVirtCloud) NodeAddresses(nodeName types.NodeName) ([]v1.NodeAddress, e // This method will not be called from the node that is requesting this ID. i.e. metadata service // and other local methods cannot be used here func (v *OVirtCloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) { - return []v1.NodeAddress{}, errors.New("unimplemented") + return []v1.NodeAddress{}, cloudprovider.NotImplemented } // mapNodeNameToInstanceName maps from a k8s NodeName to an ovirt instance name (the hostname) @@ -214,7 +213,7 @@ func (v *OVirtCloud) ExternalID(nodeName types.NodeName) (string, error) { // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. func (v *OVirtCloud) InstanceExistsByProviderID(providerID string) (bool, error) { - return false, errors.New("unimplemented") + return false, cloudprovider.NotImplemented } // InstanceID returns the cloud provider ID of the node with the specified NodeName. @@ -233,7 +232,7 @@ func (v *OVirtCloud) InstanceID(nodeName types.NodeName) (string, error) { // This method will not be called from the node that is requesting this ID. i.e. metadata service // and other local methods cannot be used here func (v *OVirtCloud) InstanceTypeByProviderID(providerID string) (string, error) { - return "", errors.New("unimplemented") + return "", cloudprovider.NotImplemented } // InstanceType returns the type of the specified instance. @@ -321,5 +320,5 @@ func (v *OVirtCloud) CurrentNodeName(hostname string) (types.NodeName, error) { } func (v *OVirtCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error { - return errors.New("unimplemented") + return cloudprovider.NotImplemented } diff --git a/pkg/cloudprovider/providers/photon/photon.go b/pkg/cloudprovider/providers/photon/photon.go index 31734099786..7b9bc57e336 100644 --- a/pkg/cloudprovider/providers/photon/photon.go +++ b/pkg/cloudprovider/providers/photon/photon.go @@ -421,11 +421,11 @@ func (pc *PCCloud) NodeAddresses(nodeName k8stypes.NodeName) ([]v1.NodeAddress, // This method will not be called from the node that is requesting this ID. i.e. metadata service // and other local methods cannot be used here func (pc *PCCloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) { - return []v1.NodeAddress{}, errors.New("unimplemented") + return []v1.NodeAddress{}, cloudprovider.NotImplemented } func (pc *PCCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error { - return errors.New("unimplemented") + return cloudprovider.NotImplemented } func (pc *PCCloud) CurrentNodeName(hostname string) (k8stypes.NodeName, error) { @@ -473,7 +473,7 @@ func (pc *PCCloud) ExternalID(nodeName k8stypes.NodeName) (string, error) { // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. func (pc *PCCloud) InstanceExistsByProviderID(providerID string) (bool, error) { - return false, errors.New("unimplemented") + return false, cloudprovider.NotImplemented } // InstanceID returns the cloud provider ID of the specified instance. @@ -497,7 +497,7 @@ func (pc *PCCloud) InstanceID(nodeName k8stypes.NodeName) (string, error) { // This method will not be called from the node that is requesting this ID. i.e. metadata service // and other local methods cannot be used here func (pc *PCCloud) InstanceTypeByProviderID(providerID string) (string, error) { - return "", errors.New("unimplemented") + return "", cloudprovider.NotImplemented } func (pc *PCCloud) InstanceType(nodeName k8stypes.NodeName) (string, error) { diff --git a/pkg/cloudprovider/providers/vsphere/vsphere.go b/pkg/cloudprovider/providers/vsphere/vsphere.go index a6042e13d7e..580ea556f2a 100644 --- a/pkg/cloudprovider/providers/vsphere/vsphere.go +++ b/pkg/cloudprovider/providers/vsphere/vsphere.go @@ -354,7 +354,7 @@ func (vs *VSphere) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddres // AddSSHKeyToAllInstances add SSH key to all instances func (vs *VSphere) AddSSHKeyToAllInstances(user string, keyData []byte) error { - return errors.New("unimplemented") + return cloudprovider.NotImplemented } // CurrentNodeName gives the current node name @@ -380,7 +380,7 @@ func (vs *VSphere) ExternalID(nodeName k8stypes.NodeName) (string, error) { // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // If false is returned with no error, the instance will be immediately deleted by the cloud controller manager. func (vs *VSphere) InstanceExistsByProviderID(providerID string) (bool, error) { - return false, errors.New("unimplemented") + return false, cloudprovider.NotImplemented } // InstanceID returns the cloud provider ID of the node with the specified Name.