argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.83k stars 5.44k forks source link

[Proposal] Custom AppSet generator - Schedules generator #16215

Open Aym3nTN opened 1 year ago

Aym3nTN commented 1 year ago

Summary

I'm suggesting to create an AppSet generator to un-apply/delete an Application using Cron expressions.

Motivation

My motivation is about cost savings, in my case, I have multiple applications that each uses an Ingress that is responsible for creating an AWS ALB (using AWS ALB Controller plugin) and alb costs money; therefore I'd like to automate shutting down my dev/stg environment when not needed like weekends or after work hours.

What do you think about that? The idea is similar to KubeGreen but acts on Argo Application resource level rather than Deployments resources.

crenshaw-dev commented 1 year ago

I think it's a cool idea. What would be the syntax?

You could probably do it today with a plugin. Pass the plugin some unique key (app name maybe) and a cron schedule, have the plugin pass back the unique key and a shutdown: true/false. Merge the plugin output with your other generators', and filter on the shutdown param.

Aym3nTN commented 1 year ago

Won't that require having my plugin's code deployed somewhere? I believe that would fit better in the applicationset_controller code base.

It can look something like that, we can adjust afterward:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: myapps
spec:
  generators:
  - schedules:
      weekdays: ["weekends", "Saturday', ...]
      workdays: "18:00-08:00"
      timezone: "UTC+1"
crenshaw-dev commented 1 year ago

Yep, it would need to be deployed separately. I'm not opposed to having it in the main code, but there is a maintenance cost tradeoff. Given the current 400 PR backlog, it might be prudent to start with a plugin.

Aym3nTN commented 1 year ago

I will write it in Go so in the future I can add to this proposal.

blakepettersson commented 11 months ago

Perhaps this could be done with a scale-to-zero feature as proposed in #6430? If we could scale an Application from 1 to 0 by implementing a scale subresource on it then we could potentially use something like KEDA to scale an application up and down.

Aym3nTN commented 11 months ago

@blakepettersson This issue is more general then the other one since in this one we're looking at not generating the "Application" at all to begin within which means no having the create any sub-k8s resources that the "Application" was supposed to generate.

blakepettersson commented 11 months ago

@Aym3nTN this could also/or be implemented on the ApplicationSet resource as well. We could have the same semantics as deleting an Application[Set] if we were to scale it down to zero. I'm not sure if this is even workable, it's just a crazy idea that I have 😄

blakepettersson commented 11 months ago

Hmm, thinking a bit more about this it would probably be a better approach to extend SyncWindows as proposed in #11755, with an added option to scale-down/remove resources in a given window.

There's overlap with #16063, where the issue is to protect an Application from being deleted, but perhaps this could also then be extended to ensure the deletion of an application during that window.

Then it'd be possible to have an AppProject scoped sync window where a generated application could be allowed to scale down within a given window.