Skip to content
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 Nextcloud Backups to API #212

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ generate: export PATH := $(go_bin):$(PATH)
generate: get-crds generate-stackgres-crds protobuf-gen ## Generate code with controller-gen and protobuf.
go version
rm -rf apis/generated
go run sigs.k8s.io/controller-tools/cmd/controller-gen paths="{./apis/v1/..., ./apis/vshn/..., ./apis/exoscale/...}" object crd:crdVersions=v1,allowDangerousTypes=true output:artifacts:config=./apis/generated
go run sigs.k8s.io/controller-tools/cmd/controller-gen paths="{./apis/v1/..., ./apis/vshn/..., ./apis/exoscale/..., ./apis/apiserver/...}" object crd:crdVersions=v1,allowDangerousTypes=true output:artifacts:config=./apis/generated
go generate ./...
# Because yaml is such a fun and easy specification, we need to hack some things here.
# Depending on the yaml parser implementation the equal sign (=) has special meaning, or not...
Expand All @@ -90,6 +90,7 @@ generate: get-crds generate-stackgres-crds protobuf-gen ## Generate code with c
rm -rf crds && cp -r apis/generated crds
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=appcat-sli-exporter paths="{./pkg/sliexporter/...}" output:artifacts:config=config/sliexporter/rbac
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=appcat-controller paths="{./pkg/controller/...}" output:rbac:stdout > config/controller/cluster-role.yaml
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=appcat-controller paths="{./pkg/apiserver/...}" output:rbac:stdout > config/apiserver/role.yaml
go run sigs.k8s.io/controller-tools/cmd/controller-gen webhook paths="{./pkg/controller/...}" output:stdout > config/controller/webhooks.yaml

.PHONY: generate-stackgres-crds
Expand Down
1,123 changes: 1,045 additions & 78 deletions apis/apiserver/v1/generated.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apis/apiserver/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&VSHNRedisBackupList{},
&VSHNMariaDBBackup{},
&VSHNMariaDBBackupList{},
&VSHNNextcloudBackup{},
&VSHNNextcloudBackupList{},
)
metav1.AddToGroupVersion(scheme, GroupVersion)
return nil
Expand Down
85 changes: 85 additions & 0 deletions apis/apiserver/v1/vshn_nextcloud_backup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/apiserver-runtime/pkg/builder/resource"
)

// VSHNNextcloudBackup needs to implement the builder resource interface
var _ resource.Object = &VSHNNextcloudBackup{}
var _ resource.ObjectList = &VSHNNextcloudBackupList{}

// +kubebuilder:object:root=true
// +k8s:openapi-gen=true
type VSHNNextcloudBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status VSHNNextcloudBackupStatus `json:"status,omitempty"`
}

// +k8s:openapi-gen=true
type VSHNNextcloudBackupStatus struct {
// FileBackupAvailable indicates if this backup contains a file backup for Nextcloud.
// Not every file backup might have a database backup associated, because the retention is not enforced at the same time.
FileBackupAvailable bool
// DatabaseBackupAvailable indicates if this backup contains a database backup for Nextcloud.
// Not every file backup might have a database backup associated, because the retention is not enforced at the same time.
DatabaseBackupAvailable bool
NextcloudFileBackup VSHNNextcloudFileBackupStatus `json:"nextcloudFileBackup,omitempty"`
DatabaseBackupStatus VSHNPostgresBackupStatus `json:"databaseBackupStatus,omitempty"`
}

// +k8s:openapi-gen=true
type VSHNNextcloudFileBackupStatus struct {
ID string `json:"id,omitempty"`
Date metav1.Time `json:"date,omitempty"`
Instance string `json:"instance,omitempty"`
}

// +kubebuilder:object:root=true
// +k8s:openapi-gen=true
type VSHNNextcloudBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []VSHNNextcloudBackup `json:"items,omitempty"`
}

// GetGroupVersionResource returns the GroupVersionResource for this resource.
// The resource should be the all lowercase and pluralized kind
func (in *VSHNNextcloudBackup) GetGroupVersionResource() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: GroupVersion.Group,
Version: GroupVersion.Version,
Resource: "vshnnextcloudbackups",
}
}

func (in *VSHNNextcloudBackup) GetObjectMeta() *metav1.ObjectMeta {
return &in.ObjectMeta
}

// IsStorageVersion returns true if the object is also the internal version -- i.e. is the type defined for the API group or an alias to this object.
// If false, the resource is expected to implement MultiVersionObject interface.
func (in *VSHNNextcloudBackup) IsStorageVersion() bool {
return true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this hardcoded to true, even though the comment suggests, that this could be false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently don't have multiple versions. This is part of the interface and needs to be implemented.

}

func (in *VSHNNextcloudBackup) NamespaceScoped() bool {
return true
}

func (in *VSHNNextcloudBackup) New() runtime.Object {
return &VSHNNextcloudBackup{}
}

func (in *VSHNNextcloudBackup) NewList() runtime.Object {
return &VSHNNextcloudBackupList{}
}

