Skip to content

Commit

Permalink
draft : lift cluster client and builder to common
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranRoche committed Feb 2, 2024
1 parent ff8c6c1 commit 0574259
Show file tree
Hide file tree
Showing 28 changed files with 1,511 additions and 39 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ clean:
rm -rf \
ocm-common \
$(NULL)

.PHONY: generate
generate:
go generate ./...
34 changes: 27 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/openshift-online/ocm-common

go 1.19
go 1.21

require (
github.com/aws/aws-sdk-go-v2 v1.22.2
github.com/aws/aws-sdk-go-v2/service/iam v1.27.1
github.com/hashicorp/go-version v1.6.0
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
github.com/openshift-online/ocm-sdk-go v0.1.391
github.com/openshift-online/ocm-sdk-go v0.1.398
go.uber.org/mock v0.3.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/crypto v0.17.0
gopkg.in/square/go-jose.v2 v2.6.0
)

Expand All @@ -21,18 +21,38 @@ require (
)

require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.9.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
483 changes: 483 additions & 0 deletions go.sum

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions pkg/ocm/builders/cluster_auto_scaler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package builders

import (
"fmt"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"

"github.com/openshift-online/ocm-common/pkg/ocm/models"
)

func BuildClusterAutoscaler(config *models.AutoscalerConfig) *cmv1.ClusterAutoscalerBuilder {
if config == nil {
return nil
}

var gpuLimits []*cmv1.AutoscalerResourceLimitsGPULimitBuilder
for _, gpuLimit := range config.ResourceLimits.GPULimits {
gpuLimits = append(
gpuLimits,
cmv1.NewAutoscalerResourceLimitsGPULimit().
Type(gpuLimit.Type).
Range(cmv1.NewResourceRange().
Min(gpuLimit.Range.Min).
Max(gpuLimit.Range.Max)),
)
}

return cmv1.NewClusterAutoscaler().
BalanceSimilarNodeGroups(config.BalanceSimilarNodeGroups).
SkipNodesWithLocalStorage(config.SkipNodesWithLocalStorage).
LogVerbosity(config.LogVerbosity).
MaxPodGracePeriod(config.MaxPodGracePeriod).
PodPriorityThreshold(config.PodPriorityThreshold).
IgnoreDaemonsetsUtilization(config.IgnoreDaemonsetsUtilization).
MaxNodeProvisionTime(config.MaxNodeProvisionTime).
BalancingIgnoredLabels(config.BalancingIgnoredLabels...).
ResourceLimits(cmv1.NewAutoscalerResourceLimits().
MaxNodesTotal(config.ResourceLimits.MaxNodesTotal).
Cores(cmv1.NewResourceRange().
Min(config.ResourceLimits.Cores.Min).
Max(config.ResourceLimits.Cores.Max)).
Memory(cmv1.NewResourceRange().
Min(config.ResourceLimits.Memory.Min).
Max(config.ResourceLimits.Memory.Max)).
GPUS(gpuLimits...)).
ScaleDown(cmv1.NewAutoscalerScaleDownConfig().
Enabled(config.ScaleDown.Enabled).
UnneededTime(config.ScaleDown.UnneededTime).
UtilizationThreshold(fmt.Sprintf("%f", config.ScaleDown.UtilizationThreshold)).
DelayAfterAdd(config.ScaleDown.DelayAfterAdd).
DelayAfterDelete(config.ScaleDown.DelayAfterDelete).
DelayAfterFailure(config.ScaleDown.DelayAfterFailure))
}
Loading

0 comments on commit 0574259

Please sign in to comment.