NodeGroupCreate for gce cloud provider
This commit is contained in:
parent
9a4c15daaa
commit
b172926b5e
|
|
@ -153,7 +153,7 @@ func (aws *awsCloudProvider) GetAvilableMachineTypes() ([]string, error) {
|
|||
|
||||
// NewNodeGroup builds a theoretical node group based on the node definition provided. The node group is not automatically
|
||||
// created on the cloud provider side. The node group is not returned by NodeGroups() until it is created.
|
||||
func (aws *awsCloudProvider) NewNodeGroup(name string, machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
func (aws *awsCloudProvider) NewNodeGroup(machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ type CloudProvider interface {
|
|||
// NewNodeGroup builds a theoretical node group based on the node definition provided. The node group is not automatically
|
||||
// created on the cloud provider side. The node group is not returned by NodeGroups() until it is created.
|
||||
// Implementation optional.
|
||||
NewNodeGroup(name string, machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (NodeGroup, error)
|
||||
NewNodeGroup(machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (NodeGroup, error)
|
||||
}
|
||||
|
||||
// ErrNotImplemented is returned if a method is not implemented.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package gce
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
|
|
@ -127,8 +128,31 @@ func (gce *GceCloudProvider) GetAvilableMachineTypes() ([]string, error) {
|
|||
|
||||
// NewNodeGroup builds a theoretical node group based on the node definition provided. The node group is not automatically
|
||||
// created on the cloud provider side. The node group is not returned by NodeGroups() until it is created.
|
||||
func (gce *GceCloudProvider) NewNodeGroup(name string, machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
func (gce *GceCloudProvider) NewNodeGroup(machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
nodePoolName := fmt.Sprintf("%s-%s-%d", nodeAutoprovisioningPrefix, machineType, time.Now().Unix())
|
||||
mig := &Mig{
|
||||
autoprovisioned: true,
|
||||
exist: false,
|
||||
nodePoolName: nodePoolName,
|
||||
GceRef: GceRef{
|
||||
Project: gce.gceManager.projectId,
|
||||
Zone: gce.gceManager.zone,
|
||||
Name: nodePoolName + "-temporary-mig",
|
||||
},
|
||||
minSize: minAutoprovisionedSize,
|
||||
maxSize: maxAutoprovisionedSize,
|
||||
spec: &autoprovisioningSpec{
|
||||
machineType: machineType,
|
||||
labels: labels,
|
||||
extraResources: extraResources,
|
||||
},
|
||||
gceManager: gce.gceManager,
|
||||
}
|
||||
_, err := gce.gceManager.templates.buildNodeFromAutoprovisioningSpec(mig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mig, nil
|
||||
}
|
||||
|
||||
// GceRef contains s reference to some entity in GCE/GKE world.
|
||||
|
|
@ -158,7 +182,7 @@ func GceRefFromProviderId(id string) (*GceRef, error) {
|
|||
type autoprovisioningSpec struct {
|
||||
machineType string
|
||||
labels map[string]string
|
||||
extraResources map[string]string
|
||||
extraResources map[string]resource.Quantity
|
||||
}
|
||||
|
||||
// Mig implements NodeGroup interfrace.
|
||||
|
|
@ -299,7 +323,7 @@ func (mig *Mig) Exist() (bool, error) {
|
|||
// Create creates the node group on the cloud provider side.
|
||||
func (mig *Mig) Create() error {
|
||||
if !mig.exist && mig.autoprovisioned {
|
||||
return mig.gceManager.createNodePool(mig.spec)
|
||||
return mig.gceManager.createNodePool(mig)
|
||||
}
|
||||
return fmt.Errorf("Cannot create non-autoprovisioned node group")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,24 +285,22 @@ func (m *GceManager) deleteNodePool(toBeRemoved *Mig) error {
|
|||
return m.fetchAllNodePools()
|
||||
}
|
||||
|
||||
func (m *GceManager) createNodePool(spec *autoprovisioningSpec) error {
|
||||
func (m *GceManager) createNodePool(mig *Mig) error {
|
||||
m.assertGKE()
|
||||
|
||||
// TODO: handle preemptable
|
||||
// TODO: handle ssd
|
||||
// TODO: handle taints
|
||||
|
||||
nodePoolName := fmt.Sprintf("%s-%s-%d", nodeAutoprovisioningPrefix, spec.machineType, time.Now().Unix())
|
||||
|
||||
config := gke.NodeConfig{
|
||||
MachineType: spec.machineType,
|
||||
MachineType: mig.spec.machineType,
|
||||
OauthScopes: defaultOAuthScopes,
|
||||
Labels: spec.labels,
|
||||
Labels: mig.spec.labels,
|
||||
}
|
||||
|
||||
createRequest := gke.CreateNodePoolRequest{
|
||||
NodePool: &gke.NodePool{
|
||||
Name: nodePoolName,
|
||||
Name: mig.nodePoolName,
|
||||
InitialNodeCount: 0,
|
||||
Config: &config,
|
||||
},
|
||||
|
|
@ -317,7 +315,17 @@ func (m *GceManager) createNodePool(spec *autoprovisioningSpec) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.fetchAllNodePools()
|
||||
err = m.fetchAllNodePools()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, existingMig := range m.getMigs() {
|
||||
if existingMig.config.nodePoolName == mig.nodePoolName {
|
||||
*mig = *existingMig.config
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("node pool %s not found", mig.nodePoolName)
|
||||
}
|
||||
|
||||
// GetMigSize gets MIG size.
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func (kubemark *KubemarkCloudProvider) GetAvilableMachineTypes() ([]string, erro
|
|||
}
|
||||
|
||||
// NewNodeGroup builds a theoretical node group based on the node definition provided.
|
||||
func (kubemark *KubemarkCloudProvider) NewNodeGroup(name string, machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
func (kubemark *KubemarkCloudProvider) NewNodeGroup(machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,6 @@ func (kubemark *KubemarkCloudProvider) GetAvilableMachineTypes() ([]string, erro
|
|||
return []string{}, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (kubemark *KubemarkCloudProvider) NewNodeGroup(name string, machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
func (kubemark *KubemarkCloudProvider) NewNodeGroup(machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func (tcp *TestCloudProvider) GetAvilableMachineTypes() ([]string, error) {
|
|||
|
||||
// NewNodeGroup builds a theoretical node group based on the node definition provided. The node group is not automatically
|
||||
// created on the cloud provider side. The node group is not returned by NodeGroups() until it is created.
|
||||
func (tcp *TestCloudProvider) NewNodeGroup(name string, machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
func (tcp *TestCloudProvider) NewNodeGroup(machineType string, labels map[string]string, extraResources map[string]resource.Quantity) (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue