• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zalando-incubator / cluster-lifecycle-manager / 9853894254

09 Jul 2024 08:46AM UTC coverage: 50.656% (-0.07%) from 50.724%
9853894254

push

github

web-flow
adding a function to simplify template rendering for karpenter (#794)

Signed-off-by: Mahmoud Gaballah <mahmoud.gaballah@zalando.de>

0 of 8 new or added lines in 1 file covered. (0.0%)

3012 of 5946 relevant lines covered (50.66%)

14.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.5
/api/node_pool.go
1
package api
2

3
import (
4
        "strings"
5

6
        log "github.com/sirupsen/logrus"
7
        "github.com/zalando-incubator/cluster-lifecycle-manager/pkg/kubernetes"
8
        "gopkg.in/yaml.v2"
9
        corev1 "k8s.io/api/core/v1"
10
        v1 "k8s.io/client-go/applyconfigurations/core/v1"
11
)
12

13
// NodePool describes a node pool in a kubernetes cluster.
14
type NodePool struct {
15
        DiscountStrategy string            `json:"discount_strategy" yaml:"discount_strategy"`
16
        InstanceTypes    []string          `json:"instance_types"    yaml:"instance_types"`
17
        Name             string            `json:"name"              yaml:"name"`
18
        Profile          string            `json:"profile"           yaml:"profile"`
19
        MinSize          int64             `json:"min_size"          yaml:"min_size"`
20
        MaxSize          int64             `json:"max_size"          yaml:"max_size"`
21
        ConfigItems      map[string]string `json:"config_items"      yaml:"config_items"`
22

23
        // Deprecated, only kept here so the existing clusters don't break
24
        InstanceType string
25
}
26

27
func (np NodePool) IsSpot() bool {
×
28
        return np.DiscountStrategy == "spot_max_price" || np.DiscountStrategy == "spot"
×
29
}
×
30

31
func (np NodePool) IsMaster() bool {
×
32
        return strings.Contains(np.Profile, "master")
×
33
}
×
34

35
func (np NodePool) IsKarpenter() bool {
1✔
36
        return np.Profile == "worker-karpenter"
1✔
37
}
1✔
38

39
func (np NodePool) Taints() []*corev1.Taint {
×
40
        conf, exist := np.ConfigItems["taints"]
×
41
        if !exist {
×
42
                return nil
×
43
        }
×
44
        var taints []*corev1.Taint
×
45
        for _, t := range strings.Split(conf, ",") {
×
46
                taint, err := kubernetes.ParseTaint(t)
×
47
                if err == nil {
×
48
                        taints = append(taints, taint)
×
49
                }
×
50
        }
51
        return taints
×
52
}
53

54
func (np NodePool) KarpenterRequirements() []v1.NodeSelectorRequirementApplyConfiguration {
×
55
        conf, exist := np.ConfigItems["requirements"]
×
56
        if !exist {
×
57
                return nil
×
58
        }
×
59
        var requirements []v1.NodeSelectorRequirementApplyConfiguration
×
60
        err := yaml.Unmarshal([]byte(conf), &requirements)
×
61
        if err != nil {
×
62
                log.Errorf("Error unmarshalling requirements: %v", err)
×
63
        }
×
64
        return requirements
×
65
}
66

NEW
67
func (np NodePool) KarpenterInstanceTypeStrategy() string {
×
NEW
68
        if len(np.InstanceTypes) == 0 {
×
NEW
69
                return "not-specified"
×
NEW
70
        }
×
NEW
71
        if len(np.InstanceTypes) == 1 && np.InstanceTypes[0] == "default-for-karpenter" {
×
NEW
72
                return "default-for-karpenter"
×
NEW
73
        }
×
NEW
74
        return "custom"
×
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc