Make Create() return newly created node group
This commit is contained in:
parent
4df8fe53d8
commit
90b67feff2
|
|
@ -179,8 +179,8 @@ func (ng *AwsNodeGroup) Exist() bool {
|
|||
}
|
||||
|
||||
// Create creates the node group on the cloud provider side.
|
||||
func (ng *AwsNodeGroup) Create() error {
|
||||
return cloudprovider.ErrAlreadyExist
|
||||
func (ng *AwsNodeGroup) Create() (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrAlreadyExist
|
||||
}
|
||||
|
||||
// Autoprovisioned returns true if the node group is autoprovisioned.
|
||||
|
|
|
|||
|
|
@ -96,8 +96,8 @@ func (as *AgentPool) Exist() bool {
|
|||
}
|
||||
|
||||
// Create creates the node group on the cloud provider side.
|
||||
func (as *AgentPool) Create() error {
|
||||
return cloudprovider.ErrAlreadyExist
|
||||
func (as *AgentPool) Create() (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrAlreadyExist
|
||||
}
|
||||
|
||||
// Delete deletes the node group on the cloud provider side.
|
||||
|
|
|
|||
|
|
@ -461,8 +461,8 @@ func (agentPool *ContainerServiceAgentPool) Exist() bool {
|
|||
|
||||
//Create is returns already exists since we don't support the
|
||||
//agent pool creation.
|
||||
func (agentPool *ContainerServiceAgentPool) Create() error {
|
||||
return cloudprovider.ErrAlreadyExist
|
||||
func (agentPool *ContainerServiceAgentPool) Create() (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrAlreadyExist
|
||||
}
|
||||
|
||||
//Delete is not implemented since we don't support agent pool
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ func (scaleSet *ScaleSet) Exist() bool {
|
|||
}
|
||||
|
||||
// Create creates the node group on the cloud provider side.
|
||||
func (scaleSet *ScaleSet) Create() error {
|
||||
return cloudprovider.ErrAlreadyExist
|
||||
func (scaleSet *ScaleSet) Create() (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrAlreadyExist
|
||||
}
|
||||
|
||||
// Delete deletes the node group on the cloud provider side.
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ type NodeGroup interface {
|
|||
Exist() bool
|
||||
|
||||
// Create creates the node group on the cloud provider side. Implementation optional.
|
||||
Create() error
|
||||
Create() (NodeGroup, error)
|
||||
|
||||
// Delete deletes the node group on the cloud provider side.
|
||||
// This will be executed only for autoprovisioned node groups, once their size drops to 0.
|
||||
|
|
|
|||
|
|
@ -379,11 +379,11 @@ func (mig *Mig) Exist() bool {
|
|||
}
|
||||
|
||||
// Create creates the node group on the cloud provider side.
|
||||
func (mig *Mig) Create() error {
|
||||
func (mig *Mig) Create() (cloudprovider.NodeGroup, error) {
|
||||
if !mig.exist && mig.autoprovisioned {
|
||||
return mig.gceManager.createNodePool(mig)
|
||||
}
|
||||
return fmt.Errorf("Cannot create non-autoprovisioned node group")
|
||||
return nil, fmt.Errorf("Cannot create non-autoprovisioned node group")
|
||||
}
|
||||
|
||||
// Delete deletes the node group on the cloud provider side.
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ func (m *gceManagerMock) getMigs() []*migInformation {
|
|||
return args.Get(0).([]*migInformation)
|
||||
}
|
||||
|
||||
func (m *gceManagerMock) createNodePool(mig *Mig) error {
|
||||
func (m *gceManagerMock) createNodePool(mig *Mig) (*Mig, error) {
|
||||
args := m.Called(mig)
|
||||
return args.Error(0)
|
||||
return mig, args.Error(0)
|
||||
}
|
||||
|
||||
func (m *gceManagerMock) deleteNodePool(toBeRemoved *Mig) error {
|
||||
|
|
@ -430,7 +430,7 @@ func TestMig(t *testing.T) {
|
|||
// Test Create.
|
||||
mig1.exist = false
|
||||
gceManagerMock.On("createNodePool", mock.AnythingOfType("*gce.Mig")).Return(nil).Once()
|
||||
err = mig1.Create()
|
||||
_, err = mig1.Create()
|
||||
assert.NoError(t, err)
|
||||
mock.AssertExpectationsForObjects(t, gceManagerMock)
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ type GceManager interface {
|
|||
// Cleanup cleans up open resources before the cloud provider is destroyed, i.e. go routines etc.
|
||||
Cleanup() error
|
||||
getMigs() []*migInformation
|
||||
createNodePool(mig *Mig) error
|
||||
createNodePool(mig *Mig) (*Mig, error)
|
||||
deleteNodePool(toBeRemoved *Mig) error
|
||||
getLocation() string
|
||||
getProjectId() string
|
||||
|
|
@ -408,24 +408,23 @@ func (m *gceManagerImpl) deleteNodePool(toBeRemoved *Mig) error {
|
|||
return m.refreshNodePools()
|
||||
}
|
||||
|
||||
func (m *gceManagerImpl) createNodePool(mig *Mig) error {
|
||||
func (m *gceManagerImpl) createNodePool(mig *Mig) (*Mig, error) {
|
||||
m.assertGKENAP()
|
||||
|
||||
err := m.GkeService.CreateNodePool(mig)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
err = m.refreshNodePools()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
for _, existingMig := range m.getMigs() {
|
||||
if existingMig.config.nodePoolName == mig.nodePoolName {
|
||||
*mig = *existingMig.config
|
||||
return nil
|
||||
return existingMig.config, nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("node pool %s not found", mig.nodePoolName)
|
||||
return nil, fmt.Errorf("node pool %s not found", mig.nodePoolName)
|
||||
}
|
||||
|
||||
func (m *gceManagerImpl) fetchMachinesCache() error {
|
||||
|
|
|
|||
|
|
@ -738,8 +738,9 @@ func TestCreateNodePool(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := g.createNodePool(mig)
|
||||
newMig, err := g.createNodePool(mig)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, newMig.Exist())
|
||||
migs := g.getMigs()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, len(migs))
|
||||
|
|
|
|||
|
|
@ -250,8 +250,8 @@ func (nodeGroup *NodeGroup) Exist() bool {
|
|||
}
|
||||
|
||||
// Create creates the node group on the cloud provider side.
|
||||
func (nodeGroup *NodeGroup) Create() error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
func (nodeGroup *NodeGroup) Create() (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
// Delete deletes the node group on the cloud provider side.
|
||||
|
|
|
|||
|
|
@ -169,11 +169,10 @@ func (tcp *TestCloudProvider) AddNodeGroup(id string, min int, max int, size int
|
|||
}
|
||||
|
||||
// AddAutoprovisionedNodeGroup adds node group to test cloud provider.
|
||||
func (tcp *TestCloudProvider) AddAutoprovisionedNodeGroup(id string, min int, max int, size int, machineType string) {
|
||||
func (tcp *TestCloudProvider) AddAutoprovisionedNodeGroup(id string, min int, max int, size int, machineType string) *TestNodeGroup {
|
||||
tcp.Lock()
|
||||
defer tcp.Unlock()
|
||||
|
||||
tcp.groups[id] = &TestNodeGroup{
|
||||
nodeGroup := &TestNodeGroup{
|
||||
cloudProvider: tcp,
|
||||
id: id,
|
||||
minSize: min,
|
||||
|
|
@ -183,6 +182,8 @@ func (tcp *TestCloudProvider) AddAutoprovisionedNodeGroup(id string, min int, ma
|
|||
autoprovisioned: true,
|
||||
machineType: machineType,
|
||||
}
|
||||
tcp.groups[id] = nodeGroup
|
||||
return nodeGroup
|
||||
}
|
||||
|
||||
// AddNode adds the given node to the group.
|
||||
|
|
@ -282,12 +283,12 @@ func (tng *TestNodeGroup) Exist() bool {
|
|||
}
|
||||
|
||||
// Create creates the node group on the cloud provider side.
|
||||
func (tng *TestNodeGroup) Create() error {
|
||||
func (tng *TestNodeGroup) Create() (cloudprovider.NodeGroup, error) {
|
||||
if tng.Exist() {
|
||||
return fmt.Errorf("Group already exist")
|
||||
return nil, fmt.Errorf("Group already exist")
|
||||
}
|
||||
tng.cloudProvider.AddAutoprovisionedNodeGroup(tng.id, tng.minSize, tng.maxSize, 0, tng.machineType)
|
||||
return tng.cloudProvider.onNodeGroupCreate(tng.id)
|
||||
newNodeGroup := tng.cloudProvider.AddAutoprovisionedNodeGroup(tng.id, tng.minSize, tng.maxSize, 0, tng.machineType)
|
||||
return newNodeGroup, tng.cloudProvider.onNodeGroupCreate(tng.id)
|
||||
}
|
||||
|
||||
// Delete deletes the node group on the cloud provider side.
|
||||
|
|
|
|||
|
|
@ -46,8 +46,10 @@ func (f *FakeNodeGroup) Nodes() ([]string, error) { return []string{},
|
|||
func (f *FakeNodeGroup) TemplateNodeInfo() (*schedulercache.NodeInfo, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
func (f *FakeNodeGroup) Exist() bool { return true }
|
||||
func (f *FakeNodeGroup) Create() error { return cloudprovider.ErrAlreadyExist }
|
||||
func (f *FakeNodeGroup) Exist() bool { return true }
|
||||
func (f *FakeNodeGroup) Create() (cloudprovider.NodeGroup, error) {
|
||||
return nil, cloudprovider.ErrAlreadyExist
|
||||
}
|
||||
func (f *FakeNodeGroup) Delete() error { return cloudprovider.ErrNotImplemented }
|
||||
func (f *FakeNodeGroup) Autoprovisioned() bool { return false }
|
||||
|
||||
|
|
|
|||
|
|
@ -41,21 +41,21 @@ func (p *AutoprovisioningNodeGroupManager) CreateNodeGroup(context *context.Auto
|
|||
}
|
||||
|
||||
oldId := nodeGroup.Id()
|
||||
err := nodeGroup.Create()
|
||||
newNodeGroup, err := nodeGroup.Create()
|
||||
if err != nil {
|
||||
context.LogRecorder.Eventf(apiv1.EventTypeWarning, "FailedToCreateNodeGroup",
|
||||
"NodeAutoprovisioning: attempt to create node group %v failed: %v", oldId, err)
|
||||
// TODO(maciekpytel): add some metric here after figuring out failure scenarios
|
||||
return nil, errors.ToAutoscalerError(errors.CloudProviderError, err)
|
||||
}
|
||||
newId := nodeGroup.Id()
|
||||
newId := newNodeGroup.Id()
|
||||
if newId != oldId {
|
||||
glog.V(2).Infof("Created node group %s based on template node group %s, will use new node group in scale-up", newId, oldId)
|
||||
}
|
||||
context.LogRecorder.Eventf(apiv1.EventTypeNormal, "CreatedNodeGroup",
|
||||
"NodeAutoprovisioning: created new node group %v", newId)
|
||||
metrics.RegisterNodeGroupCreation()
|
||||
return nodeGroup, nil
|
||||
return newNodeGroup, nil
|
||||
}
|
||||
|
||||
// RemoveUnneededNodeGroups removes node groups that are not needed anymore.
|
||||
|
|
|
|||
Loading…
Reference in New Issue