Skip to content

Commit

Permalink
adjust code for k8s 1.8 dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinyv committed Nov 29, 2017
1 parent 229dc87 commit a78ca2f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
29 changes: 29 additions & 0 deletions qingcloud/qingcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package qingcloud
// and must pay attention to your account resource quota limit.

import (
"errors"
"fmt"
"io"

Expand All @@ -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"
)
Expand Down Expand Up @@ -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")
}
16 changes: 8 additions & 8 deletions qingcloud/qingcloud_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ 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.
func (qc *QingCloud) NodeAddresses(nodeName types.NodeName) ([]v1.NodeAddress, error) {
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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion qingcloud/qingcloud_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion qingcloud/qingcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion qingcloud/qingcloud_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit a78ca2f

Please sign in to comment.