Skip to content

Commit

Permalink
Merge remote-tracking branch 'stratio/branch-0.17.0-0.1' into feature…
Browse files Browse the repository at this point in the history
…/EOS_11009_add_labels_to_node_groups
  • Loading branch information
kahun committed Mar 14, 2023
2 parents 41c5b82 + c0d447f commit 524b3a8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changelog

## 0.1.0 (upcoming)
## 0.17.0-0.1.0 (upcoming)

* Add clusterAPI capabilities for EKS
* Add clusterAPI capabilities for EKS
42 changes: 27 additions & 15 deletions pkg/cluster/internal/create/actions/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"embed"
"os"
"strings"
"text/template"

"github.com/go-playground/validator/v10"
Expand Down Expand Up @@ -111,8 +112,8 @@ type WorkerNodes []struct {
SSHKey string `yaml:"ssh_key"`
Spot bool `yaml:"spot" validate:"omitempty,boolean"`
Labels map[string]string `yaml:"labels"`
NodeGroupMaxSize int `yaml:"max_size" validate:"required,numeric,gtefield=Quantity,gt=0"`
NodeGroupMinSize int `yaml:"min_size" validate:"required,numeric,ltefield=Quantity,gt=0"`
NodeGroupMaxSize int `yaml:"max_size" validate:"omitempty,numeric,required_with=NodeGroupMinSize,gtefield=Quantity,gt=0"`
NodeGroupMinSize int `yaml:"min_size" validate:"omitempty,numeric,required_with=NodeGroupMaxSize,ltefield=Quantity,gt=0"`
RootVolume struct {
Size int `yaml:"size" validate:"numeric"`
Type string `yaml:"type"`
Expand Down Expand Up @@ -216,34 +217,45 @@ func GetClusterDescriptor(descriptorPath string) (*DescriptorFile, error) {
return &descriptorFile, nil
}

func resto(n int, i int) int {
var r int
r = (n % 3) / (i + 1)
if r > 1 {
r = 1
}
return r
}

func GetClusterManifest(flavor string, params TemplateParams) (string, error) {

funcMap := template.FuncMap{
"loop": func(az string, qa int, maxsize int, minsize int) <-chan Node {
"loop": func(az string, zd string, qa int, maxsize int, minsize int) <-chan Node {
ch := make(chan Node)
go func() {
var azs []string
var q int
var mx int
var mn int
if az != "" {
azs = []string{az}
q = qa
mx = maxsize
mn = minsize
ch <- Node{AZ: az, QA: qa, MaxSize: maxsize, MinSize: minsize}
} else {
azs = []string{"a", "b", "c"}
q = qa / 3
mx = maxsize / 3
mn = minsize / 3
}
for _, a := range azs {
ch <- Node{AZ: a, QA: q, MaxSize: mx, MinSize: mn}
for i, a := range []string{"a", "b", "c"} {
if zd == "unbalanced" {
q = qa/3 + resto(qa, i)
mx = maxsize/3 + resto(maxsize, i)
mn = minsize/3 + resto(minsize, i)
ch <- Node{AZ: a, QA: q, MaxSize: mx, MinSize: mn}
} else {
ch <- Node{AZ: a, QA: qa / 3, MaxSize: maxsize / 3, MinSize: minsize / 3}
}
}
}
close(ch)
}()
return ch
},
"hostname": func(s string) string {
return strings.Split(s, "/")[0]
},
}

var tpl bytes.Buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ spec:
- name: ANNOTATE_POD_IP
value: \"true\"
{{- range $node := .Descriptor.WorkerNodes }}
{{- range $index, $n := loop .AZ .Quantity .NodeGroupMaxSize .NodeGroupMinSize }}
{{- range $index, $n := loop .AZ .ZoneDistribution .Quantity .NodeGroupMaxSize .NodeGroupMinSize }}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
{{- if and $node.NodeGroupMaxSize $node.NodeGroupMinSize }}
{{- if and (gt $node.NodeGroupMaxSize 0) (gt $node.NodeGroupMinSize 0) }}
annotations:
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: '{{ $n.MaxSize }}'
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: '{{ $n.MinSize }}'
Expand Down
14 changes: 7 additions & 7 deletions pkg/cluster/internal/create/actions/cluster/templates/gcp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ spec:
[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors]
[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"]
endpoint = [\"https://registry-1.docker.io\"]
[plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ .ExternalRegistry.Url }}\".auth]
{{- $url := hostname .ExternalRegistry.Url }}
[plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ $url }}\".auth]
password = \"{{ .ExternalRegistry.Pass }}\"
username = \"{{ .ExternalRegistry.User }}\"
path: /etc/containerd/config.toml
Expand Down Expand Up @@ -121,18 +122,16 @@ spec:
rootDeviceType: {{ .Descriptor.ControlPlane.RootVolume.Type }}
{{- end }}
{{- range $node := .Descriptor.WorkerNodes }}
{{- range $index, $n := loop .AZ .Quantity .NodeGroupMaxSize .NodeGroupMinSize }}
{{- range $index, $n := loop .AZ .ZoneDistribution .Quantity .NodeGroupMaxSize .NodeGroupMinSize }}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
{{- if and (gt $node.NodeGroupMaxSize 0) (gt $node.NodeGroupMinSize 0) }}
annotations:
{{- if $node.NodeGroupMaxSize }}
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: '{{ $n.MaxSize }}'
{{- end }}
{{- if $node.NodeGroupMinSize }}
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: '{{ $n.MinSize }}'
{{- end }}
{{- end }}
name: "{{ $node.Name }}-md-{{ $index }}"
namespace: "cluster-{{ $.Descriptor.ClusterID }}"
spec:
Expand Down Expand Up @@ -196,7 +195,8 @@ spec:
[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors]
[plugins.\"io.containerd.grpc.v1.cri\".registry.mirrors.\"docker.io\"]
endpoint = [\"https://registry-1.docker.io\"]
[plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ $.ExternalRegistry.Url }}\".auth]
{{- $url := hostname $.ExternalRegistry.Url }}
[plugins.\"io.containerd.grpc.v1.cri\".registry.configs.\"{{ $url }}\".auth]
password = \"{{ $.ExternalRegistry.Pass }}\"
username = \"{{ $.ExternalRegistry.User }}\"
path: /etc/containerd/config.toml
Expand Down

0 comments on commit 524b3a8

Please sign in to comment.