-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed custom label generation. Refactored scheduling logic in prepa…
…ration for multiple provisioner selection
- Loading branch information
Showing
17 changed files
with
361 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha5 | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
// Constraints are applied to all nodes created by the provisioner. | ||
type Constraints struct { | ||
// Labels are layered with Requirements and applied to every node. | ||
//+optional | ||
Labels map[string]string `json:"labels,omitempty"` | ||
// Taints will be applied to every node launched by the Provisioner. If | ||
// specified, the provisioner will not provision nodes for pods that do not | ||
// have matching tolerations. Additional taints will be created that match | ||
// pod tolerations on a per-node basis. | ||
// +optional | ||
Taints Taints `json:"taints,omitempty"` | ||
// Requirements are layered with Labels and applied to every node. | ||
Requirements Requirements `json:"requirements,omitempty"` | ||
// Provider contains fields specific to your cloudprovider. | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
Provider *runtime.RawExtension `json:"provider,omitempty"` | ||
} | ||
|
||
// Supports returns true if the pod's requirements are met by the constraints | ||
func (c *Constraints) Supports(pod *v1.Pod) error { | ||
// Tolerate Taints | ||
if err := c.Taints.Tolerates(pod); err != nil { | ||
return err | ||
} | ||
// The constraints do not support this requirement | ||
podRequirements := PodRequirements(pod) | ||
for _, key := range podRequirements.Keys() { | ||
if c.Requirements.Requirement(key).Len() == 0 { | ||
return fmt.Errorf("%s is too constrained", key) | ||
} | ||
} | ||
// The combined requirements are not compatible | ||
combined := c.Requirements.With(podRequirements) | ||
for _, key := range podRequirements.Keys() { | ||
if combined.Requirement(key).Len() == 0 { | ||
return fmt.Errorf("%s is too constrained", key) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Constraints) Tighten(pod *v1.Pod) *Constraints { | ||
return &Constraints{ | ||
Labels: c.Labels, | ||
Requirements: c.Requirements.With(PodRequirements(pod)).Consolidate().WellKnown(), | ||
Taints: c.Taints.WithPod(pod), | ||
Provider: c.Provider, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.