Skip to content

Commit

Permalink
Remove Persistence option for SolrBackup. (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoustonPutman authored Nov 3, 2021
1 parent 94b62dc commit fb29d60
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 490 deletions.
65 changes: 21 additions & 44 deletions api/v1beta1/solrbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ import (
"strings"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
DefaultAWSCliImageRepo = "infrastructureascode/aws-cli"
DefaultAWSCliImageVersion = "1.16.204"
DefaultS3Retries = 5
)

// SolrBackupSpec defines the desired state of SolrBackup
type SolrBackupSpec struct {
// A reference to the SolrCloud to create a backup for
Expand All @@ -52,20 +43,26 @@ type SolrBackupSpec struct {
Location string `json:"location,omitempty"`

// Persistence is the specification on how to persist the backup data.
// This feature has been removed as of v0.5.0. Any options specified here will not be used.
//
// +optional
Persistence *PersistenceSource `json:"persistence,omitempty"`
}

func (spec *SolrBackupSpec) withDefaults(backupName string) (changed bool) {
func (spec *SolrBackupSpec) withDefaults() (changed bool) {
// Remove any Persistence specs, since this feature was removed.
if spec.Persistence != nil {
changed = spec.Persistence.withDefaults(backupName) || changed
changed = true
spec.Persistence = nil
}

return changed
}

// PersistenceSource defines the location and method of persisting the backup data.
// Exactly one member must be specified.
//
// Deprecated: Will be unused as of v0.5.0
type PersistenceSource struct {
// Persist to an s3 compatible endpoint
// +optional
Expand All @@ -76,19 +73,9 @@ type PersistenceSource struct {
Volume *VolumePersistenceSource `json:"volume,omitempty"`
}

func (spec *PersistenceSource) withDefaults(backupName string) (changed bool) {
if spec.Volume != nil {
changed = spec.Volume.withDefaults(backupName) || changed
}

if spec.S3 != nil {
changed = spec.S3.withDefaults(backupName) || changed
}

return changed
}

// S3PersistenceSource defines the specs for connecting to s3 for persistence
//
// Deprecated: Will be unused as of v0.5.0
type S3PersistenceSource struct {
// The S3 compatible endpoint URL
// +optional
Expand Down Expand Up @@ -120,26 +107,9 @@ type S3PersistenceSource struct {
AWSCliImage ContainerImage `json:"AWSCliImage,omitempty"`
}

func (spec *S3PersistenceSource) withDefaults(backupName string) (changed bool) {
changed = spec.AWSCliImage.withDefaults(DefaultAWSCliImageRepo, DefaultAWSCliImageVersion, DefaultPullPolicy) || changed

if spec.Key == "" {
spec.Key = backupName + ".tgz"
changed = true
} else if strings.HasPrefix(spec.Key, "/") {
spec.Key = strings.TrimPrefix(spec.Key, "/")
changed = true
}
if spec.Retries == nil {
retries := int32(DefaultS3Retries)
spec.Retries = &retries
changed = true
}

return changed
}

// S3Secrets describes the secrets provided for accessing s3.
//
// Deprecated: Will be unused as of v0.5.0
type S3Secrets struct {
// The name of the secrets object to use
Name string `json:"fromSecret"`
Expand All @@ -162,6 +132,8 @@ type S3Secrets struct {
}

// UploadSpec defines the location and method of uploading the backup data
//
// Deprecated: Will be unused as of v0.5.0
type VolumePersistenceSource struct {
// The volume for persistence
VolumeSource corev1.VolumeSource `json:"source"`
Expand All @@ -180,6 +152,7 @@ type VolumePersistenceSource struct {
BusyBoxImage ContainerImage `json:"busyBoxImage,omitempty"`
}

// Deprecated: Will be unused as of v0.5.0
func (spec *VolumePersistenceSource) withDefaults(backupName string) (changed bool) {
changed = spec.BusyBoxImage.withDefaults(DefaultBusyBoxImageRepo, DefaultBusyBoxImageVersion, DefaultPullPolicy) || changed

Expand All @@ -205,7 +178,9 @@ type SolrBackupStatus struct {
// +optional
CollectionBackupStatuses []CollectionBackupStatus `json:"collectionBackupStatuses,omitempty"`

// Whether the backups are in progress of being persisted
// Whether the backups are in progress of being persisted.
// This feature has been removed as of v0.5.0.
//
// +optional
PersistenceStatus *BackupPersistenceStatus `json:"persistenceStatus,omitempty"`

Expand Down Expand Up @@ -255,6 +230,8 @@ type CollectionBackupStatus struct {
}

// BackupPersistenceStatus defines the status of persisting Solr backup data
//
// Deprecated: Will be unused as of v0.5.0
type BackupPersistenceStatus struct {
// Whether the collection is being backed up
// +optional
Expand Down Expand Up @@ -319,7 +296,7 @@ type SolrBackup struct {

// WithDefaults set default values when not defined in the spec.
func (sb *SolrBackup) WithDefaults() bool {
return sb.Spec.withDefaults(sb.Name)
return sb.Spec.withDefaults()
}

//+kubebuilder:object:root=true
Expand Down
45 changes: 45 additions & 0 deletions api/v1beta1/solrbackup_with_defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package v1beta1

import (
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"testing"
)

func TestRemoveBackupPersistence(t *testing.T) {
solrBackup := &SolrBackup{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
Spec: SolrBackupSpec{},
}

// Set defaults for SolrCloud
assert.False(t, solrBackup.WithDefaults(), "Defaulting an empty backup should do nothing")

//No deprecated repository to move, no existing repos
assert.Nilf(t, solrBackup.Spec.Persistence, "No Persistence should exist after setting backup defaults")

solrBackup.Spec.Persistence = &PersistenceSource{}

// Set defaults for SolrCloud
assert.True(t, solrBackup.WithDefaults(), "Defaulting a backup with persistence should result in a change")

//No deprecated repository to move, no existing repos
assert.Nilf(t, solrBackup.Spec.Persistence, "No Persistence should exist after setting backup defaults")
}
4 changes: 2 additions & 2 deletions config/crd/bases/solr.apache.org_solrbackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
description: The location to store the backup in the specified backup repository.
type: string
persistence:
description: Persistence is the specification on how to persist the backup data.
description: Persistence is the specification on how to persist the backup data. This feature has been removed as of v0.5.0. Any options specified here will not be used.
properties:
S3:
description: Persist to an s3 compatible endpoint
Expand Down Expand Up @@ -1106,7 +1106,7 @@ spec:
description: Whether the backup has finished
type: boolean
persistenceStatus:
description: Whether the backups are in progress of being persisted
description: Whether the backups are in progress of being persisted. This feature has been removed as of v0.5.0.
properties:
finishTimestamp:
description: Time that the collection backup finished at
Expand Down
18 changes: 0 additions & 18 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,6 @@ rules:
- statefulsets/status
verbs:
- get
- apiGroups:
- batch
resources:
- jobs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- batch
resources:
- jobs/status
verbs:
- get
- apiGroups:
- networking.k8s.io
resources:
Expand Down
Loading

0 comments on commit fb29d60

Please sign in to comment.