Skip to content

Commit

Permalink
Add maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsntTheWay committed Feb 17, 2025
1 parent c697056 commit 7ff5285
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/comp-functions/functions/common/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package common

import (
"fmt"
v1 "github.com/vshn/appcat/v4/apis/vshn/v1"
"math/rand"
"time"

v1 "github.com/vshn/appcat/v4/apis/vshn/v1"
)

var (
Expand Down
1 change: 0 additions & 1 deletion pkg/comp-functions/functions/vshnforgejo/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func AddBackup(ctx context.Context, comp *vshnv1.VSHNForgejo, svc *runtime.Servi
if err != nil {
return runtime.NewFatalResult(fmt.Errorf("cannot add k8s backup to the desired state: %w", err))
}
common.SetRandomSchedules(comp, comp)

err = backup.AddBackupScriptCM(svc, comp, forgejoBackupScript)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions pkg/comp-functions/functions/vshnforgejo/maintenance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package vshnforgejo

import (
"context"
"fmt"

xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1"
vshnv1 "github.com/vshn/appcat/v4/apis/vshn/v1"
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common"
"github.com/vshn/appcat/v4/pkg/comp-functions/functions/common/maintenance"
"github.com/vshn/appcat/v4/pkg/comp-functions/runtime"
)

// AddMaintenanceJob will add a job to do the maintenance for the instance
func AddMaintenanceJob(ctx context.Context, comp *vshnv1.VSHNForgejo, svc *runtime.ServiceRuntime) *xfnproto.Result {

err := svc.GetObservedComposite(comp)
if err != nil {
return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err))
}

common.SetRandomSchedules(comp, comp)

instanceNamespace := comp.GetInstanceNamespace()
schedule := comp.GetFullMaintenanceSchedule()

err = svc.SetDesiredCompositeStatus(comp)
if err != nil {
return runtime.NewFatalResult(fmt.Errorf("cannot update composite status: %w", err))
}

return maintenance.New(comp, svc, schedule, instanceNamespace, comp.GetServiceName()).
WithHelmBasedService().
Run(ctx)
}
4 changes: 4 additions & 0 deletions pkg/comp-functions/functions/vshnforgejo/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func init() {
Name: "deploy",
Execute: DeployForgejo,
},
{
Name: "maintenance",
Execute: AddMaintenanceJob,
},
{
Name: "backup",
Execute: AddBackup,
Expand Down

0 comments on commit 7ff5285

Please sign in to comment.