diff --git a/api/v1alpha1/revision_types.go b/api/v1alpha1/revision_types.go index e70b2b2d..45a37baf 100644 --- a/api/v1alpha1/revision_types.go +++ b/api/v1alpha1/revision_types.go @@ -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 { diff --git a/config/crd/bases/picchu.medium.engineering_revisions.yaml b/config/crd/bases/picchu.medium.engineering_revisions.yaml index 5029e84b..d54070c8 100644 --- a/config/crd/bases/picchu.medium.engineering_revisions.yaml +++ b/config/crd/bases/picchu.medium.engineering_revisions.yaml @@ -1069,6 +1069,8 @@ spec: additionalProperties: type: string type: object + doNotEvict: + type: boolean env: items: description: EnvVar represents an environment variable present diff --git a/controllers/incarnation.go b/controllers/incarnation.go index a0436ad9..26174758 100644 --- a/controllers/incarnation.go +++ b/controllers/incarnation.go @@ -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() { diff --git a/controllers/plan/syncRevision.go b/controllers/plan/syncRevision.go index b325138e..e5ca9644 100644 --- a/controllers/plan/syncRevision.go +++ b/controllers/plan/syncRevision.go @@ -85,6 +85,7 @@ type SyncRevision struct { VolumeMounts []corev1.VolumeMount Volumes []corev1.Volume PodDisruptionBudget *policyv1.PodDisruptionBudget + DoNotEvict bool } func (p *SyncRevision) Printable() interface{} { @@ -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)