diff --git a/qingcloud/qingcloud.go b/qingcloud/qingcloud.go index 9f8772b7a..94e8f345c 100644 --- a/qingcloud/qingcloud.go +++ b/qingcloud/qingcloud.go @@ -4,6 +4,7 @@ package qingcloud // and must pay attention to your account resource quota limit. import ( + "errors" "fmt" "io" @@ -14,6 +15,7 @@ import ( "github.com/golang/glog" qcconfig "github.com/yunify/qingcloud-sdk-go/config" qcservice "github.com/yunify/qingcloud-sdk-go/service" + "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/cloudprovider" "k8s.io/kubernetes/pkg/controller" ) @@ -174,3 +176,30 @@ func getHostname() (string, error) { } return string(content), nil } + +// HasClusterID returns true if the cluster has a clusterID +func (qc *QingCloud) HasClusterID() bool { + return false +} + +// GetZoneByNodeName implements Zones.GetZoneByNodeName +// This is particularly useful in external cloud providers where the kubelet +// does not initialize node data. +func (qc *QingCloud) GetZoneByNodeName(nodeName types.NodeName) (cloudprovider.Zone, error) { + glog.V(4).Infof("GetZoneByNodeName() called, current zone is %v, and return zone directly as temporary solution", qc.zone) + return cloudprovider.Zone{Region: qc.zone}, nil +} + +// GetZoneByProviderID implements Zones.GetZoneByProviderID +// This is particularly useful in external cloud providers where the kubelet +// does not initialize node data. +func (qc *QingCloud) GetZoneByProviderID(providerID string) (cloudprovider.Zone, error) { + glog.V(4).Infof("GetZoneByProviderID() called, current zone is %v, and return zone directly as temporary solution", qc.zone) + return cloudprovider.Zone{Region: qc.zone}, nil +} + +// 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 (qc *QingCloud) InstanceExistsByProviderID(providerID string) (bool, error) { + return false, errors.New("unimplemented") +} diff --git a/qingcloud/qingcloud_instances.go b/qingcloud/qingcloud_instances.go index 376fb4b5d..e52c8ef0c 100644 --- a/qingcloud/qingcloud_instances.go +++ b/qingcloud/qingcloud_instances.go @@ -7,9 +7,9 @@ import ( "github.com/golang/glog" qcservice "github.com/yunify/qingcloud-sdk-go/service" - "k8s.io/kubernetes/pkg/cloudprovider" + "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/kubernetes/pkg/api/v1" + "k8s.io/kubernetes/pkg/cloudprovider" ) // NodeAddresses returns the addresses of the specified instance. @@ -17,7 +17,7 @@ func (qc *QingCloud) NodeAddresses(nodeName types.NodeName) ([]v1.NodeAddress, e return qc.instanceAddress(NodeNameToInstanceID(nodeName)) } -func (qc *QingCloud) NodeAddressesByProviderID(providerId string) ([]v1.NodeAddress, error){ +func (qc *QingCloud) NodeAddressesByProviderID(providerId string) ([]v1.NodeAddress, error) { return qc.instanceAddress(providerId) } @@ -60,7 +60,7 @@ func (qc *QingCloud) InstanceType(name types.NodeName) (string, error) { return qc.instanceType(NodeNameToInstanceID(name)) } -func (qc *QingCloud) InstanceTypeByProviderID(providerID string) (string, error){ +func (qc *QingCloud) InstanceTypeByProviderID(providerID string) (string, error) { return qc.instanceType(providerID) } @@ -104,7 +104,7 @@ func (qc *QingCloud) CurrentNodeName(hostname string) (types.NodeName, error) { return types.NodeName(hostname), nil } -func (qc *QingCloud) GetSelf() (*qcservice.Instance) { +func (qc *QingCloud) GetSelf() *qcservice.Instance { return qc.selfInstance } @@ -118,9 +118,9 @@ func (qc *QingCloud) GetInstanceByID(instanceID string) (*qcservice.Instance, er status := []*string{qcservice.String("pending"), qcservice.String("running"), qcservice.String("stopped")} verbose := qcservice.Int(1) output, err := qc.instanceService.DescribeInstances(&qcservice.DescribeInstancesInput{ - Instances: []*string{&instanceID}, - Status: status, - Verbose: verbose, + Instances: []*string{&instanceID}, + Status: status, + Verbose: verbose, IsClusterNode: qcservice.Int(1), }) if err != nil { diff --git a/qingcloud/qingcloud_loadbalancer.go b/qingcloud/qingcloud_loadbalancer.go index 4c1051edf..f2fbf3e03 100644 --- a/qingcloud/qingcloud_loadbalancer.go +++ b/qingcloud/qingcloud_loadbalancer.go @@ -16,9 +16,9 @@ import ( "github.com/golang/glog" qcclient "github.com/yunify/qingcloud-sdk-go/client" qcservice "github.com/yunify/qingcloud-sdk-go/service" + "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/cloudprovider" ) diff --git a/qingcloud/qingcloud_test.go b/qingcloud/qingcloud_test.go index e9867eede..0d499461f 100644 --- a/qingcloud/qingcloud_test.go +++ b/qingcloud/qingcloud_test.go @@ -11,8 +11,8 @@ import ( "encoding/json" qcservice "github.com/yunify/qingcloud-sdk-go/service" + "k8s.io/api/core/v1" machineryv1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/api/v1" ) func getMockupQingCloud() (*qcservice.DescribeLoadBalancersOutput, *qcservice.DescribeLoadBalancerListenersOutput, error) { diff --git a/qingcloud/qingcloud_util.go b/qingcloud/qingcloud_util.go index 79e30daa8..3ab52acb2 100644 --- a/qingcloud/qingcloud_util.go +++ b/qingcloud/qingcloud_util.go @@ -3,8 +3,8 @@ package qingcloud import ( "time" + "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/kubernetes/pkg/api/v1" ) const (