Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with upstream v1.21.3 #129

Merged
merged 47 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
32b4045
Set maxAsgNamesPerDescribe to the new maximum value
bpineau Apr 8, 2021
a0a1bcd
Break out unmarshal from GenerateEC2InstanceTypes
aidy Jul 7, 2021
b62982b
Optimise GenerateEC2InstanceTypes unmarshal memory usage
aidy Jul 7, 2021
67c6404
use aws sdk to find region
darkpssngr Jun 9, 2021
af87cfd
Merge pull request #4267 from gjtempleton/automated-cherry-pick-of-#3…
k8s-ci-robot Aug 17, 2021
146cdab
Merge pull request #4274 from kinvolk/imran/cloud-provider-packet-fix
k8s-ci-robot Aug 19, 2021
5fee6c6
Merge pull request #4288 from kinvolk/backport-1.21
k8s-ci-robot Sep 6, 2021
815b32e
Fix templated nodeinfo names collisions in BinpackingNodeEstimator
bpineau May 19, 2021
b920a67
Merge pull request #4311 from towca/jtuznik/4089-cp
k8s-ci-robot Sep 7, 2021
618fada
Improve misleading log
sylr Apr 28, 2021
38dd2fc
Merge pull request #4333 from nitrag/backport-535a212-1.21
k8s-ci-robot Sep 16, 2021
3a17413
dont proactively decrement azure cache for unregistered nodes
marwanad Jun 10, 2021
1b26f7f
annotate fakeNodes so that cloudprovider implementations can identify…
marwanad Jun 6, 2021
836506e
move annotations to cloudprovider package
marwanad Jun 8, 2021
7c4fb20
Merge pull request #4372 from marwanad/cherry-pick-4130-1.21
k8s-ci-robot Oct 1, 2021
02d636c
Cluster Autoscaler 1.21.1
towca Sep 30, 2021
7b089cd
Merge pull request #4364 from towca/jtuznik/1.21.1
k8s-ci-robot Oct 1, 2021
2b6ee77
CA - AWS - Instance List Update 03-10-21 - 1.21 release branch
gjtempleton Oct 3, 2021
fc39466
Merge pull request #4381 from gjtempleton/CA-AWS-Instance-List-Update…
k8s-ci-robot Oct 18, 2021
2ce33e8
CA - AWS - Instance List Update 29-10-21 - 1.21 release branch
sturman Oct 29, 2021
5547629
Merge pull request #4431 from sturman/CA-EC2-AWS-Instance-List-Update…
k8s-ci-robot Nov 1, 2021
43641f8
Cluster-Autoscaler update AWS EC2 instance types with g5, m6 and r6
sturman Nov 29, 2021
df4aaf6
Merge pull request #4484 from sturman/CA-EC2-AWS-Instance-List-Update…
k8s-ci-robot Dec 13, 2021
1026b58
CA - AWS Instance List Update - 13/12/21 - 1.21
gjtempleton Dec 13, 2021
e94dcdd
Merge pull request #4497 from marwanad/add-more-azure-instance-types
k8s-ci-robot Dec 7, 2021
b45adf1
Merge pull request #4525 from gandhipr/cluster-autoscaler-release-1.21
k8s-ci-robot Dec 14, 2021
00c1211
Merge pull request #4522 from gjtempleton/CA-AWS-Instance-List-Update…
k8s-ci-robot Dec 16, 2021
11c5b0e
Cluster Autoscaler 1.21.2
MaciekPytel Dec 16, 2021
499cf60
Merge pull request #4531 from MaciekPytel/ca_1_21_2
k8s-ci-robot Dec 20, 2021
606f44d
Add `--feature-gates` flag to support scale up on volume limits (CSI …
ialidzhikov Dec 19, 2021
19aba01
Merge pull request #4554 from ialidzhikov/automated-cherry-pick-of-#4…
k8s-ci-robot Dec 22, 2021
785cc16
[Cherry pick 1.21] Remove TestDeleteBlob UT
lzhecheng Jan 19, 2022
da4baf7
Merge pull request #4631 from lzhecheng/cherry-pick-remove-deleteblob…
k8s-ci-robot Jan 21, 2022
17e062b
cherry-pick #4022 [cluster-autoscaler] Publish node group min/max met…
k8s-ci-robot Jul 5, 2021
482cb1e
Skipping metrics tests added in #4022
MaciekPytel Jul 8, 2021
0ad1731
Merge pull request #4700 from mongodb-forks/cluster-autoscaler-releas…
k8s-ci-robot Apr 25, 2022
fcd0433
cherry-pick #4162 and #4172 [cluster-autoscaler]Add flag to control D…
Shubham82 May 25, 2022
6ae7fa1
CA - AWS Cloud Provider - 1.21 Static Instance List Update 02-06-2022
gjtempleton Jun 2, 2022
b73c4ea
fix instance type fallback
tzneal May 9, 2022
3c35b67
Merge pull request #4943 from tzneal/cluster-autoscaler-release-1.21-…
k8s-ci-robot Jun 4, 2022
7b54523
Merge pull request #4937 from gjtempleton/cluster-autoscaler-release-…
k8s-ci-robot Jun 6, 2022
a263aa1
Merge pull request #4916 from Shubham82/cluster-autoscaler-release-1.…
k8s-ci-robot Jun 6, 2022
8c37531
Cluster Autoscaler - 1.21.3 release
gjtempleton Jun 13, 2022
c95c261
Merge pull request #4963 from gjtempleton/cluster-autoscaler-release-…
k8s-ci-robot Jun 13, 2022
ba0787f
Merge changes till upstream v1.21.3
himanshu-kun Jun 23, 2022
ddc0a84
FAQ updated
himanshu-kun Jun 23, 2022
47ce25c
Sync_changes file updated
himanshu-kun Jun 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
486 changes: 283 additions & 203 deletions cluster-autoscaler/FAQ.md

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions cluster-autoscaler/SYNC-CHANGES/SYNC-CHANGES-1.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
- [During merging](#during-merging)
- [During vendoring k8s](#during-vendoring-k8s)
- [Others](#others)
- [v1.21.1](#v1211)
- [Synced with which upstream CA](#synced-with-which-upstream-ca-1)
- [Changes made](#changes-made-1)
- [To FAQ](#to-faq-1)
- [During merging](#during-merging-1)
- [During vendoring k8s](#during-vendoring-k8s-1)
- [Others](#others-1)


# v1.21.0
Expand Down Expand Up @@ -38,3 +45,28 @@
- cluster-autoscaler/cloudprovider/builder/builder_all.go
- cluster-autoscaler/cloudprovider/mcm
- cluster-autoscaler/integration


# v1.21.1


## Synced with which upstream CA

[v1.21.3](https://github.com/kubernetes/autoscaler/tree/cluster-autoscaler-1.21.3/cluster-autoscaler)

## Changes made

### To FAQ

- included new questions and answers
- included new steps to vendor new MCM version

### During merging

- included new ec2 instances in `cluster-autoscaler/cloudprovider/aws/ec2_instance_types.go`

### During vendoring k8s
Still vendoring k8s 1.21.0 in this fork but the upstream 1.21.3 is vendoring k8s 1.25.0

### Others
_None_
14 changes: 7 additions & 7 deletions cluster-autoscaler/cloudprovider/aws/auto_scaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ import (
"github.com/stretchr/testify/require"
)

func TestMoreThen50Groups(t *testing.T) {
func TestMoreThen100Groups(t *testing.T) {
service := &AutoScalingMock{}
autoScalingWrapper := &autoScalingWrapper{
autoScaling: service,
}

// Generate 51 ASG names
names := make([]string, 51)
// Generate 101 ASG names
names := make([]string, 101)
for i := 0; i < len(names); i++ {
names[i] = fmt.Sprintf("asg-%d", i)
}

// First batch, first 50 elements
// First batch, first 100 elements
service.On("DescribeAutoScalingGroupsPages",
&autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: aws.StringSlice(names[:50]),
AutoScalingGroupNames: aws.StringSlice(names[:100]),
MaxRecords: aws.Int64(maxRecordsReturnedByAPI),
},
mock.AnythingOfType("func(*autoscaling.DescribeAutoScalingGroupsOutput, bool) bool"),
Expand All @@ -51,10 +51,10 @@ func TestMoreThen50Groups(t *testing.T) {
fn(testNamedDescribeAutoScalingGroupsOutput("asg-1", 1, "test-instance-id"), false)
}).Return(nil)

// Second batch, element 51
// Second batch, element 101
service.On("DescribeAutoScalingGroupsPages",
&autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: aws.StringSlice([]string{"asg-50"}),
AutoScalingGroupNames: aws.StringSlice([]string{"asg-100"}),
MaxRecords: aws.Int64(maxRecordsReturnedByAPI),
},
mock.AnythingOfType("func(*autoscaling.DescribeAutoScalingGroupsOutput, bool) bool"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ func BuildAWS(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscover

generatedInstanceTypes, err := GenerateEC2InstanceTypes(region)
if err != nil {
klog.Fatalf("Failed to generate AWS EC2 Instance Types: %v", err)
klog.Errorf("Failed to generate AWS EC2 Instance Types: %v, falling back to static list with last update time: %s", err, lastUpdateTime)
}
if generatedInstanceTypes == nil {
generatedInstanceTypes = map[string]*InstanceType{}
}
// fallback on the static list if we miss any instance types in the generated output
// credits to: https://github.com/lyft/cni-ipvlan-vpc-k8s/pull/80
Expand Down
19 changes: 19 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_cloud_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package aws

import (
"os"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/stretchr/testify/mock"
apiv1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/config"
)

type AutoScalingMock struct {
Expand Down Expand Up @@ -148,6 +150,23 @@ func TestBuildAwsCloudProvider(t *testing.T) {
assert.NoError(t, err)
}

func TestInstanceTypeFallback(t *testing.T) {
resourceLimiter := cloudprovider.NewResourceLimiter(
map[string]int64{cloudprovider.ResourceNameCores: 1, cloudprovider.ResourceNameMemory: 10000000},
map[string]int64{cloudprovider.ResourceNameCores: 10, cloudprovider.ResourceNameMemory: 100000000})

do := cloudprovider.NodeGroupDiscoveryOptions{}
opts := config.AutoscalingOptions{}

os.Setenv("AWS_REGION", "non-existent-region")
defer os.Unsetenv("AWS_REGION")

// This test ensures that no klog.Fatalf calls occur when constructing the AWS cloud provider. Specifically it is
// intended to ensure that instance type fallback works correctly in the event of an error enumerating instance
// types.
_ = BuildAWS(opts, do, resourceLimiter)
}

func TestName(t *testing.T) {
provider := testProvider(t, testAwsManager)
assert.Equal(t, provider.Name(), cloudprovider.AwsProviderName)
Expand Down
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
operationWaitTimeout = 5 * time.Second
operationPollInterval = 100 * time.Millisecond
maxRecordsReturnedByAPI = 100
maxAsgNamesPerDescribe = 50
maxAsgNamesPerDescribe = 100
refreshInterval = 1 * time.Minute
autoDiscovererTypeASG = "asg"
asgAutoDiscovererKeyTag = "tag"
Expand Down Expand Up @@ -312,7 +312,7 @@ func (m *AwsManager) getAsgTemplate(asg *asg) (*asgTemplate, error) {
region := az[0 : len(az)-1]

if len(asg.AvailabilityZones) > 1 {
klog.Warningf("Found multiple availability zones for ASG %q; using %s\n", asg.Name, az)
klog.V(4).Infof("Found multiple availability zones for ASG %q; using %s for %s label\n", asg.Name, az, apiv1.LabelFailureDomainBetaZone)
}

instanceTypeName, err := m.buildInstanceType(asg)
Expand Down
101 changes: 69 additions & 32 deletions cluster-autoscaler/cloudprovider/aws/aws_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,26 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/aws/aws-sdk-go/aws/endpoints"
"io/ioutil"
klog "k8s.io/klog/v2"
"io"
"net/http"
"os"
"regexp"
"strconv"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"

klog "k8s.io/klog/v2"
)

var (
ec2MetaDataServiceUrl = "http://169.254.169.254/latest/dynamic/instance-identity/document"
ec2MetaDataServiceUrl = "http://169.254.169.254"
ec2PricingServiceUrlTemplate = "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/%s/index.json"
ec2PricingServiceUrlTemplateCN = "https://pricing.cn-north-1.amazonaws.com.cn/offers/v1.0/cn/AmazonEC2/current/%s/index.json"
staticListLastUpdateTime = "2020-12-07"
staticListLastUpdateTime = "2022-06-02"
)

type response struct {
Expand Down Expand Up @@ -82,16 +87,9 @@ func GenerateEC2InstanceTypes(region string) (map[string]*InstanceType, error) {

defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
unmarshalled, err := unmarshalProductsResponse(res.Body)
if err != nil {
klog.Warningf("Error parsing %s skipping...\n", url)
continue
}

var unmarshalled = response{}
err = json.Unmarshal(body, &unmarshalled)
if err != nil {
klog.Warningf("Error unmarshalling %s, skip...\n", url)
klog.Warningf("Error parsing %s skipping...\n%s\n", url, err)
continue
}

Expand Down Expand Up @@ -127,6 +125,58 @@ func GetStaticEC2InstanceTypes() (map[string]*InstanceType, string) {
return InstanceTypes, staticListLastUpdateTime
}

func unmarshalProductsResponse(r io.Reader) (*response, error) {
dec := json.NewDecoder(r)
t, err := dec.Token()
if err != nil {
return nil, err
}
if delim, ok := t.(json.Delim); !ok || delim.String() != "{" {
return nil, errors.New("Invalid products json")
}

unmarshalled := response{map[string]product{}}

for dec.More() {
t, err = dec.Token()
if err != nil {
return nil, err
}

if t == "products" {
tt, err := dec.Token()
if err != nil {
return nil, err
}
if delim, ok := tt.(json.Delim); !ok || delim.String() != "{" {
return nil, errors.New("Invalid products json")
}
for dec.More() {
productCode, err := dec.Token()
if err != nil {
return nil, err
}

prod := product{}
if err = dec.Decode(&prod); err != nil {
return nil, err
}
unmarshalled.Products[productCode.(string)] = prod
}
}
}

t, err = dec.Token()
if err != nil {
return nil, err
}
if delim, ok := t.(json.Delim); !ok || delim.String() != "}" {
return nil, errors.New("Invalid products json")
}

return &unmarshalled, nil
}

func parseMemory(memory string) int64 {
reg, err := regexp.Compile("[^0-9\\.]+")
if err != nil {
Expand Down Expand Up @@ -155,26 +205,13 @@ func GetCurrentAwsRegion() (string, error) {
region, present := os.LookupEnv("AWS_REGION")

if !present {
klog.V(1).Infof("fetching %s\n", ec2MetaDataServiceUrl)
res, err := http.Get(ec2MetaDataServiceUrl)
if err != nil {
return "", fmt.Errorf("Error fetching %s", ec2MetaDataServiceUrl)
}

defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
c := aws.NewConfig().
WithEndpoint(ec2MetaDataServiceUrl)
sess, err := session.NewSession()
if err != nil {
return "", fmt.Errorf("Error parsing %s", ec2MetaDataServiceUrl)
return "", fmt.Errorf("failed to create session")
}

var unmarshalled = map[string]string{}
err = json.Unmarshal(body, &unmarshalled)
if err != nil {
klog.Warningf("Error unmarshalling %s, skip...\n", ec2MetaDataServiceUrl)
}

region = unmarshalled["region"]
return ec2metadata.New(sess, c).Region()
}

return region, nil
Expand Down
Loading