Skip to content

Commit

Permalink
Cleanups for requirements refactor PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn authored and felix-zhe-huang committed Feb 3, 2022
1 parent a4c6aba commit 97e9714
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 352 deletions.
3 changes: 1 addition & 2 deletions charts/karpenter/crds/karpenter.sh_provisioners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
name: provisioners.karpenter.sh
spec:
Expand Down Expand Up @@ -170,7 +170,6 @@ spec:
transitioned from one status to another. We use VolatileTime
in place of metav1.Time to exclude this from creating equality.Semantic
differences (all other things held constant).
format: date-time
type: string
message:
description: A human readable message indicating details about
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/provisioning/v1alpha5/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Constraints struct {
// +optional
Taints Taints `json:"taints,omitempty"`
// Requirements are layered with Labels and applied to every node.
Requirements *Requirements `json:"requirements,inline,omitempty"`
Requirements Requirements `json:"requirements,inline,omitempty"`
// KubeletConfiguration are options passed to the kubelet when provisioning nodes
//+optional
KubeletConfiguration KubeletConfiguration `json:"kubeletConfiguration,omitempty"`
Expand All @@ -52,21 +52,21 @@ func (c *Constraints) ValidatePod(pod *v1.Pod) error {
return err
}
// Test if pod requirements are valid
podRequirements := NewRequirements(PodRequirements(pod)...)
if errs := podRequirements.Validate(); errs != nil {
requirements := NewPodRequirements(pod)
if errs := requirements.Validate(); errs != nil {
return fmt.Errorf("pod requirements not feasible, %v", errs)
}
// Test if pod requirements are compatible
if errs := c.Requirements.Compatible(podRequirements); errs != nil {
return fmt.Errorf("incompatible requirements %w", errs)
if errs := c.Requirements.Compatible(requirements); errs != nil {
return fmt.Errorf("incompatible requirements, %w", errs)
}
return nil
}

func (c *Constraints) Tighten(pod *v1.Pod) *Constraints {
return &Constraints{
Labels: c.Labels,
Requirements: c.Requirements.Add(PodRequirements(pod)...).WellKnown(),
Requirements: c.Requirements.Add(NewPodRequirements(pod).Requirements...).WellKnown(),
Taints: c.Taints,
Provider: c.Provider,
KubeletConfiguration: c.KubeletConfiguration,
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/provisioning/v1alpha5/provisioner_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func (c *Constraints) validateTaints() (errs *apis.FieldError) {
// When this function is called, the provisioner's requirments do not include the requirements from labels.
// Provisioner requirements only support well known labels.
func (c *Constraints) validateRequirements() (errs *apis.FieldError) {
// validate if requirement keys are well known labels
for _, key := range c.Requirements.Keys() {
// Ensure requirements are well known
for key := range c.Requirements.Keys() {
if !WellKnownLabels.Has(key) {
errs = errs.Also(apis.ErrInvalidKeyName(fmt.Sprintf("%s not in %v", key, WellKnownLabels.UnsortedList()), "key"))
}
Expand Down
Loading

0 comments on commit 97e9714

Please sign in to comment.