-
Notifications
You must be signed in to change notification settings - Fork 1
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 Forgejo backup #310
Open
ThisIsntTheWay
wants to merge
14
commits into
master
Choose a base branch
from
add/forgejo-backup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−7
Open
Add Forgejo backup #310
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
843fcaa
Add backup functionality
ThisIsntTheWay f7f2097
Fix typo
ThisIsntTheWay cae72c4
Temp: Logging
ThisIsntTheWay d96ab82
Fix values fields
ThisIsntTheWay bb0c4f1
Test: use comp name directly
ThisIsntTheWay d463d40
Revert "Test: use comp name directly"
ThisIsntTheWay fad9329
Use comp name directly again
ThisIsntTheWay f238836
NewRelease(): Use (unused) resName
ThisIsntTheWay c697056
GetMaintenanceTimeOfDay(): Return pointer, set backup schedule
ThisIsntTheWay 7ff5285
Add maintenance
ThisIsntTheWay 9ce7aed
Remove maintenance; Only backup
ThisIsntTheWay 7de9b6c
Don't create bucket if no comp name, no fatal err
ThisIsntTheWay 9fcebcd
Use tar
ThisIsntTheWay 59774e7
Newline, correct name
ThisIsntTheWay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ func NewRelease(ctx context.Context, svc *runtime.ServiceRuntime, comp InfoGette | |
|
||
release := &xhelmv1.Release{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: comp.GetName(), | ||
Name: resName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this has to change? This is in common package and will disrupt existing releases from other services, we have to be very carefully here. |
||
}, | ||
Spec: xhelmv1.ReleaseSpec{ | ||
ForProvider: xhelmv1.ReleaseParameters{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package vshnforgejo | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"encoding/json" | ||
"fmt" | ||
|
||
xfnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
xhelmv1 "github.com/vshn/appcat/v4/apis/helm/release/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/backup" | ||
"github.com/vshn/appcat/v4/pkg/comp-functions/runtime" | ||
) | ||
|
||
//go:embed script/backup.sh | ||
var forgejoBackupScript string | ||
|
||
func AddBackup(ctx context.Context, comp *vshnv1.VSHNForgejo, svc *runtime.ServiceRuntime) *xfnproto.Result { | ||
err := svc.GetDesiredComposite(comp) | ||
if err != nil { | ||
return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) | ||
} | ||
|
||
common.SetRandomSchedules(comp, comp) | ||
err = backup.AddK8upBackup(ctx, svc, comp) | ||
if err != nil { | ||
return runtime.NewWarningResult(fmt.Sprintf("cannot add k8s backup to the desired state: %v", err)) | ||
} | ||
|
||
err = backup.AddBackupScriptCM(svc, comp, forgejoBackupScript) | ||
if err != nil { | ||
return runtime.NewFatalResult(err) | ||
} | ||
|
||
err = updateRelease(svc, comp) | ||
if err != nil { | ||
return runtime.NewWarningResult(fmt.Sprintf("cannot update release with backup configuration: %s", err)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func updateRelease(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNForgejo) error { | ||
ThisIsntTheWay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
release := &xhelmv1.Release{} | ||
|
||
err := svc.GetDesiredComposedResourceByName(release, comp.GetName()+"-release") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
values, err := common.GetReleaseValues(release) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = backup.AddPVCAnnotationToValues(values, "persistence", "annotations") | ||
if err != nil { | ||
return fmt.Errorf("cannot add pvc annotations to values: %w", err) | ||
} | ||
|
||
err = backup.AddPodAnnotationToValues(values, "/scripts/backup.sh", ".tar", "gitea", "podAnnotations") | ||
if err != nil { | ||
return fmt.Errorf("cannot add pod annotations to values: %w", err) | ||
} | ||
|
||
err = backup.AddBackupCMToValues(values, []string{"extraVolumes"}, []string{"extraContainerVolumeMounts"}) | ||
if err != nil { | ||
return fmt.Errorf("cannot add backup cm to values: %w", err) | ||
} | ||
|
||
byteValues, err := json.Marshal(values) | ||
if err != nil { | ||
return err | ||
} | ||
release.Spec.ForProvider.Values.Raw = byteValues | ||
|
||
return svc.SetDesiredComposedResourceWithName(release, comp.GetName()+"-release") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,10 @@ func init() { | |
Name: "deploy", | ||
Execute: DeployForgejo, | ||
}, | ||
{ | ||
Name: "backup", | ||
Execute: AddBackup, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
forgejo dump --type tar -t /tmp/backup -V -f - | ||
ThisIsntTheWay marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be possible. The
comp
argument is the composite itself which cannot exist without a name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually did return an empty string on a few occasions.
With an empty string, it creates a bucket with a bad policy
-bucket
which minio complains about and then the whole pipeline gets stuck until that bucket is deleted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we have a deeper problem somewhere in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you debug this part? Try to reproduce and see why it's empty