func (in *VSHNNextcloudBackupList) GetListMeta() *metav1.ListMeta {
return &in.ListMeta
}
91 changes: 91 additions & 0 deletions apis/apiserver/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apis/vshn/v1/vshn_nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type VSHNNextcloudSpec struct {
// Parameters are the configurable fields of a VSHNNextcloud.
Parameters VSHNNextcloudParameters `json:"parameters,omitempty"`

// ResourceRef tracks the internal composite belonging to this claim
ResourceRef xpv1.TypedReference `json:"resourceRef,omitempty"`

// WriteConnectionSecretToRef references a secret to which the connection details will be written.
WriteConnectionSecretToRef v1.LocalObjectReference `json:"writeConnectionSecretToRef,omitempty"`
}
Expand Down Expand Up @@ -186,6 +189,8 @@ type XVSHNNextcloudSpec struct {
// Parameters are the configurable fields of a VSHNNextcloud.
Parameters VSHNNextcloudParameters `json:"parameters,omitempty"`

ResourceRefs []xpv1.TypedReference `json:"resourceRefs,omitempty"`

xpv1.ResourceSpec `json:",inline"`
}

Expand Down
6 changes: 6 additions & 0 deletions apis/vshn/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cmd/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
appcatv1 "github.com/vshn/appcat/v4/apis/apiserver/v1"
"github.com/vshn/appcat/v4/pkg/apiserver/appcat"
vshnmariadb "github.com/vshn/appcat/v4/pkg/apiserver/vshn/mariadb"
vshnnextcloud "github.com/vshn/appcat/v4/pkg/apiserver/vshn/nextcloud"
vshnpostgres "github.com/vshn/appcat/v4/pkg/apiserver/vshn/postgres"
vshnredis "github.com/vshn/appcat/v4/pkg/apiserver/vshn/redis"
appcatopenapi "github.com/vshn/appcat/v4/pkg/openapi"
Expand All @@ -27,6 +28,8 @@ func newAPIServerCMD() *cobra.Command {

b.WithResourceAndHandler(&appcatv1.VSHNMariaDBBackup{}, vshnmariadb.New())

b.WithResourceAndHandler(&appcatv1.VSHNNextcloudBackup{}, vshnnextcloud.New())

b.WithoutEtcd().
ExposeLoopbackAuthorizer().
ExposeLoopbackMasterClientConfig()
Expand Down
40 changes: 39 additions & 1 deletion config/apiserver/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: appcat
name: appcat-controller
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -73,7 +73,45 @@ rules:
- vshn.appcat.vshn.io
resources:
- vshnmariadbs
verbs:
- get
- list
- watch
- apiGroups:
- vshn.appcat.vshn.io
resources:
- vshnnextclouds
verbs:
- get
- list
- watch
- apiGroups:
- vshn.appcat.vshn.io
resources:
- vshnpostgresqls
verbs:
- get
- list
- watch
- apiGroups:
- vshn.appcat.vshn.io
resources:
- vshnredis
verbs:
- get
- list
- watch
- apiGroups:
- vshn.appcat.vshn.io
resources:
- xvshnnextclouds
verbs:
- get
- list
- watch
- apiGroups:
- vshn.appcat.vshn.io
resources:
- xvshnpostgresqls
verbs:
- get
Expand Down
20 changes: 20 additions & 0 deletions crds/vshn.appcat.vshn.io_vshnnextclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9949,6 +9949,26 @@ spec:
default: {}
type: object
default: {}
resourceRef:
description: ResourceRef tracks the internal composite belonging to this claim
properties:
apiVersion:
description: APIVersion of the referenced object.
type: string
kind:
description: Kind of the referenced object.
type: string
name:
description: Name of the referenced object.
type: string
uid:
description: UID of the referenced object.
type: string
required:
- apiVersion
- kind
- name
type: object
writeConnectionSecretToRef:
description: WriteConnectionSecretToRef references a secret to which the connection details will be written.
properties:
Expand Down
25 changes: 25 additions & 0 deletions crds/vshn.appcat.vshn.io_xvshnnextclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11867,6 +11867,31 @@ spec:
required:
- name
type: object
resourceRefs:
items:
description: |-
A TypedReference refers to an object by Name, Kind, and APIVersion. It is
commonly used to reference cluster-scoped objects or objects where the
namespace is already known.
properties:
apiVersion:
description: APIVersion of the referenced object.
type: string
kind:
description: Kind of the referenced object.
type: string
name:
description: Name of the referenced object.
type: string
uid:
description: UID of the referenced object.
type: string
required:
- apiVersion
- kind
- name
type: object
type: array
writeConnectionSecretToRef:
description: |-
WriteConnectionSecretToReference specifies the namespace and name of a
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver/appcat/appcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// +kubebuilder:rbac:groups="admissionregistration.k8s.io",resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch;create;delete;update
// +kubebuilder:rbac:groups="authorization.k8s.io",resources=subjectaccessreviews,verbs=get;list;watch;create;delete;update
// +kubebuilder:rbac:groups="apiextensions.crossplane.io",resources=compositions,verbs=get;list;watch

// New returns a new storage provider for AppCat
func New() restbuilder.ResourceHandlerProvider {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func GetBackupColumnDefinition() []metav1.TableColumnDefinition {
desc := metav1.ObjectMeta{}.SwaggerDoc()
return []metav1.TableColumnDefinition{
{Name: "Backup ID", Type: "string", Format: "name", Description: desc["name"]},
{Name: "Database Instance", Type: "string", Description: "The database instance"},
{Name: "Instance", Type: "string", Description: "The instance that this backup belongs to"},
{Name: "Started", Type: "string", Description: "The backup start time"},
{Name: "Finished", Type: "string", Description: "The data is available up to this time"},
{Name: "Status", Type: "string", Description: "The state of this backup"},
Expand Down
Loading
Loading