-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
t-qini
committed
Dec 26, 2019
1 parent
a1cd503
commit fe7be21
Showing
7 changed files
with
284 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
cluster-autoscaler/cloudprovider/azure/azure_agent_pool_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2017-05-10/resources" | ||
"github.com/Azure/go-autorest/autorest/date" | ||
"github.com/Azure/go-autorest/autorest/to" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func newTestAgentPool(manager *AzureManager, name string) *AgentPool { | ||
return &AgentPool{ | ||
azureRef: azureRef{ | ||
Name: name, | ||
}, | ||
manager: manager, | ||
minSize: 1, | ||
maxSize: 5, | ||
} | ||
} | ||
|
||
func TestDeleteOutdatedDeployments(t *testing.T) { | ||
timeLayout := "2006-01-02 15:04:05" | ||
timeBenchMark, _ := time.Parse(timeLayout, "2000-01-01 00:00:00") | ||
|
||
testCases := []struct { | ||
deployments map[string]resources.DeploymentExtended | ||
expectedDeployments []resources.DeploymentExtended | ||
expectedErr error | ||
desc string | ||
}{ | ||
{ | ||
deployments: map[string]resources.DeploymentExtended{ | ||
"non-cluster-autoscaler-0000": { | ||
Name: to.StringPtr("non-cluster-autoscaler-0000"), | ||
Properties: &resources.DeploymentPropertiesExtended{ | ||
ProvisioningState: to.StringPtr("Succeeded"), | ||
Timestamp: &date.Time{Time: timeBenchMark.Add(2 * time.Minute)}, | ||
}, | ||
}, | ||
"cluster-autoscaler-0000": { | ||
Name: to.StringPtr("cluster-autoscaler-0000"), | ||
Properties: &resources.DeploymentPropertiesExtended{ | ||
ProvisioningState: to.StringPtr("Succeeded"), | ||
Timestamp: &date.Time{Time: timeBenchMark}, | ||
}, | ||
}, | ||
"cluster-autoscaler-0001": { | ||
Name: to.StringPtr("cluster-autoscaler-0001"), | ||
Properties: &resources.DeploymentPropertiesExtended{ | ||
ProvisioningState: to.StringPtr("Succeeded"), | ||
Timestamp: &date.Time{Time: timeBenchMark.Add(time.Minute)}, | ||
}, | ||
}, | ||
"cluster-autoscaler-0002": { | ||
Name: to.StringPtr("cluster-autoscaler-0002"), | ||
Properties: &resources.DeploymentPropertiesExtended{ | ||
ProvisioningState: to.StringPtr("Succeeded"), | ||
Timestamp: &date.Time{Time: timeBenchMark.Add(2 * time.Minute)}, | ||
}, | ||
}, | ||
}, | ||
expectedDeployments: []resources.DeploymentExtended{ | ||
{ | ||
Name: to.StringPtr("non-cluster-autoscaler-0000"), | ||
Properties: &resources.DeploymentPropertiesExtended{ | ||
ProvisioningState: to.StringPtr("Succeeded"), | ||
Timestamp: &date.Time{Time: timeBenchMark.Add(2 * time.Minute)}, | ||
}, | ||
}, | ||
{ | ||
Name: to.StringPtr("cluster-autoscaler-0001"), | ||
Properties: &resources.DeploymentPropertiesExtended{ | ||
ProvisioningState: to.StringPtr("Succeeded"), | ||
Timestamp: &date.Time{Time: timeBenchMark.Add(time.Minute)}, | ||
}, | ||
}, | ||
{ | ||
Name: to.StringPtr("cluster-autoscaler-0002"), | ||
Properties: &resources.DeploymentPropertiesExtended{ | ||
ProvisioningState: to.StringPtr("Succeeded"), | ||
Timestamp: &date.Time{Time: timeBenchMark.Add(2 * time.Minute)}, | ||
}, | ||
}, | ||
}, | ||
expectedErr: nil, | ||
desc: "cluster autoscaler provider azure should delete outdated deployments created by cluster autoscaler", | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
testAS := newTestAgentPool(newTestAzureManager(t), "testAS") | ||
testAS.manager.azClient.deploymentsClient = &DeploymentsClientMock{ | ||
FakeStore: test.deployments, | ||
} | ||
|
||
allDeployments := make([]resources.DeploymentExtended, 0) | ||
for _, v := range test.deployments { | ||
allDeployments = append(allDeployments, v) | ||
} | ||
|
||
err := testAS.deleteOutdatedDeployments(allDeployments) | ||
assert.Equal(t, test.expectedErr, err, test.desc) | ||
existedDeployments, err := testAS.manager.azClient.deploymentsClient.List(context.Background(), "", "", to.Int32Ptr(0)) | ||
assert.Equal(t, test.expectedDeployments, existedDeployments, test.desc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters