Skip to content

Commit

Permalink
Merge branch 'kubernetes:master' into aep-prov-req
Browse files Browse the repository at this point in the history
  • Loading branch information
kisieland authored Jun 28, 2023
2 parents 7381eb3 + 1c8ec5c commit d6a23c2
Show file tree
Hide file tree
Showing 841 changed files with 41,127 additions and 33,820 deletions.
4 changes: 2 additions & 2 deletions charts/cluster-autoscaler/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
appVersion: 1.27.1
appVersion: 1.27.2
description: Scales Kubernetes worker nodes within autoscaling groups.
engine: gotpl
home: https://github.com/kubernetes/autoscaler
Expand All @@ -11,4 +11,4 @@ name: cluster-autoscaler
sources:
- https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler
type: application
version: 9.29.0
version: 9.29.1
7 changes: 5 additions & 2 deletions charts/cluster-autoscaler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ Though enough for the majority of installations, the default PodSecurityPolicy _
### VerticalPodAutoscaler
The chart can install a [`VerticalPodAutoscaler`](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/README.md) for the Deployment if needed. A VPA can help minimize wasted resources when usage spikes periodically or remediate containers that are being OOMKilled.
The CA Helm Chart can install a [`VerticalPodAutoscaler`](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/README.md) object from Chart version `9.27.0`
onwards for the Cluster Autoscaler Deployment to scale the CA as appropriate, but for that, we
need to install the VPA to the cluster separately. A VPA can help minimize wasted resources
when usage spikes periodically or remediate containers that are being OOMKilled.
The following example snippet can be used to install VPA that allows scaling down from the default recommendations of the deployment template:
Expand Down Expand Up @@ -383,7 +386,7 @@ vpa:
| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy |
| image.pullSecrets | list | `[]` | Image pull secrets |
| image.repository | string | `"registry.k8s.io/autoscaling/cluster-autoscaler"` | Image repository |
| image.tag | string | `"v1.27.1"` | Image tag |
| image.tag | string | `"v1.27.2"` | Image tag |
| kubeTargetVersionOverride | string | `""` | Allow overriding the `.Capabilities.KubeVersion.GitVersion` check. Useful for `helm template` commands. |
| magnumCABundlePath | string | `"/etc/kubernetes/ca-bundle.crt"` | Path to the host's CA bundle, from `ca-file` in the cloud-config file. |
| magnumClusterName | string | `""` | Cluster name or ID in Magnum. Required if `cloudProvider=magnum` and not setting `autoDiscovery.clusterName`. |
Expand Down
5 changes: 4 additions & 1 deletion charts/cluster-autoscaler/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ Though enough for the majority of installations, the default PodSecurityPolicy _

### VerticalPodAutoscaler

The chart can install a [`VerticalPodAutoscaler`](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/README.md) for the Deployment if needed. A VPA can help minimize wasted resources when usage spikes periodically or remediate containers that are being OOMKilled.
The CA Helm Chart can install a [`VerticalPodAutoscaler`](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/README.md) object from Chart version `9.27.0`
onwards for the Cluster Autoscaler Deployment to scale the CA as appropriate, but for that, we
need to install the VPA to the cluster separately. A VPA can help minimize wasted resources
when usage spikes periodically or remediate containers that are being OOMKilled.

The following example snippet can be used to install VPA that allows scaling down from the default recommendations of the deployment template:

Expand Down
2 changes: 1 addition & 1 deletion charts/cluster-autoscaler/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ image:
# image.repository -- Image repository
repository: registry.k8s.io/autoscaling/cluster-autoscaler
# image.tag -- Image tag
tag: v1.27.1
tag: v1.27.2
# image.pullPolicy -- Image pull policy
pullPolicy: IfNotPresent
## Optionally specify an array of imagePullSecrets.
Expand Down
7 changes: 6 additions & 1 deletion cluster-autoscaler/cloudprovider/aws/aws_sdk_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws/aws-sdk-go/aws"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws/aws-sdk-go/aws/ec2metadata"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws/aws-sdk-go/aws/endpoints"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws/aws-sdk-go/aws/request"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws/aws-sdk-go/aws/session"
"k8s.io/autoscaler/cluster-autoscaler/version"
provider_aws "k8s.io/cloud-provider-aws/pkg/providers/v1"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -61,11 +63,14 @@ func createAWSSDKProvider(configReader io.Reader) (*awsSDKProvider, error) {
}

sess, err := session.NewSession(config)

if err != nil {
return nil, err
}

// add cluster-autoscaler to the user-agent to make it easier to identify
agent := fmt.Sprintf("cluster-autoscaler/v%s", version.ClusterAutoscalerVersion)
sess.Handlers.Build.PushBack(request.MakeAddToUserAgentFreeFormHandler(agent))

provider := &awsSDKProvider{
session: sess,
}
Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/brightbox/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export BUILD_TAGS=brightbox
export REGISTRY=brightbox
export REGISTRY?=brightbox
export GOARCH?=$(shell go env GOARCH)
ifndef TAG
override TAG=dev
Expand Down
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/brightbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ $ make build

This builds an autoscaler containing only the Brightbox Cloud provider,
tagged as `brightbox/cluster-autoscaler-brightbox:dev`. To build any
other version add a TAG variable
other version add a TAG variable and/or a REGISTRY variable

```
make build TAG=1.1x
make build TAG=1.1x REGISTRY=cr.brightbox.com/acc-xxxxx/<registry-name>
```
28 changes: 18 additions & 10 deletions cluster-autoscaler/cloudprovider/brightbox/brightbox_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,24 +359,32 @@ func makeNodeGroupFromAPIDetails(
if mapData["server_group"] == "" {
return nil, cloudprovider.ErrIllegalConfiguration
}
ng := brightboxNodeGroup{
id: mapData["server_group"],
minSize: minSize,
maxSize: maxSize,
Cloud: cloudclient,
}
imageID := mapData["image"]
if !(len(imageID) == 9 && strings.HasPrefix(imageID, "img-")) {
image, err := ng.GetImageByName(imageID)
if err != nil || image == nil {
return nil, cloudprovider.ErrIllegalConfiguration
}
imageID = image.Id
}
userData := mapData["user_data"]
options := &brightbox.ServerOptions{
Image: mapData["image"],
Image: imageID,
Name: &name,
ServerType: mapData["type"],
Zone: mapData["zone"],
UserData: &userData,
ServerGroups: mergeServerGroups(mapData),
}
result := brightboxNodeGroup{
id: mapData["server_group"],
minSize: minSize,
maxSize: maxSize,
serverOptions: options,
Cloud: cloudclient,
}
klog.V(4).Info(result.Debug())
return &result, nil
ng.serverOptions = options
klog.V(4).Info(ng.Debug())
return &ng, nil
}

func mergeServerGroups(data map[string]string) []string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"context"
"fmt"
"net/http"
"regexp"
"sort"
"strings"

brightbox "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/brightbox/gobrightbox"
Expand Down Expand Up @@ -166,6 +168,36 @@ func (c *Cloud) GetServerType(identifier string) (*brightbox.ServerType, error)
return client.ServerType(identifier)
}

// GetImageByName obtains the most recent available image that matches the supplied pattern
func (c *Cloud) GetImageByName(name string) (*brightbox.Image, error) {
klog.V(4).Infof("GetImageByName %q", name)
client, err := c.CloudClient()
if err != nil {
return nil, err
}
klog.V(6).Info("GetImageByName compiling regexp")
nameRe, err := regexp.Compile(name)
if err != nil {
return nil, err
}
klog.V(6).Info("GetImageByName retrieving images")
images, err := client.Images()
if err != nil {
return nil, err
}
klog.V(6).Info("GetImageByName filtering images")
filteredImages := filter(
images,
func(i brightbox.Image) bool {
return i.Official &&
i.Status == status.Available &&
nameRe.MatchString(i.Name)
},
)
klog.V(6).Infof("GetImageByName images selected (%+v)", filteredImages)
return mostRecent(filteredImages), nil
}

// GetConfigMaps obtains the list of Config Maps on the account
func (c *Cloud) GetConfigMaps() ([]brightbox.ConfigMap, error) {
klog.V(4).Info("GetConfigMaps")
Expand Down Expand Up @@ -555,3 +587,27 @@ func ErrorIfAcmeNotComplete(acme *brightbox.LoadBalancerAcme) error {
}
return nil
}

// Returns the most recent item out of a slice of items with Dates
// or nil if there are no items
func mostRecent(items []brightbox.Image) *brightbox.Image {
if len(items) == 0 {
return nil
}
sortedItems := items
sort.Slice(items, func(i, j int) bool {
return items[i].CreatedAt.Unix() > items[j].CreatedAt.Unix()
})
return &sortedItems[0]
}

// filter returns a new slice with all elements from the
// input elements for which the provided predicate function returns true.
func filter[T any](input []T, pred func(T) bool) (output []T) {
for _, v := range input {
if pred(v) {
output = append(output, v)
}
}
return output
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ type CloudAccess interface {
// DestroyCloudIP issues a request to destroy the cloud ip
DestroyCloudIP(identifier string) error

// ConfigMaps retrieves a list of all config maps
Images() ([]brightbox.Image, error)

// ConfigMaps retrieves a list of all config maps
ConfigMaps() ([]brightbox.ConfigMap, error)

Expand Down
Loading

0 comments on commit d6a23c2

Please sign in to comment.