mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #7872 from dokku/fix-scaling-k3s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/annotations:set subcommands/autoscaling-auth:set subcommands/autoscaling-auth:report subcommands/cluster-add subcommands/cluster-list subcommands/cluster-remove subcommands/ensure-charts subcommands/initialize subcommands/labels:set subcommands/report subcommands/set subcommands/show-kubeconfig subcommands/uninstall
|
||||
TRIGGERS = triggers/core-post-deploy triggers/core-post-extract triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-create triggers/post-delete triggers/report triggers/scheduler-app-status triggers/scheduler-deploy triggers/scheduler-enter triggers/scheduler-logs triggers/scheduler-proxy-config triggers/scheduler-proxy-logs triggers/scheduler-post-delete triggers/scheduler-run triggers/scheduler-run-list triggers/scheduler-stop
|
||||
TRIGGERS = triggers/core-post-deploy triggers/core-post-extract triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-create triggers/post-delete triggers/report triggers/scheduler-app-status triggers/scheduler-deploy triggers/scheduler-enter triggers/scheduler-is-deployed triggers/scheduler-logs triggers/scheduler-proxy-config triggers/scheduler-proxy-logs triggers/scheduler-post-delete triggers/scheduler-run triggers/scheduler-run-list triggers/scheduler-stop
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = scheduler-k3s
|
||||
|
||||
|
||||
@@ -576,7 +576,6 @@ func getAutoscaling(input GetAutoscalingInput) (ProcessAutoscaling, error) {
|
||||
}
|
||||
|
||||
if !ok {
|
||||
common.LogWarn(fmt.Sprintf("No autoscaling config found for %s:%s", input.AppName, input.ProcessType))
|
||||
return ProcessAutoscaling{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -264,6 +264,7 @@ func (h *HelmAgent) InstallChart(ctx context.Context, input ChartInput) error {
|
||||
}
|
||||
|
||||
kustomizeRenderer := KustomizeRenderer{
|
||||
ReleaseName: input.ReleaseName,
|
||||
KustomizeRootPath: input.KustomizeRootPath,
|
||||
}
|
||||
|
||||
@@ -387,6 +388,7 @@ func (h *HelmAgent) UpgradeChart(ctx context.Context, input ChartInput) error {
|
||||
}
|
||||
|
||||
kustomizeRenderer := KustomizeRenderer{
|
||||
ReleaseName: input.ReleaseName,
|
||||
KustomizeRootPath: input.KustomizeRootPath,
|
||||
}
|
||||
|
||||
@@ -464,10 +466,16 @@ func (p *DebugRenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, err
|
||||
return renderedManifests, nil
|
||||
}
|
||||
|
||||
// KustomizeRenderer is a post renderer that kustomizes the rendered manifests
|
||||
type KustomizeRenderer struct {
|
||||
// KustomizeRootPath is the path to the kustomize root path to use
|
||||
KustomizeRootPath string
|
||||
|
||||
// ReleaseName is the name of the release to kustomize
|
||||
ReleaseName string
|
||||
}
|
||||
|
||||
// Run kustomizes the rendered manifests
|
||||
func (p *KustomizeRenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) {
|
||||
if p.KustomizeRootPath == "" {
|
||||
return renderedManifests, nil
|
||||
@@ -477,6 +485,7 @@ func (p *KustomizeRenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer,
|
||||
return renderedManifests, nil
|
||||
}
|
||||
|
||||
common.LogVerboseQuiet(fmt.Sprintf("Applying kustomization to %s", p.ReleaseName))
|
||||
fs, err := filesys.MakeFsOnDiskSecureBuild(p.KustomizeRootPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error creating filesystem: %w", err)
|
||||
|
||||
@@ -72,6 +72,10 @@ func main() {
|
||||
}
|
||||
|
||||
err = scheduler_k3s.TriggerSchedulerEnter(scheduler, appName, containerType, ptr.Deref(podIdentifier, ""), args)
|
||||
case "scheduler-is-deployed":
|
||||
scheduler := flag.Arg(0)
|
||||
appName := flag.Arg(1)
|
||||
err = scheduler_k3s.TriggerSchedulerIsDeployed(scheduler, appName)
|
||||
case "scheduler-logs":
|
||||
var tail bool
|
||||
var quiet bool
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{{- range $processName, $config := .Values.processes }}
|
||||
# Only process cron jobs
|
||||
{{- if not (and (hasKey $config "cron") (hasKey $config.cron "id")) }}
|
||||
# Skip {{ $processName }} as it is not a cron job
|
||||
{{- continue }}
|
||||
{{- end }}
|
||||
---
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{{- range $processName, $config := .Values.processes }}
|
||||
{{- if not (hasKey $config "web") }}
|
||||
# Skip {{ $processName }} as it doesn't have a web section
|
||||
{{- if hasKey $config "cron" }}
|
||||
# Skip {{ $processName }} as it is a cron job
|
||||
{{- continue }}
|
||||
{{- end }}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{{- if .Capabilities.APIVersions.Has "keda.sh/v1alpha1" -}}
|
||||
{{- range $processName, $config := .Values.processes }}
|
||||
{{- if not (hasKey $config "web") }}
|
||||
# Skip {{ $processName }} as it doesn't have a web section
|
||||
{{- if hasKey $config "cron" }}
|
||||
# Skip {{ $processName }} as it is a cron job
|
||||
{{- continue }}
|
||||
{{- end }}
|
||||
|
||||
{{- if and $config.autoscaling (and $config.autoscaling.enabled (eq $config.autoscaling.type "keda")) }}
|
||||
{{- if and (hasKey $config "autoscaling") (and $config.autoscaling.enabled (eq $config.autoscaling.type "keda")) }}
|
||||
---
|
||||
apiVersion: keda.sh/v1alpha1
|
||||
kind: ScaledObject
|
||||
|
||||
@@ -789,6 +789,32 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerSchedulerIsDeployed returns true if given app has a running container
|
||||
func TriggerSchedulerIsDeployed(scheduler string, appName string) error {
|
||||
if scheduler != "k3s" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// check if there are any helm revisions for the specified appName
|
||||
helmAgent, err := NewHelmAgent(getComputedNamespace(appName), DeployLogPrinter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating helm agent: %w", err)
|
||||
}
|
||||
|
||||
revisions, err := helmAgent.ListRevisions(ListRevisionsInput{
|
||||
ReleaseName: appName,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error listing helm revisions: %w", err)
|
||||
}
|
||||
|
||||
if len(revisions) > 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("App %s is not deployed", appName)
|
||||
}
|
||||
|
||||
// TriggerSchedulerEnter enters a container for a given application
|
||||
func TriggerSchedulerEnter(scheduler string, appName string, processType string, podName string, args []string) error {
|
||||
if scheduler != "k3s" {
|
||||
|
||||
@@ -29,6 +29,11 @@ teardown_() {
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 worker=2"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP inject_kustomization_yaml
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
@@ -39,6 +44,12 @@ teardown_() {
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "3"
|
||||
|
||||
run /bin/bash -c "kubectl get deployment $TEST_APP-worker -o json | jq -r '.spec.replicas'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "2"
|
||||
}
|
||||
|
||||
inject_kustomization_yaml() {
|
||||
@@ -58,8 +69,9 @@ patches:
|
||||
path: /spec/replicas
|
||||
value: 3
|
||||
target:
|
||||
group: apps
|
||||
version: v1
|
||||
kind: Deployment
|
||||
group: apps
|
||||
version: v1
|
||||
kind: Deployment
|
||||
name: $APP-web
|
||||
EOF
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user