|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2018 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | +// Author Adam Janikowski |
| 21 | +// |
| 22 | + |
| 23 | +package v1 |
| 24 | + |
| 25 | +import ( |
| 26 | + "fmt" |
| 27 | + |
| 28 | + deployment "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" |
| 29 | + |
| 30 | + "github.com/arangodb/kube-arangodb/pkg/backup/utils" |
| 31 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 32 | +) |
| 33 | + |
| 34 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 35 | + |
| 36 | +// ArangoBackupPolicyList is a list of ArangoDB backup policy. |
| 37 | +type ArangoBackupPolicyList struct { |
| 38 | + metav1.TypeMeta `json:",inline"` |
| 39 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 40 | + |
| 41 | + Items []ArangoBackupPolicy `json:"items"` |
| 42 | +} |
| 43 | + |
| 44 | +// +genclient |
| 45 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 46 | + |
| 47 | +// ArangoBackupPolicy contains definition and status of the ArangoDB Backup Policy. |
| 48 | +type ArangoBackupPolicy struct { |
| 49 | + metav1.TypeMeta `json:",inline"` |
| 50 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 51 | + |
| 52 | + Spec ArangoBackupPolicySpec `json:"spec"` |
| 53 | + Status ArangoBackupPolicyStatus `json:"status"` |
| 54 | +} |
| 55 | + |
| 56 | +func (a *ArangoBackupPolicy) NewBackup(d *deployment.ArangoDeployment) *ArangoBackup { |
| 57 | + policyName := a.Name |
| 58 | + |
| 59 | + spec := &ArangoBackupSpec{ |
| 60 | + Deployment: ArangoBackupSpecDeployment{ |
| 61 | + Name: d.Name, |
| 62 | + }, |
| 63 | + Upload: a.Spec.BackupTemplate.Upload.DeepCopy(), |
| 64 | + Options: a.Spec.BackupTemplate.Options.DeepCopy(), |
| 65 | + PolicyName: &policyName, |
| 66 | + } |
| 67 | + |
| 68 | + return &ArangoBackup{ |
| 69 | + ObjectMeta: metav1.ObjectMeta{ |
| 70 | + Name: fmt.Sprintf("%s-%s", d.Name, utils.RandomString(8)), |
| 71 | + Namespace: a.Namespace, |
| 72 | + |
| 73 | + Labels: d.Labels, |
| 74 | + |
| 75 | + Finalizers: []string{ |
| 76 | + FinalizerArangoBackup, |
| 77 | + }, |
| 78 | + }, |
| 79 | + Spec: *spec, |
| 80 | + } |
| 81 | +} |
0 commit comments