Skip to content

Commit

Permalink
Fixes for kube 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaroaleman committed Jun 4, 2019
1 parent 8180fe1 commit 1ad497c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 148 deletions.
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/azure/azure_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef) error {
return nil
}

glog.V(3).Infof("Deleting vmss instances %q", instances)
glog.V(3).Infof("Deleting vmss instances %v", instances)

commonAsg, err := scaleSet.manager.GetAsgForInstance(instances[0])
if err != nil {
Expand Down
65 changes: 0 additions & 65 deletions cluster-autoscaler/cloudprovider/builder/builder_all.go

This file was deleted.

42 changes: 0 additions & 42 deletions cluster-autoscaler/cloudprovider/builder/builder_clusterapi.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/azure"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/clusterapi"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/gce"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/kubemark"
"k8s.io/client-go/informers"
Expand All @@ -36,15 +37,11 @@ import (

// AvailableCloudProviders supported by the cloud provider builder.
var AvailableCloudProviders = []string{
aws.ProviderName,
azure.ProviderName,
gce.ProviderNameGCE,
gce.ProviderNameGKE,
kubemark.ProviderName,
clusterapi.ProviderName,
}

// DefaultCloudProvider is GCE.
const DefaultCloudProvider = gce.ProviderNameGCE
// DefaultCloudProvider for machineapi-only build.
const DefaultCloudProvider = clusterapi.ProviderName

// CloudProviderBuilder builds a cloud provider from all the necessary parameters including the name of a cloud provider e.g. aws, gce
// and the path to a config file
Expand All @@ -54,16 +51,18 @@ type CloudProviderBuilder struct {
clusterName string
autoprovisioningEnabled bool
regional bool
kubeconfigPath string
}

// NewCloudProviderBuilder builds a new builder from static settings
func NewCloudProviderBuilder(cloudProviderFlag, cloudConfig, clusterName string, autoprovisioningEnabled, regional bool) CloudProviderBuilder {
func NewCloudProviderBuilder(kubeconfigPath, cloudProviderFlag, cloudConfig, clusterName string, autoprovisioningEnabled, regional bool) CloudProviderBuilder {
return CloudProviderBuilder{
cloudProviderFlag: cloudProviderFlag,
cloudConfig: cloudConfig,
clusterName: clusterName,
autoprovisioningEnabled: autoprovisioningEnabled,
regional: regional,
kubeconfigPath: kubeconfigPath,
}
}

Expand All @@ -87,6 +86,8 @@ func (b CloudProviderBuilder) Build(discoveryOpts cloudprovider.NodeGroupDiscove
return b.buildAzure(discoveryOpts, resourceLimiter)
case kubemark.ProviderName:
return b.buildKubemark(discoveryOpts, resourceLimiter)
case clusterapi.ProviderName:
return clusterapi.BuildClusterAPI(b.kubeconfigPath, discoveryOpts, resourceLimiter)
case "":
// Ideally this would be an error, but several unit tests of the
// StaticAutoscaler depend on this behaviour.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
schedulercache "k8s.io/kubernetes/pkg/scheduler/cache"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
)
Expand Down Expand Up @@ -168,20 +168,12 @@ func (ng *nodegroup) Debug() string {
}

// Nodes returns a list of all nodes that belong to this node group.
func (ng *nodegroup) Nodes() ([]cloudprovider.Instance, error) {
func (ng *nodegroup) Nodes() ([]string, error) {
nodes, err := ng.scalableResource.Nodes()
if err != nil {
return nil, err
}

instances := make([]cloudprovider.Instance, len(nodes))
for i := range nodes {
instances[i] = cloudprovider.Instance{
Id: nodes[i],
}
}

return instances, nil
return nodes, nil
}

// TemplateNodeInfo returns a schedulercache.NodeInfo structure of an
Expand All @@ -192,7 +184,7 @@ func (ng *nodegroup) Nodes() ([]cloudprovider.Instance, error) {
// allocatable information as well as all pods that are started on the
// node by default, using manifest (most likely only kube-proxy).
// Implementation optional.
func (ng *nodegroup) TemplateNodeInfo() (*schedulernodeinfo.NodeInfo, error) {
func (ng *nodegroup) TemplateNodeInfo() (*schedulercache.NodeInfo, error) {
return nil, cloudprovider.ErrNotImplemented
}

Expand All @@ -205,8 +197,8 @@ func (ng *nodegroup) Exist() bool {

// Create creates the node group on the cloud nodegroup side.
// Implementation optional.
func (ng *nodegroup) Create() (cloudprovider.NodeGroup, error) {
return nil, cloudprovider.ErrAlreadyExist
func (ng *nodegroup) Create() error {
return cloudprovider.ErrAlreadyExist
}

// Delete deletes the node group on the cloud nodegroup side. This will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestNodeGroupNewNodeGroupConstructor(t *testing.T) {
t.Errorf("expected %t, got %t", true, exists)
}

if _, err := ng.Create(); err != cloudprovider.ErrAlreadyExist {
if err := ng.Create(); err != cloudprovider.ErrAlreadyExist {
t.Error("expected error")
}

Expand Down Expand Up @@ -623,12 +623,12 @@ func TestNodeGroupDeleteNodes(t *testing.T) {
}

sort.SliceStable(nodeNames, func(i, j int) bool {
return nodeNames[i].Id < nodeNames[j].Id
return nodeNames[i] < nodeNames[j]
})

for i := 0; i < len(nodeNames); i++ {
if nodeNames[i].Id != testConfig.nodes[i].Spec.ProviderID {
t.Fatalf("expected %q, got %q", testConfig.nodes[i].Spec.ProviderID, nodeNames[i].Id)
if nodeNames[i] != testConfig.nodes[i].Spec.ProviderID {
t.Fatalf("expected %q, got %q", testConfig.nodes[i].Spec.ProviderID, nodeNames[i])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ package clusterapi
import (
"reflect"

"github.com/golang/glog"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
clusterclientset "k8s.io/autoscaler/cluster-autoscaler/client/clusterapi/clientset/versioned"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/autoscaler/cluster-autoscaler/utils/errors"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
clusterclientset "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
)

const (
Expand Down Expand Up @@ -132,11 +131,11 @@ func newProvider(
}

// BuildClusterAPI builds CloudProvider implementation for machine api.
func BuildClusterAPI(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider {
func BuildClusterAPI(kubeconfigPath string, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider {
var err error
var config *rest.Config

config, err = clientcmd.BuildConfigFromFlags("", opts.KubeConfigPath)
config, err = clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
klog.Fatalf("cannot build config: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,4 @@ func TestProviderConstructorProperties(t *testing.T) {
t.Fatalf("unexpected nodegroup: %v", ng.Id())
}

if got := provider.GPULabel(); got != GPULabel {
t.Fatalf("expected %q, got %q", GPULabel, got)
}

if got := len(provider.GetAvailableGPUTypes()); got != 0 {
t.Fatalf("expected 0 GPU types, got %d", got)
}
}
5 changes: 3 additions & 2 deletions cluster-autoscaler/context/autoscaling_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ type AutoscalingOptions struct {
// Pods with null priority (PodPriority disabled) are non-expendable.
ExpendablePodsPriorityCutoff int
// Regional tells whether the cluster is regional.
Regional bool
Regional bool
KubeConfigPath string
}

// NewResourceLimiterFromAutoscalingOptions creates new instance of cloudprovider.ResourceLimiter
Expand All @@ -170,7 +171,7 @@ func NewAutoscalingContext(options AutoscalingOptions, predicateChecker *simulat
kubeClient kube_client.Interface, kubeEventRecorder kube_record.EventRecorder,
logEventRecorder *utils.LogEventRecorder, listerRegistry kube_util.ListerRegistry) (*AutoscalingContext, errors.AutoscalerError) {

cloudProviderBuilder := builder.NewCloudProviderBuilder(options.CloudProviderName, options.CloudConfig, options.ClusterName, options.NodeAutoprovisioningEnabled, options.Regional)
cloudProviderBuilder := builder.NewCloudProviderBuilder(options.KubeConfigPath, options.CloudProviderName, options.CloudConfig, options.ClusterName, options.NodeAutoprovisioningEnabled, options.Regional)
cloudProvider := cloudProviderBuilder.Build(cloudprovider.NodeGroupDiscoveryOptions{
NodeGroupSpecs: options.NodeGroups,
NodeGroupAutoDiscoverySpecs: options.NodeGroupAutoDiscovery},
Expand Down

0 comments on commit 1ad497c

Please sign in to comment.