Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for do not evict karpenter #396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/revision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type RevisionTarget struct {

Istio *Istio `json:"istio,omitempty"`
PodDisruptionBudget *policyv1.PodDisruptionBudget `json:"podDisruptionBudget,omitempty"`
DoNotEvict bool `json:"doNotEvict,omitempty"`
}

type ExternalTest struct {
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/picchu.medium.engineering_revisions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,8 @@ spec:
additionalProperties:
type: string
type: object
doNotEvict:
type: boolean
env:
items:
description: EnvVar represents an environment variable present
Expand Down
50 changes: 26 additions & 24 deletions controllers/incarnation.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,30 +375,32 @@ func (i *Incarnation) sync(ctx context.Context) error {

}
syncPlan := &rmplan.SyncRevision{
App: i.appName(),
Tag: i.tag,
Namespace: i.targetNamespace(),
Labels: i.defaultLabels(),
Configs: append(append(configs, secrets...), configMaps...),
Ports: i.ports(),
Replicas: replicas,
Image: i.image(),
Sidecars: i.target().Sidecars,
Resources: i.target().Resources,
IAMRole: i.target().AWS.IAM.RoleARN,
PodAnnotations: i.target().PodAnnotations,
ServiceAccountName: i.target().ServiceAccountName,
ReadinessProbe: i.target().ReadinessProbe,
LivenessProbe: i.target().LivenessProbe,
MinReadySeconds: i.target().Scale.MinReadySeconds,
Worker: i.target().Scale.Worker,
Lifecycle: i.target().Lifecycle,
Affinity: i.target().Affinity,
PriorityClassName: i.target().PriorityClassName,
Tolerations: i.target().Tolerations,
EnvVars: i.target().Env,
Volumes: i.target().Volumes,
VolumeMounts: i.target().VolumeMounts,
App: i.appName(),
Tag: i.tag,
Namespace: i.targetNamespace(),
Labels: i.defaultLabels(),
Configs: append(append(configs, secrets...), configMaps...),
Ports: i.ports(),
Replicas: replicas,
Image: i.image(),
Sidecars: i.target().Sidecars,
Resources: i.target().Resources,
IAMRole: i.target().AWS.IAM.RoleARN,
PodAnnotations: i.target().PodAnnotations,
ServiceAccountName: i.target().ServiceAccountName,
ReadinessProbe: i.target().ReadinessProbe,
LivenessProbe: i.target().LivenessProbe,
MinReadySeconds: i.target().Scale.MinReadySeconds,
Worker: i.target().Scale.Worker,
Lifecycle: i.target().Lifecycle,
Affinity: i.target().Affinity,
PriorityClassName: i.target().PriorityClassName,
Tolerations: i.target().Tolerations,
EnvVars: i.target().Env,
Volumes: i.target().Volumes,
VolumeMounts: i.target().VolumeMounts,
PodDisruptionBudget: i.target().PodDisruptionBudget,
DoNotEvict: i.target().DoNotEvict,
}

if !i.isRoutable() {
Expand Down
5 changes: 5 additions & 0 deletions controllers/plan/syncRevision.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type SyncRevision struct {
VolumeMounts []corev1.VolumeMount
Volumes []corev1.Volume
PodDisruptionBudget *policyv1.PodDisruptionBudget
DoNotEvict bool
}

func (p *SyncRevision) Printable() interface{} {
Expand Down Expand Up @@ -201,6 +202,10 @@ func (p *SyncRevision) Apply(ctx context.Context, cli client.Client, cluster *pi
labels[k] = v
}

if p.DoNotEvict {
labels["karpenter.sh/do-not-evict"] = "true"
}

var scalingFactor *float64
if cluster.Spec.ScalingFactorString != nil {
f, err := strconv.ParseFloat(*cluster.Spec.ScalingFactorString, 64)
Expand Down